mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-06-25 15:37:24 +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:
@ -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(
|
||||
|
@ -2,7 +2,7 @@ import os
|
||||
import re
|
||||
|
||||
from corres2math.lists import get_sympa_client
|
||||
from corres2math.matrix import Matrix
|
||||
from corres2math.matrix import Matrix, RoomPreset, RoomVisibility
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.core.validators import RegexValidator
|
||||
from django.db import models
|
||||
@ -13,7 +13,6 @@ from django.utils import timezone
|
||||
from django.utils.crypto import get_random_string
|
||||
from django.utils.text import format_lazy
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from nio import RoomPreset, RoomVisibility
|
||||
|
||||
|
||||
class Team(models.Model):
|
||||
|
@ -1,4 +1,3 @@
|
||||
import os
|
||||
from datetime import timedelta
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
@ -705,7 +704,6 @@ class TestStudentParticipation(TestCase):
|
||||
|
||||
call_command('fix_matrix_channels')
|
||||
call_command('setup_third_phase')
|
||||
os.remove(".matrix_avatar")
|
||||
|
||||
|
||||
class TestAdmin(TestCase):
|
||||
|
@ -12,7 +12,7 @@ from django.utils.encoding import force_bytes
|
||||
from django.utils.http import urlsafe_base64_encode
|
||||
|
||||
from .auth import CustomAuthUser
|
||||
from .models import AdminRegistration, CoachRegistration, Registration, StudentRegistration
|
||||
from .models import AdminRegistration, CoachRegistration, StudentRegistration
|
||||
|
||||
|
||||
class TestIndexPage(TestCase):
|
||||
|
Reference in New Issue
Block a user