summary refs log tree commit diff
path: root/tests/rest
diff options
context:
space:
mode:
authorAndrew Morgan <1342360+anoadragon453@users.noreply.github.com>2020-09-10 19:04:34 +0100
committerGitHub <noreply@github.com>2020-09-10 19:04:34 +0100
commit3d1c941a6eb6e9192ac17e00f5beef1ceea1b11c (patch)
tree0440d8dee470ea3bb556234db3d10e9ac15ca447 /tests/rest
parentAdd a config option for validating 'next_link' parameters against a domain wh... (diff)
downloadsynapse-3d1c941a6eb6e9192ac17e00f5beef1ceea1b11c.tar.xz
RoomAccessRules cleanup (#62)
Various cleanups of the DINUM-specific `RoomAccessRules` module, including:

* Type hints
* Docstring cleanups
* Some code cleanups
Diffstat (limited to 'tests/rest')
-rw-r--r--tests/rest/client/test_room_access_rules.py61
1 files changed, 27 insertions, 34 deletions
diff --git a/tests/rest/client/test_room_access_rules.py b/tests/rest/client/test_room_access_rules.py

index 7da0ef4e18..42580c0f05 100644 --- a/tests/rest/client/test_room_access_rules.py +++ b/tests/rest/client/test_room_access_rules.py
@@ -12,8 +12,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - - import json import random import string @@ -25,12 +23,7 @@ from twisted.internet import defer from synapse.api.constants import EventTypes, JoinRules, RoomCreationPreset from synapse.rest import admin from synapse.rest.client.v1 import login, room -from synapse.third_party_rules.access_rules import ( - ACCESS_RULE_DIRECT, - ACCESS_RULE_RESTRICTED, - ACCESS_RULE_UNRESTRICTED, - ACCESS_RULES_TYPE, -) +from synapse.third_party_rules.access_rules import ACCESS_RULES_TYPE, AccessRules from tests import unittest @@ -109,7 +102,7 @@ class RoomAccessTestCase(unittest.HomeserverTestCase): self.tok = self.login("kermit", "monkey") self.restricted_room = self.create_room() - self.unrestricted_room = self.create_room(rule=ACCESS_RULE_UNRESTRICTED) + self.unrestricted_room = self.create_room(rule=AccessRules.UNRESTRICTED) self.direct_rooms = [ self.create_room(direct=True), self.create_room(direct=True), @@ -127,34 +120,34 @@ class RoomAccessTestCase(unittest.HomeserverTestCase): ) def test_create_room_no_rule(self): - """Tests that creating a room with no rule will set the default value.""" + """Tests that creating a room with no rule will set the default.""" room_id = self.create_room() rule = self.current_rule_in_room(room_id) - self.assertEqual(rule, ACCESS_RULE_RESTRICTED) + self.assertEqual(rule, AccessRules.RESTRICTED) def test_create_room_direct_no_rule(self): - """Tests that creating a direct room with no rule will set the default value.""" + """Tests that creating a direct room with no rule will set the default.""" room_id = self.create_room(direct=True) rule = self.current_rule_in_room(room_id) - self.assertEqual(rule, ACCESS_RULE_DIRECT) + self.assertEqual(rule, AccessRules.DIRECT) def test_create_room_valid_rule(self): - """Tests that creating a room with a valid rule will set the right value.""" - room_id = self.create_room(rule=ACCESS_RULE_UNRESTRICTED) + """Tests that creating a room with a valid rule will set the right.""" + room_id = self.create_room(rule=AccessRules.UNRESTRICTED) rule = self.current_rule_in_room(room_id) - self.assertEqual(rule, ACCESS_RULE_UNRESTRICTED) + self.assertEqual(rule, AccessRules.UNRESTRICTED) def test_create_room_invalid_rule(self): """Tests that creating a room with an invalid rule will set fail.""" - self.create_room(rule=ACCESS_RULE_DIRECT, expected_code=400) + self.create_room(rule=AccessRules.DIRECT, expected_code=400) def test_create_room_direct_invalid_rule(self): """Tests that creating a direct room with an invalid rule will fail. """ - self.create_room(direct=True, rule=ACCESS_RULE_RESTRICTED, expected_code=400) + self.create_room(direct=True, rule=AccessRules.RESTRICTED, expected_code=400) def test_public_room(self): """Tests that it's not possible to have a room with the public join rule and an @@ -164,7 +157,7 @@ class RoomAccessTestCase(unittest.HomeserverTestCase): # rule to restricted. preset_room_id = self.create_room(preset=RoomCreationPreset.PUBLIC_CHAT) self.assertEqual( - self.current_rule_in_room(preset_room_id), ACCESS_RULE_RESTRICTED + self.current_rule_in_room(preset_room_id), AccessRules.RESTRICTED ) # Creating a room with the public join rule in its initial state should succeed @@ -178,21 +171,21 @@ class RoomAccessTestCase(unittest.HomeserverTestCase): ] ) self.assertEqual( - self.current_rule_in_room(init_state_room_id), ACCESS_RULE_RESTRICTED + self.current_rule_in_room(init_state_room_id), AccessRules.RESTRICTED ) # Changing access rule to unrestricted should fail. self.change_rule_in_room( - preset_room_id, ACCESS_RULE_UNRESTRICTED, expected_code=403 + preset_room_id, AccessRules.UNRESTRICTED, expected_code=403 ) self.change_rule_in_room( - init_state_room_id, ACCESS_RULE_UNRESTRICTED, expected_code=403 + init_state_room_id, AccessRules.UNRESTRICTED, expected_code=403 ) # Changing access rule to direct should fail. - self.change_rule_in_room(preset_room_id, ACCESS_RULE_DIRECT, expected_code=403) + self.change_rule_in_room(preset_room_id, AccessRules.DIRECT, expected_code=403) self.change_rule_in_room( - init_state_room_id, ACCESS_RULE_DIRECT, expected_code=403 + init_state_room_id, AccessRules.DIRECT, expected_code=403 ) # Changing join rule to public in an unrestricted room should fail. @@ -208,12 +201,12 @@ class RoomAccessTestCase(unittest.HomeserverTestCase): # restricted should fail. self.create_room( preset=RoomCreationPreset.PUBLIC_CHAT, - rule=ACCESS_RULE_UNRESTRICTED, + rule=AccessRules.UNRESTRICTED, expected_code=400, ) self.create_room( preset=RoomCreationPreset.PUBLIC_CHAT, - rule=ACCESS_RULE_DIRECT, + rule=AccessRules.DIRECT, expected_code=400, ) @@ -226,7 +219,7 @@ class RoomAccessTestCase(unittest.HomeserverTestCase): "content": {"join_rule": JoinRules.PUBLIC}, } ], - rule=ACCESS_RULE_UNRESTRICTED, + rule=AccessRules.UNRESTRICTED, expected_code=400, ) self.create_room( @@ -236,7 +229,7 @@ class RoomAccessTestCase(unittest.HomeserverTestCase): "content": {"join_rule": JoinRules.PUBLIC}, } ], - rule=ACCESS_RULE_DIRECT, + rule=AccessRules.DIRECT, expected_code=400, ) @@ -446,40 +439,40 @@ class RoomAccessTestCase(unittest.HomeserverTestCase): # We can change the rule from restricted to unrestricted. self.change_rule_in_room( room_id=self.restricted_room, - new_rule=ACCESS_RULE_UNRESTRICTED, + new_rule=AccessRules.UNRESTRICTED, expected_code=200, ) # We can't change the rule from restricted to direct. self.change_rule_in_room( - room_id=self.restricted_room, new_rule=ACCESS_RULE_DIRECT, expected_code=403 + room_id=self.restricted_room, new_rule=AccessRules.DIRECT, expected_code=403 ) # We can't change the rule from unrestricted to restricted. self.change_rule_in_room( room_id=self.unrestricted_room, - new_rule=ACCESS_RULE_RESTRICTED, + new_rule=AccessRules.RESTRICTED, expected_code=403, ) # We can't change the rule from unrestricted to direct. self.change_rule_in_room( room_id=self.unrestricted_room, - new_rule=ACCESS_RULE_DIRECT, + new_rule=AccessRules.DIRECT, expected_code=403, ) # We can't change the rule from direct to restricted. self.change_rule_in_room( room_id=self.direct_rooms[0], - new_rule=ACCESS_RULE_RESTRICTED, + new_rule=AccessRules.RESTRICTED, expected_code=403, ) # We can't change the rule from direct to unrestricted. self.change_rule_in_room( room_id=self.direct_rooms[0], - new_rule=ACCESS_RULE_UNRESTRICTED, + new_rule=AccessRules.UNRESTRICTED, expected_code=403, )