tests: Test that we're sending out user updates from the daemon.

This commit is contained in:
Damir Jelić 2019-06-19 15:55:40 +02:00
parent 62d0e5607e
commit 9308dfec3f
2 changed files with 49 additions and 4 deletions

View File

@ -125,11 +125,43 @@ async def pan_proxy_server(tempdir, aiohttp_server):
server = await aiohttp_server(app)
yield server, proxy
yield server, proxy, (pan_queue, ui_queue)
await proxy.shutdown(app)
@pytest.fixture
async def running_proxy(pan_proxy_server, aioresponse, aiohttp_client):
server, proxy, queues = pan_proxy_server
login_response = {
"access_token": "abc123",
"device_id": "GHTYAJCE",
"home_server": "example.org",
"user_id": "@example:example.org"
}
aioclient = await aiohttp_client(server)
aioresponse.post(
"https://example.org/_matrix/client/r0/login",
status=200,
payload=login_response,
repeat=True
)
await aioclient.post(
"/_matrix/client/r0/login",
json={
"type": "m.login.password",
"user": "example",
"password": "wordpass",
}
)
yield server, aioclient, proxy, queues
@pytest.fixture
def aioresponse():
with aioresponses(passthrough=["http://127.0.0.1"]) as m:

View File

@ -5,6 +5,7 @@ import re
from aiohttp import web
from conftest import faker
from pantalaimon.thread_messages import UpdateUsersMessage
class TestClass(object):
@ -36,7 +37,7 @@ class TestClass(object):
}
async def test_daemon_start(self, pan_proxy_server, aiohttp_client, aioresponse):
server, daemon = pan_proxy_server
server, daemon, _ = pan_proxy_server
client = await aiohttp_client(server)
@ -70,7 +71,7 @@ class TestClass(object):
assert pan_client.task
async def test_pan_client_sync(self, pan_proxy_server, aiohttp_client, aioresponse):
server, daemon = pan_proxy_server
server, daemon, _ = pan_proxy_server
client = await aiohttp_client(server)
@ -105,7 +106,7 @@ class TestClass(object):
assert len(pan_client.rooms) == 1
async def test_pan_client_keys_upload(self, pan_proxy_server, aiohttp_client, aioresponse):
server, daemon = pan_proxy_server
server, daemon, _ = pan_proxy_server
client = await aiohttp_client(server)
@ -148,3 +149,15 @@ class TestClass(object):
pan_client = list(daemon.pan_clients.values())[0]
assert pan_client.olm.account.shared
async def test_server_users_update(self, running_proxy):
_, _, _, queues = running_proxy
queue, _ = queues
queue = queue.sync_q
message = queue.get_nowait()
assert isinstance(message, UpdateUsersMessage)
assert message.user_id == "@example:example.org"
assert message.device_id == "GHTYAJCE"