remember-remember-bot/tests/conftest.py

43 lines
1.2 KiB
Python
Raw Normal View History

2023-12-10 10:58:42 +00:00
import os
import deltachat
2023-09-01 21:58:54 +00:00
import pytest
2023-12-10 10:58:42 +00:00
import requests
2023-09-01 21:58:54 +00:00
@pytest.fixture
def tmp_file_path(request, tmpdir):
if request.param:
path = str(tmpdir) + "/" + str(request.param)
with open(path, "w+", encoding="utf-8") as f:
f.write("test")
return path
2023-12-10 10:58:42 +00:00
@pytest.fixture
def chat(tmpdir):
token = os.getenv("DCC_NEW_TMP_EMAIL", "https://nine.testrun.org/cgi-bin/newemail.py")
# create bot account from token
result = requests.post(token)
addr = result.json()['email']
password = result.json()['password']
bot = deltachat.Account(str(tmpdir) + "/db.sqlite")
bot.run_account(addr=addr, password=password, show_ffi=True)
# :TODO how to start the loop? In a subthread?
# create chat partner from token
result = requests.post(token)
addr = result.json()['email']
password = result.json()['password']
user = deltachat.Account(str(tmpdir) + "/db.sqlite")
user.run_account(addr=addr, password=password, show_ffi=False)
# initiate a chat between them
yield user.create_chat(bot.get_config('addr'))
# return the chat object
bot.shutdown()
user.shutdown()
bot.wait_shutdown()
user.wait_shutdown()