This commit is contained in:
Guilhem Saurel 2021-07-13 08:53:10 +02:00
parent 6a2e0336d9
commit 2d8c68665e
3 changed files with 14 additions and 11 deletions

4
.gitignore vendored
View file

@ -1 +1,5 @@
.coverage
.env
.mypy_cache
coverage.xml coverage.xml
htmlcov

View file

@ -1,4 +1,4 @@
FROM python:3.9-slim FROM python:3.9
EXPOSE 4785 EXPOSE 4785

View file

@ -14,17 +14,16 @@ BOT_URL = 'http://localhost:4785'
MATRIX_URL, MATRIX_ID, MATRIX_PW = (environ[v] for v in ['MATRIX_URL', 'MATRIX_ID', 'MATRIX_PW']) MATRIX_URL, MATRIX_ID, MATRIX_PW = (environ[v] for v in ['MATRIX_URL', 'MATRIX_ID', 'MATRIX_PW'])
def check_json(url: str, key: str) -> bool:
"""Ensure a service at a given url answers with valid json containing a certain key."""
try:
data = httpx.get(url).json()
return key in data
except httpx.ConnectError:
return False
def wait_available(url: str, key: str, timeout: int = 10) -> bool: def wait_available(url: str, key: str, timeout: int = 10) -> bool:
"""Wait until a service answer correctly or timeout.""" """Wait until a service answer correctly or timeout."""
def check_json(url: str, key: str) -> bool:
"""Ensure a service at a given url answers with valid json containing a certain key."""
try:
data = httpx.get(url).json()
return key in data
except httpx.ConnectError:
return False
start = time() start = time()
while True: while True:
if check_json(url, key): if check_json(url, key):
@ -38,7 +37,7 @@ def run_and_test():
if not wait_available(f'{MATRIX_URL}/_matrix/client/r0/login', 'flows'): if not wait_available(f'{MATRIX_URL}/_matrix/client/r0/login', 'flows'):
return False return False
# Try to register an user for the bot. # Try to register a user for the bot.
with open('/srv/homeserver.yaml') as f: with open('/srv/homeserver.yaml') as f:
secret = yaml.safe_load(f.read()).get("registration_shared_secret", None) secret = yaml.safe_load(f.read()).get("registration_shared_secret", None)
request_registration(MATRIX_ID, MATRIX_PW, MATRIX_URL, secret, admin=True) request_registration(MATRIX_ID, MATRIX_PW, MATRIX_URL, secret, admin=True)