tests: Add fixtures for proxydaemon tests.

This commit is contained in:
Damir Jelić 2019-06-19 11:22:11 +02:00
parent 2c831de532
commit 315c4bb6f7

View File

@ -1,7 +1,12 @@
import asyncio
import shutil
import tempfile
import janus
from random import choices
from urllib.parse import urlparse
from string import ascii_letters, ascii_uppercase, digits
from aiohttp import web
from aioresponses import aioresponses
import pytest
from faker import Faker
@ -10,6 +15,8 @@ from nio.crypto import OlmAccount
from nio.store import SqliteStore
from pantalaimon.store import ClientInfo, PanStore
from pantalaimon.daemon import ProxyDaemon
from pantalaimon.config import ServerConfig
faker = Faker()
@ -78,3 +85,52 @@ def panstore_with_users(panstore):
panstore.save_server_user(server2, user_id2)
return panstore
@pytest.fixture
async def pan_proxy_server(tempdir, aiohttp_server):
loop = asyncio.get_event_loop()
app = web.Application()
server_name = faker.hostname()
config = ServerConfig(server_name, urlparse("https://example.org"))
pan_queue = janus.Queue(loop=loop)
ui_queue = janus.Queue(loop=loop)
proxy = ProxyDaemon(
config.name,
config.homeserver,
config,
tempdir,
send_queue=pan_queue.async_q,
recv_queue=ui_queue.async_q,
proxy=None,
ssl=False
)
app.add_routes([
web.post("/_matrix/client/r0/login", proxy.login),
web.get("/_matrix/client/r0/sync", proxy.sync),
web.get("/_matrix/client/r0/rooms/{room_id}/messages", proxy.messages),
web.put(
r"/_matrix/client/r0/rooms/{room_id}/send/{event_type}/{txnid}",
proxy.send_message
),
web.post("/_matrix/client/r0/user/{user_id}/filter", proxy.filter),
web.post("/_matrix/client/r0/search", proxy.search),
web.options("/_matrix/client/r0/search", proxy.search_opts),
])
server = await aiohttp_server(app)
yield server, proxy
await proxy.shutdown(app)
@pytest.fixture
def aioresponse():
with aioresponses(passthrough=["http://127.0.0.1"]) as m:
yield m