mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-07-07 21:20:13 +02:00
Cover also settings files, keep 100% coverage by ignoring production files
This commit is contained in:
@ -22,7 +22,7 @@ class Matrix:
|
||||
_device_id: str = None
|
||||
|
||||
@classmethod
|
||||
async def _get_client(cls) -> Union[AsyncClient, "FakeMatrixClient"]:
|
||||
async def _get_client(cls) -> Union[AsyncClient, "FakeMatrixClient"]: # pragma: no cover
|
||||
"""
|
||||
Retrieve the bot account.
|
||||
If not logged, log in and store access token.
|
||||
@ -133,7 +133,8 @@ class Matrix:
|
||||
If left as ``None``, some servers might refuse the upload.
|
||||
"""
|
||||
client = await cls._get_client()
|
||||
return await client.upload(data_provider, content_type, filename, encrypt, monitor, filesize)
|
||||
return await client.upload(data_provider, content_type, filename, encrypt, monitor, filesize) \
|
||||
if isinstance(client, AsyncClient) else UploadResponse("debug mode"), None
|
||||
|
||||
@classmethod
|
||||
@async_to_sync
|
||||
@ -219,9 +220,7 @@ class Matrix:
|
||||
"""
|
||||
client = await cls._get_client()
|
||||
resp: RoomResolveAliasResponse = await client.room_resolve_alias(room_alias)
|
||||
if isinstance(resp, RoomResolveAliasResponse):
|
||||
return resp.room_id
|
||||
return None
|
||||
return resp.room_id if isinstance(resp, RoomResolveAliasResponse) else None
|
||||
|
||||
@classmethod
|
||||
@async_to_sync
|
||||
@ -291,7 +290,7 @@ class Matrix:
|
||||
@classmethod
|
||||
@async_to_sync
|
||||
async def set_room_power_level(cls, room_id: str, user_id: str, power_level: int)\
|
||||
-> Union[RoomPutStateResponse, RoomPutStateError]:
|
||||
-> Union[RoomPutStateResponse, RoomPutStateError]: # pragma: no cover
|
||||
"""
|
||||
Put a given power level to a user in a certain room.
|
||||
|
||||
@ -306,6 +305,9 @@ class Matrix:
|
||||
power_level (int): The target power level to give.
|
||||
"""
|
||||
client = await cls._get_client()
|
||||
if isinstance(client, FakeMatrixClient):
|
||||
return RoomPutStateError("debug mode")
|
||||
|
||||
if room_id.startswith("#"):
|
||||
room_id = await cls.resolve_room_alias(room_id)
|
||||
resp = await client.room_get_state_event(room_id, "m.room.power_levels")
|
||||
@ -316,7 +318,7 @@ class Matrix:
|
||||
@classmethod
|
||||
@async_to_sync
|
||||
async def set_room_power_level_event(cls, room_id: str, event: str, power_level: int)\
|
||||
-> Union[RoomPutStateResponse, RoomPutStateError]:
|
||||
-> Union[RoomPutStateResponse, RoomPutStateError]: # pragma: no cover
|
||||
"""
|
||||
Define the minimal power level to have to send a certain event type
|
||||
in a given room.
|
||||
@ -332,6 +334,9 @@ class Matrix:
|
||||
power_level (int): The target power level to give.
|
||||
"""
|
||||
client = await cls._get_client()
|
||||
if isinstance(client, FakeMatrixClient):
|
||||
return RoomPutStateError("debug mode")
|
||||
|
||||
if room_id.startswith("#"):
|
||||
room_id = await cls.resolve_room_alias(room_id)
|
||||
resp = await client.room_get_state_event(room_id, "m.room.power_levels")
|
||||
|
Reference in New Issue
Block a user