File size: 2,839 Bytes
550665c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
from gcsa.acl import AccessControlRule, ACLRole, ACLScopeType
from tests.google_calendar_tests.test_case_with_mocked_service import TestCaseWithMockedService
class TestACLService(TestCaseWithMockedService):
def test_get_access_control_list(self):
acl_rules = list(self.gc.get_acl_rules())
self.assertEqual(len(acl_rules), 8)
def test_get_acl_rule(self):
acl_rule = self.gc.get_acl_rule(rule_id='user:[email protected]')
self.assertEqual(acl_rule.acl_id, 'user:[email protected]')
self.assertEqual(acl_rule.role, 'reader')
self.assertEqual(acl_rule.scope_type, 'user')
self.assertEqual(acl_rule.scope_value, '[email protected]')
def test_add_acl_rule(self):
acl_rule = AccessControlRule(
role=ACLRole.WRITER,
scope_type=ACLScopeType.DOMAIN,
scope_value='test.com'
)
acl_rule = self.gc.add_acl_rule(acl_rule)
self.assertEqual(acl_rule.acl_id, 'domain:test.com')
self.assertEqual(acl_rule.role, 'writer')
self.assertEqual(acl_rule.scope_type, 'domain')
self.assertEqual(acl_rule.scope_value, 'test.com')
def test_update_acl_rule(self):
acl_rule = self.gc.get_acl_rule(rule_id='user:[email protected]')
acl_rule.role = ACLRole.FREE_BUSY_READER
self.gc.update_acl_rule(acl_rule)
acl_rule = self.gc.get_acl_rule(rule_id='user:[email protected]')
self.assertEqual(acl_rule.acl_id, 'user:[email protected]')
self.assertEqual(acl_rule.role, 'freeBusyReader')
self.assertEqual(acl_rule.scope_type, 'user')
self.assertEqual(acl_rule.scope_value, '[email protected]')
def test_delete_acl_rule(self):
self.gc.delete_acl_rule(acl_rule='user:[email protected]')
self.gc.delete_acl_rule(
acl_rule=AccessControlRule(
role=ACLRole.READER,
scope_type=ACLScopeType.GROUP,
acl_id='group:[email protected]',
scope_value='[email protected]'
)
)
deleted_ids = ('user:[email protected]', 'group:[email protected]')
acl_rules = list(self.gc.get_acl_rules())
self.assertEqual(len(acl_rules), 6)
self.assertTrue(all(r.id not in deleted_ids for r in acl_rules))
acl_rule = AccessControlRule(
role=ACLRole.READER,
scope_type=ACLScopeType.GROUP,
scope_value='[email protected]'
)
with self.assertRaises(ValueError):
# no acl_id
self.gc.delete_acl_rule(acl_rule)
with self.assertRaises(TypeError):
# should be a AccessControlRule or acl rule id as a string
self.gc.delete_acl_rule(acl_rule=None)
|