1
0
mirror of https://gitlab.com/animath/si/plateforme-corres2math.git synced 2025-06-22 08:38:21 +02:00

Tests should not depend on Matrix-nio, that uses lxml that needs a lot of dependencies and a lot of time to build

This commit is contained in:
Yohann D'ANELLO
2020-11-03 20:52:55 +01:00
parent 1ddf39f296
commit 04dd02b88a
11 changed files with 110 additions and 85 deletions

View File

@ -1,9 +1,8 @@
import os
from asgiref.sync import async_to_sync
from corres2math.matrix import Matrix, RoomVisibility, UploadError
from corres2math.matrix import Matrix, RoomPreset, RoomVisibility
from django.core.management import BaseCommand
from nio import RoomPreset
from registration.models import AdminRegistration, Registration
@ -11,19 +10,23 @@ class Command(BaseCommand):
def handle(self, *args, **options):
Matrix.set_display_name("Bot des Correspondances")
if not os.path.isfile(".matrix_avatar"): # pragma: no cover
stat_file = os.stat("corres2math/static/logo.png")
with open("corres2math/static/logo.png", "rb") as f:
resp, _ = Matrix.upload(f, filename="logo.png", content_type="image/png", filesize=stat_file.st_size)
if isinstance(resp, UploadError):
raise Exception(resp)
avatar_uri = resp.content_uri
with open(".matrix_avatar", "w") as f:
f.write(avatar_uri)
Matrix.set_avatar(avatar_uri)
if not os.getenv("SYNAPSE_PASSWORD"):
avatar_uri = "plop"
else: # pragma: no cover
if not os.path.isfile(".matrix_avatar"):
stat_file = os.stat("corres2math/static/logo.png")
with open("corres2math/static/logo.png", "rb") as f:
resp, _ = Matrix.upload(f, filename="logo.png", content_type="image/png",
filesize=stat_file.st_size)
if not hasattr(resp, "content_uri"):
raise Exception(resp)
avatar_uri = resp.content_uri
with open(".matrix_avatar", "w") as f:
f.write(avatar_uri)
Matrix.set_avatar(avatar_uri)
with open(".matrix_avatar", "r") as f:
avatar_uri = f.read().rstrip(" \t\r\n")
with open(".matrix_avatar", "r") as f:
avatar_uri = f.read().rstrip(" \t\r\n")
if not async_to_sync(Matrix.resolve_room_alias)("#faq:correspondances-maths.fr"):
Matrix.create_room(