File size: 1,814 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 |
from unittest import TestCase
from gcsa.acl import AccessControlRule, ACLRole, ACLScopeType
from gcsa.serializers.acl_rule_serializer import ACLRuleSerializer
class TestACLRule(TestCase):
def test_repr_str(self):
acl_rule = AccessControlRule(
role=ACLRole.READER,
scope_type=ACLScopeType.USER,
scope_value='[email protected]'
)
self.assertEqual(acl_rule.__repr__(), "<AccessControlRule [email protected] - reader>")
self.assertEqual(acl_rule.__str__(), "[email protected] - reader")
class TestACLRuleSerializer(TestCase):
def test_to_json(self):
acl_rule = AccessControlRule(
role=ACLRole.READER,
scope_type=ACLScopeType.USER,
acl_id='user:[email protected]',
scope_value='[email protected]'
)
acl_rule_json = ACLRuleSerializer.to_json(acl_rule)
self.assertEqual(acl_rule.role, acl_rule_json['role'])
self.assertEqual(acl_rule.scope_type, acl_rule_json['scope']['type'])
self.assertEqual(acl_rule.acl_id, acl_rule_json['id'])
self.assertEqual(acl_rule.scope_value, acl_rule_json['scope']['value'])
def test_to_object(self):
acl_rule_json = {
'id': 'user:[email protected]',
'scope': {
'type': 'user',
'value': '[email protected]'
},
'role': 'reader'
}
acl_rule = ACLRuleSerializer.to_object(acl_rule_json)
self.assertEqual(acl_rule_json['role'], acl_rule.role)
self.assertEqual(acl_rule_json['scope']['type'], acl_rule.scope_type)
self.assertEqual(acl_rule_json['id'], acl_rule.acl_id)
self.assertEqual(acl_rule_json['scope']['value'], acl_rule.scope_value)
|