Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Replace str constants with Membership attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
anoadragon453 committed Jun 18, 2021
1 parent 3911959 commit 15f833b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
14 changes: 7 additions & 7 deletions synapse/rest/client/v2_alpha/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,20 +262,20 @@ async def encode_response(self, time_now, sync_result, access_token_id, filter):
] = sync_result.device_unused_fallback_key_types

if joined:
response["rooms"]["join"] = joined
response["rooms"][Membership.JOIN] = joined
if invited:
response["rooms"]["invite"] = invited
response["rooms"][Membership.INVITE] = invited
if knocked:
response["rooms"]["knock"] = knocked
response["rooms"][Membership.KNOCK] = knocked
if archived:
response["rooms"]["leave"] = archived
response["rooms"][Membership.LEAVE] = archived

if sync_result.groups.join:
response["groups"]["join"] = sync_result.groups.join
response["groups"][Membership.JOIN] = sync_result.groups.join
if sync_result.groups.invite:
response["groups"]["invite"] = sync_result.groups.invite
response["groups"][Membership.INVITE] = sync_result.groups.invite
if sync_result.groups.leave:
response["groups"]["leave"] = sync_result.groups.leave
response["groups"][Membership.LEAVE] = sync_result.groups.leave

return response

Expand Down
11 changes: 8 additions & 3 deletions tests/rest/client/v2_alpha/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
import json

import synapse.rest.admin
from synapse.api.constants import EventContentFields, EventTypes, RelationTypes
from synapse.api.constants import (
EventContentFields,
EventTypes,
Membership,
RelationTypes,
)
from synapse.rest.client.v1 import login, room
from synapse.rest.client.v2_alpha import knock, read_marker, sync

Expand Down Expand Up @@ -343,7 +348,7 @@ def test_knock_room_state(self):

# We expect to see the knock event in the stripped room state later
self.expected_room_state[EventTypes.Member] = {
"content": {"membership": "knock", "displayname": "knocker"},
"content": {"membership": Membership.KNOCK, "displayname": "knocker"},
"state_key": "@knocker:test",
}

Expand All @@ -356,7 +361,7 @@ def test_knock_room_state(self):
self.assertEqual(channel.code, 200, channel.json_body)

# Extract the stripped room state events from /sync
knock_entry = channel.json_body["rooms"]["knock"]
knock_entry = channel.json_body["rooms"][Membership.KNOCK]
room_state_events = knock_entry[self.room_id]["knock_state"]["events"]

# Validate that the knock membership event came last
Expand Down
13 changes: 10 additions & 3 deletions tests/server_notices/test_resource_limits_server_notices.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@

from twisted.internet import defer

from synapse.api.constants import EventTypes, LimitBlockingTypes, ServerNoticeMsgType
from synapse.api.constants import (
EventTypes,
LimitBlockingTypes,
Membership,
ServerNoticeMsgType,
)
from synapse.api.errors import ResourceLimitError
from synapse.rest import admin
from synapse.rest.client.v1 import login, room
Expand Down Expand Up @@ -322,7 +327,9 @@ def test_invite_with_notice(self):

# Scan the events in the room to search for a message from the server notices
# user.
events = channel.json_body["rooms"]["join"][room_id]["timeline"]["events"]
events = channel.json_body["rooms"][Membership.JOIN][room_id]["timeline"][
"events"
]
notice_in_room = False
for event in events:
if (
Expand Down Expand Up @@ -366,7 +373,7 @@ def _trigger_notice_and_join(self):
# invite to a system notices room, but it doesn't matter which user we're
# using so we use the last one because it saves us an extra sync.
if "rooms" in channel.json_body:
invites = channel.json_body["rooms"]["invite"]
invites = channel.json_body["rooms"][Membership.INVITE]

# Make sure we have an invite to process.
self.assertEqual(len(invites), 1, invites)
Expand Down

0 comments on commit 15f833b

Please sign in to comment.