Run black on tests/rulecheck/test_domainrulecheck.py

This commit is contained in:
Erik Johnston 2019-03-18 14:23:46 +00:00
parent b85ff4b894
commit e64f7c0188

View file

@ -21,22 +21,24 @@ from tests import unittest
class DomainRuleCheckerTestCase(unittest.TestCase): class DomainRuleCheckerTestCase(unittest.TestCase):
def test_allowed(self): def test_allowed(self):
config = { config = {
"default": False, "default": False,
"domain_mapping": { "domain_mapping": {
"source_one": ["target_one", "target_two"], "source_one": ["target_one", "target_two"],
"source_two": ["target_two"] "source_two": ["target_two"],
} },
} }
check = DomainRuleChecker(config) check = DomainRuleChecker(config)
self.assertTrue(check.user_may_invite("test:source_one", self.assertTrue(
"test:target_one", "room")) check.user_may_invite("test:source_one", "test:target_one", "room")
self.assertTrue(check.user_may_invite("test:source_one", )
"test:target_two", "room")) self.assertTrue(
self.assertTrue(check.user_may_invite("test:source_two", check.user_may_invite("test:source_one", "test:target_two", "room")
"test:target_two", "room")) )
self.assertTrue(
check.user_may_invite("test:source_two", "test:target_two", "room")
)
def test_disallowed(self): def test_disallowed(self):
config = { config = {
@ -44,50 +46,56 @@ class DomainRuleCheckerTestCase(unittest.TestCase):
"domain_mapping": { "domain_mapping": {
"source_one": ["target_one", "target_two"], "source_one": ["target_one", "target_two"],
"source_two": ["target_two"], "source_two": ["target_two"],
"source_four": [] "source_four": [],
} },
} }
check = DomainRuleChecker(config) check = DomainRuleChecker(config)
self.assertFalse(check.user_may_invite("test:source_one", self.assertFalse(
"test:target_three", "room")) check.user_may_invite("test:source_one", "test:target_three", "room")
self.assertFalse(check.user_may_invite("test:source_two", )
"test:target_three", "room")) self.assertFalse(
self.assertFalse(check.user_may_invite("test:source_two", check.user_may_invite("test:source_two", "test:target_three", "room")
"test:target_one", "room")) )
self.assertFalse(check.user_may_invite("test:source_four", self.assertFalse(
"test:target_one", "room")) check.user_may_invite("test:source_two", "test:target_one", "room")
)
self.assertFalse(
check.user_may_invite("test:source_four", "test:target_one", "room")
)
def test_default_allow(self): def test_default_allow(self):
config = { config = {
"default": True, "default": True,
"domain_mapping": { "domain_mapping": {
"source_one": ["target_one", "target_two"], "source_one": ["target_one", "target_two"],
"source_two": ["target_two"] "source_two": ["target_two"],
} },
} }
check = DomainRuleChecker(config) check = DomainRuleChecker(config)
self.assertTrue(check.user_may_invite("test:source_three", self.assertTrue(
"test:target_one", "room")) check.user_may_invite("test:source_three", "test:target_one", "room")
)
def test_default_deny(self): def test_default_deny(self):
config = { config = {
"default": False, "default": False,
"domain_mapping": { "domain_mapping": {
"source_one": ["target_one", "target_two"], "source_one": ["target_one", "target_two"],
"source_two": ["target_two"] "source_two": ["target_two"],
} },
} }
check = DomainRuleChecker(config) check = DomainRuleChecker(config)
self.assertFalse(check.user_may_invite("test:source_three", self.assertFalse(
"test:target_one", "room")) check.user_may_invite("test:source_three", "test:target_one", "room")
)
def test_config_parse(self): def test_config_parse(self):
config = { config = {
"default": False, "default": False,
"domain_mapping": { "domain_mapping": {
"source_one": ["target_one", "target_two"], "source_one": ["target_one", "target_two"],
"source_two": ["target_two"] "source_two": ["target_two"],
} },
} }
self.assertEquals(config, DomainRuleChecker.parse_config(config)) self.assertEquals(config, DomainRuleChecker.parse_config(config))
@ -95,7 +103,7 @@ class DomainRuleCheckerTestCase(unittest.TestCase):
config = { config = {
"domain_mapping": { "domain_mapping": {
"source_one": ["target_one", "target_two"], "source_one": ["target_one", "target_two"],
"source_two": ["target_two"] "source_two": ["target_two"],
} }
} }
self.assertRaises(ConfigError, DomainRuleChecker.parse_config, config) self.assertRaises(ConfigError, DomainRuleChecker.parse_config, config)