clean tests

This commit is contained in:
Guilhem Saurel
2021-07-13 10:28:40 +02:00
parent 2d8c68665e
commit 6633020fba
5 changed files with 29 additions and 39 deletions

View File

@@ -1,23 +1,10 @@
"""Main test module."""
import os
import unittest
import httpx
import nio
from .start import BOT_URL, MATRIX_ID, MATRIX_PW, MATRIX_URL
KEY = os.environ['API_KEY']
FULL_ID = f'@{MATRIX_ID}:{MATRIX_URL.split("/")[2]}'
def bot_req(req=None, key=None, room_id=None):
"""Bot requests boilerplate."""
if key is not None:
req['key'] = key
url = BOT_URL if room_id is None else f'{BOT_URL}/{room_id}'
return httpx.post(url, json=req).json()
from .start import FULL_ID, KEY, MATRIX_ID, MATRIX_PW, MATRIX_URL, bot_req
class BotTest(unittest.IsolatedAsyncioTestCase):
@@ -50,20 +37,3 @@ class BotTest(unittest.IsolatedAsyncioTestCase):
self.assertEqual(message.sender, FULL_ID)
self.assertEqual(message.body, text)
self.assertEqual(message.formatted_body, '<h1>Hello</h1>')
async def test_z_disconnected(self):
"""Send a message after disconnection, and check the error."""
client = nio.AsyncClient(MATRIX_URL, MATRIX_ID)
await client.login(MATRIX_PW)
token = client.access_token
resp = httpx.post(f'{MATRIX_URL}/_synapse/admin/v1/deactivate/{FULL_ID}',
json={'erase': True},
params={'access_token': token})
self.assertEqual(resp.json(), {'id_server_unbind_result': 'success'})
await client.logout(all_devices=True)
await client.close()
# TODO: I was hopping that one wouldn't be happy
self.assertEqual(bot_req({'text': 'bye'}, KEY), {'status': 200, 'ret': 'OK'})