pantalaimon/tests/conftest.py
Damir Jelić 725c043e87 pantalaimon: Initial search support.
This patch adds support for the Matrix search API endpoint.

Events are stored in the pan sqlite database while the indexing is
handled by tanvity.

An tantivy index is created for each pan user. Currently only ordering
by ranking is supported, and all the search options are ignored for now.
2019-06-06 14:25:14 +02:00

81 lines
1.6 KiB
Python

import shutil
import tempfile
from random import choices
from string import ascii_letters, ascii_uppercase, digits
import pytest
from faker import Faker
from faker.providers import BaseProvider
from nio.crypto import OlmAccount
from nio.store import SqliteStore
from pantalaimon.store import ClientInfo, PanStore
faker = Faker()
class Provider(BaseProvider):
def mx_id(self):
return "@{}:{}".format(faker.user_name(), faker.hostname())
def device_id(self):
return "".join(choices(ascii_uppercase, k=10))
def access_token(self):
return "MDA" + "".join(choices(digits + ascii_letters, k=272))
def client(self):
return ClientInfo(faker.mx_id(), faker.access_token())
faker.add_provider(Provider)
@pytest.fixture
def access_token():
return faker.access_token()
@pytest.fixture
def client():
return faker.client()
@pytest.fixture
def tempdir():
newpath = tempfile.mkdtemp()
yield newpath
shutil.rmtree(newpath)
@pytest.fixture
def panstore(tempdir):
for _ in range(10):
store = SqliteStore(
faker.mx_id(),
faker.device_id(),
tempdir,
"",
"pan.db"
)
account = OlmAccount()
store.save_account(account)
store = PanStore(tempdir, "pan.db")
return store
@pytest.fixture
def panstore_with_users(panstore):
accounts = panstore.load_all_users()
user_id, device_id = accounts[0]
server = "example"
panstore.save_server_user(server, user_id)
server2 = "localhost"
user_id2, device_id2 = accounts[1]
panstore.save_server_user(server2, user_id2)
return panstore