| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -71,7 +71,7 @@ def __getitem__(self, key): | |||
| 71 | 71 | return self._bindings[key] | |
| 72 | 72 | ||
| 73 | 73 | def __setitem__(self, key, value): | |
| 74 | - self._bindings[key] = frozenset(value) | ||
| 74 | + self._bindings[key] = set(value) | ||
| 75 | 75 | ||
| 76 | 76 | def __delitem__(self, key): | |
| 77 | 77 | del self._bindings[key] | |
@@ -91,7 +91,7 @@ def owners(self, value): | |||
| 91 | 91 | warnings.warn( | |
| 92 | 92 | _ASSIGNMENT_DEPRECATED_MSG.format('owners', OWNER_ROLE), | |
| 93 | 93 | DeprecationWarning) | |
| 94 | - self._bindings[OWNER_ROLE] = list(value) | ||
| 94 | + self[OWNER_ROLE] = value | ||
| 95 | 95 | ||
| 96 | 96 | @property | |
| 97 | 97 | def editors(self): | |
@@ -108,7 +108,7 @@ def editors(self, value): | |||
| 108 | 108 | warnings.warn( | |
| 109 | 109 | _ASSIGNMENT_DEPRECATED_MSG.format('editors', EDITOR_ROLE), | |
| 110 | 110 | DeprecationWarning) | |
| 111 | - self._bindings[EDITOR_ROLE] = list(value) | ||
| 111 | + self[EDITOR_ROLE] = value | ||
| 112 | 112 | ||
| 113 | 113 | @property | |
| 114 | 114 | def viewers(self): | |
@@ -125,7 +125,7 @@ def viewers(self, value): | |||
| 125 | 125 | warnings.warn( | |
| 126 | 126 | _ASSIGNMENT_DEPRECATED_MSG.format('viewers', VIEWER_ROLE), | |
| 127 | 127 | DeprecationWarning) | |
| 128 | - self._bindings[VIEWER_ROLE] = list(value) | ||
| 128 | + self[VIEWER_ROLE] = value | ||
| 129 | 129 | ||
| 130 | 130 | @staticmethod | |
| 131 | 131 | def user(email): | |
@@ -209,7 +209,7 @@ def from_api_repr(cls, resource): | |||
| 209 | 209 | for binding in resource.get('bindings', ()): | |
| 210 | 210 | role = binding['role'] | |
| 211 | 211 | members = sorted(binding['members']) | |
| 212 | - policy._bindings[role] = members | ||
| 212 | + policy[role] = members | ||
| 213 | 213 | return policy | |
| 214 | 214 | ||
| 215 | 215 | def to_api_repr(self): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,27 +27,26 @@ def _make_one(self, *args, **kw): | |||
| 27 | 27 | return self._get_target_class()(*args, **kw) | |
| 28 | 28 | ||
| 29 | 29 | def test_ctor_defaults(self): | |
| 30 | + empty = frozenset() | ||
| 30 | 31 | policy = self._make_one() | |
| 31 | 32 | self.assertIsNone(policy.etag) | |
| 32 | 33 | self.assertIsNone(policy.version) | |
| 33 | - self.assertIsInstance(policy.owners, frozenset) | ||
| 34 | - self.assertEqual(list(policy.owners), []) | ||
| 35 | - self.assertIsInstance(policy.editors, frozenset) | ||
| 36 | - self.assertEqual(list(policy.editors), []) | ||
| 37 | - self.assertIsInstance(policy.viewers, frozenset) | ||
| 38 | - self.assertEqual(list(policy.viewers), []) | ||
| 34 | + self.assertEqual(policy.owners, empty) | ||
| 35 | + self.assertEqual(policy.editors, empty) | ||
| 36 | + self.assertEqual(policy.viewers, empty) | ||
| 39 | 37 | self.assertEqual(len(policy), 0) | |
| 40 | 38 | self.assertEqual(dict(policy), {}) | |
| 41 | 39 | ||
| 42 | 40 | def test_ctor_explicit(self): | |
| 43 | 41 | VERSION = 17 | |
| 44 | 42 | ETAG = 'ETAG' | |
| 43 | + empty = frozenset() | ||
| 45 | 44 | policy = self._make_one(ETAG, VERSION) | |
| 46 | 45 | self.assertEqual(policy.etag, ETAG) | |
| 47 | 46 | self.assertEqual(policy.version, VERSION) | |
| 48 | - self.assertEqual(list(policy.owners), []) | ||
| 49 | - self.assertEqual(list(policy.editors), []) | ||
| 50 | - self.assertEqual(list(policy.viewers), []) | ||
| 47 | + self.assertEqual(policy.owners, empty) | ||
| 48 | + self.assertEqual(policy.editors, empty) | ||
| 49 | + self.assertEqual(policy.viewers, empty) | ||
| 51 | 50 | self.assertEqual(len(policy), 0) | |
| 52 | 51 | self.assertEqual(dict(policy), {}) | |
| 53 | 52 | ||
@@ -58,7 +57,7 @@ def test___getitem___miss(self): | |||
| 58 | 57 | ||
| 59 | 58 | def test___setitem__(self): | |
| 60 | 59 | USER = 'user:phred@example.com' | |
| 61 | - PRINCIPALS = frozenset([USER]) | ||
| 60 | + PRINCIPALS = set([USER]) | ||
| 62 | 61 | policy = self._make_one() | |
| 63 | 62 | policy['rolename'] = [USER] | |
| 64 | 63 | self.assertEqual(policy['rolename'], PRINCIPALS) | |
@@ -80,54 +79,59 @@ def test___delitem___miss(self): | |||
| 80 | 79 | def test_owners_getter(self): | |
| 81 | 80 | from google.cloud.iam import OWNER_ROLE | |
| 82 | 81 | MEMBER = 'user:phred@example.com' | |
| 82 | + expected = frozenset([MEMBER]) | ||
| 83 | 83 | policy = self._make_one() | |
| 84 | 84 | policy[OWNER_ROLE] = [MEMBER] | |
| 85 | - self.assertIsInstance(policy.owners, frozenset) | ||
| 86 | - self.assertEqual(list(policy.owners), [MEMBER]) | ||
| 85 | + self.assertEqual(policy.owners, expected) | ||
| 87 | 86 | ||
| 88 | 87 | def test_owners_setter(self): | |
| 89 | 88 | import warnings | |
| 90 | 89 | from google.cloud.iam import OWNER_ROLE | |
| 91 | 90 | MEMBER = 'user:phred@example.com' | |
| 91 | + expected = set([MEMBER]) | ||
| 92 | 92 | policy = self._make_one() | |
| 93 | 93 | with warnings.catch_warnings(): | |
| 94 | + warnings.simplefilter('always') | ||
| 94 | 95 | policy.owners = [MEMBER] | |
| 95 | - self.assertEqual(list(policy[OWNER_ROLE]), [MEMBER]) | ||
| 96 | + self.assertEqual(policy[OWNER_ROLE], expected) | ||
| 96 | 97 | ||
| 97 | 98 | def test_editors_getter(self): | |
| 98 | 99 | from google.cloud.iam import EDITOR_ROLE | |
| 99 | 100 | MEMBER = 'user:phred@example.com' | |
| 101 | + expected = frozenset([MEMBER]) | ||
| 100 | 102 | policy = self._make_one() | |
| 101 | 103 | policy[EDITOR_ROLE] = [MEMBER] | |
| 102 | - self.assertIsInstance(policy.editors, frozenset) | ||
| 103 | - self.assertEqual(list(policy.editors), [MEMBER]) | ||
| 104 | + self.assertEqual(policy.editors, expected) | ||
| 104 | 105 | ||
| 105 | 106 | def test_editors_setter(self): | |
| 106 | 107 | import warnings | |
| 107 | 108 | from google.cloud.iam import EDITOR_ROLE | |
| 108 | 109 | MEMBER = 'user:phred@example.com' | |
| 110 | + expected = set([MEMBER]) | ||
| 109 | 111 | policy = self._make_one() | |
| 110 | 112 | with warnings.catch_warnings(): | |
| 113 | + warnings.simplefilter('always') | ||
| 111 | 114 | policy.editors = [MEMBER] | |
| 112 | - self.assertEqual(list(policy[EDITOR_ROLE]), [MEMBER]) | ||
| 115 | + self.assertEqual(policy[EDITOR_ROLE], expected) | ||
| 113 | 116 | ||
| 114 | 117 | def test_viewers_getter(self): | |
| 115 | 118 | from google.cloud.iam import VIEWER_ROLE | |
| 116 | 119 | MEMBER = 'user:phred@example.com' | |
| 120 | + expected = frozenset([MEMBER]) | ||
| 117 | 121 | policy = self._make_one() | |
| 118 | 122 | policy[VIEWER_ROLE] = [MEMBER] | |
| 119 | - self.assertIsInstance(policy.viewers, frozenset) | ||
| 120 | - self.assertEqual(list(policy.viewers), [MEMBER]) | ||
| 123 | + self.assertEqual(policy.viewers, expected) | ||
| 121 | 124 | ||
| 122 | 125 | def test_viewers_setter(self): | |
| 123 | 126 | import warnings | |
| 124 | 127 | from google.cloud.iam import VIEWER_ROLE | |
| 125 | 128 | MEMBER = 'user:phred@example.com' | |
| 129 | + expected = set([MEMBER]) | ||
| 126 | 130 | policy = self._make_one() | |
| 127 | 131 | with warnings.catch_warnings(): | |
| 128 | 132 | warnings.simplefilter('always') | |
| 129 | 133 | policy.viewers = [MEMBER] | |
| 130 | - self.assertEqual(list(policy[VIEWER_ROLE]), [MEMBER]) | ||
| 134 | + self.assertEqual(policy[VIEWER_ROLE], expected) | ||
| 131 | 135 | ||
| 132 | 136 | def test_user(self): | |
| 133 | 137 | EMAIL = 'phred@example.com' | |
@@ -162,16 +166,17 @@ def test_authenticated_users(self): | |||
| 162 | 166 | self.assertEqual(policy.authenticated_users(), 'allAuthenticatedUsers') | |
| 163 | 167 | ||
| 164 | 168 | def test_from_api_repr_only_etag(self): | |
| 169 | + empty = frozenset() | ||
| 165 | 170 | RESOURCE = { | |
| 166 | 171 | 'etag': 'ACAB', | |
| 167 | 172 | } | |
| 168 | 173 | klass = self._get_target_class() | |
| 169 | 174 | policy = klass.from_api_repr(RESOURCE) | |
| 170 | 175 | self.assertEqual(policy.etag, 'ACAB') | |
| 171 | 176 | self.assertIsNone(policy.version) | |
| 172 | - self.assertEqual(list(policy.owners), []) | ||
| 173 | - self.assertEqual(list(policy.editors), []) | ||
| 174 | - self.assertEqual(list(policy.viewers), []) | ||
| 177 | + self.assertEqual(policy.owners, empty) | ||
| 178 | + self.assertEqual(policy.editors, empty) | ||
| 179 | + self.assertEqual(policy.viewers, empty) | ||
| 175 | 180 | self.assertEqual(dict(policy), {}) | |
| 176 | 181 | ||
| 177 | 182 | def test_from_api_repr_complete(self): | |
@@ -196,18 +201,19 @@ def test_from_api_repr_complete(self): | |||
| 196 | 201 | {'role': VIEWER_ROLE, 'members': [VIEWER1, VIEWER2]}, | |
| 197 | 202 | ], | |
| 198 | 203 | } | |
| 204 | + empty = frozenset() | ||
| 199 | 205 | klass = self._get_target_class() | |
| 200 | 206 | policy = klass.from_api_repr(RESOURCE) | |
| 201 | 207 | self.assertEqual(policy.etag, 'DEADBEEF') | |
| 202 | 208 | self.assertEqual(policy.version, 17) | |
| 203 | - self.assertEqual(sorted(policy.owners), [OWNER1, OWNER2]) | ||
| 204 | - self.assertEqual(sorted(policy.editors), [EDITOR1, EDITOR2]) | ||
| 205 | - self.assertEqual(sorted(policy.viewers), [VIEWER1, VIEWER2]) | ||
| 209 | + self.assertEqual(policy.owners, frozenset([OWNER1, OWNER2])) | ||
| 210 | + self.assertEqual(policy.editors, frozenset([EDITOR1, EDITOR2])) | ||
| 211 | + self.assertEqual(policy.viewers, frozenset([VIEWER1, VIEWER2])) | ||
| 206 | 212 | self.assertEqual( | |
| 207 | 213 | dict(policy), { | |
| 208 | - OWNER_ROLE: [OWNER1, OWNER2], | ||
| 209 | - EDITOR_ROLE: [EDITOR1, EDITOR2], | ||
| 210 | - VIEWER_ROLE: [VIEWER1, VIEWER2], | ||
| 214 | + OWNER_ROLE: set([OWNER1, OWNER2]), | ||
| 215 | + EDITOR_ROLE: set([EDITOR1, EDITOR2]), | ||
| 216 | + VIEWER_ROLE: set([VIEWER1, VIEWER2]), | ||
| 211 | 217 | }) | |
| 212 | 218 | ||
| 213 | 219 | def test_from_api_repr_unknown_role(self): | |
@@ -224,7 +230,7 @@ def test_from_api_repr_unknown_role(self): | |||
| 224 | 230 | policy = klass.from_api_repr(RESOURCE) | |
| 225 | 231 | self.assertEqual(policy.etag, 'DEADBEEF') | |
| 226 | 232 | self.assertEqual(policy.version, 17) | |
| 227 | - self.assertEqual(dict(policy), {'unknown': [GROUP, USER]}) | ||
| 233 | + self.assertEqual(dict(policy), {'unknown': set([GROUP, USER])}) | ||
| 228 | 234 | ||
| 229 | 235 | def test_to_api_repr_defaults(self): | |
| 230 | 236 | policy = self._make_one() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -121,7 +121,7 @@ def publishers(self, value): | |||
| 121 | 121 | _ASSIGNMENT_DEPRECATED_MSG.format( | |
| 122 | 122 | 'publishers', PUBSUB_PUBLISHER_ROLE), | |
| 123 | 123 | DeprecationWarning) | |
| 124 | - self._bindings[PUBSUB_PUBLISHER_ROLE] = list(value) | ||
| 124 | + self[PUBSUB_PUBLISHER_ROLE] = value | ||
| 125 | 125 | ||
| 126 | 126 | @property | |
| 127 | 127 | def subscribers(self): | |
@@ -135,4 +135,4 @@ def subscribers(self, value): | |||
| 135 | 135 | _ASSIGNMENT_DEPRECATED_MSG.format( | |
| 136 | 136 | 'subscribers', PUBSUB_SUBSCRIBER_ROLE), | |
| 137 | 137 | DeprecationWarning) | |
| 138 | - self._bindings[PUBSUB_SUBSCRIBER_ROLE] = list(value) | ||
| 138 | + self[PUBSUB_SUBSCRIBER_ROLE] = value | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,56 +27,55 @@ def _make_one(self, *args, **kw): | |||
| 27 | 27 | return self._get_target_class()(*args, **kw) | |
| 28 | 28 | ||
| 29 | 29 | def test_ctor_defaults(self): | |
| 30 | + empty = frozenset() | ||
| 30 | 31 | policy = self._make_one() | |
| 31 | 32 | self.assertIsNone(policy.etag) | |
| 32 | 33 | self.assertIsNone(policy.version) | |
| 33 | - self.assertIsInstance(policy.owners, frozenset) | ||
| 34 | - self.assertEqual(list(policy.owners), []) | ||
| 35 | - self.assertIsInstance(policy.editors, frozenset) | ||
| 36 | - self.assertEqual(list(policy.editors), []) | ||
| 37 | - self.assertIsInstance(policy.viewers, frozenset) | ||
| 38 | - self.assertEqual(list(policy.viewers), []) | ||
| 39 | - self.assertIsInstance(policy.publishers, frozenset) | ||
| 40 | - self.assertEqual(list(policy.publishers), []) | ||
| 41 | - self.assertIsInstance(policy.subscribers, frozenset) | ||
| 42 | - self.assertEqual(list(policy.subscribers), []) | ||
| 34 | + self.assertEqual(policy.owners, empty) | ||
| 35 | + self.assertEqual(policy.editors, empty) | ||
| 36 | + self.assertEqual(policy.viewers, empty) | ||
| 37 | + self.assertEqual(policy.publishers, empty) | ||
| 38 | + self.assertEqual(policy.subscribers, empty) | ||
| 43 | 39 | ||
| 44 | 40 | def test_ctor_explicit(self): | |
| 45 | 41 | VERSION = 17 | |
| 46 | 42 | ETAG = 'ETAG' | |
| 43 | + empty = frozenset() | ||
| 47 | 44 | policy = self._make_one(ETAG, VERSION) | |
| 48 | 45 | self.assertEqual(policy.etag, ETAG) | |
| 49 | 46 | self.assertEqual(policy.version, VERSION) | |
| 50 | - self.assertEqual(list(policy.owners), []) | ||
| 51 | - self.assertEqual(list(policy.editors), []) | ||
| 52 | - self.assertEqual(list(policy.viewers), []) | ||
| 53 | - self.assertEqual(list(policy.publishers), []) | ||
| 54 | - self.assertEqual(list(policy.subscribers), []) | ||
| 47 | + self.assertEqual(policy.owners, empty) | ||
| 48 | + self.assertEqual(policy.editors, empty) | ||
| 49 | + self.assertEqual(policy.viewers, empty) | ||
| 50 | + self.assertEqual(policy.publishers, empty) | ||
| 51 | + self.assertEqual(policy.subscribers, empty) | ||
| 55 | 52 | ||
| 56 | 53 | def test_publishers_setter(self): | |
| 57 | 54 | import warnings | |
| 58 | 55 | from google.cloud.pubsub.iam import ( | |
| 59 | 56 | PUBSUB_PUBLISHER_ROLE, | |
| 60 | 57 | ) | |
| 61 | 58 | PUBLISHER = 'user:phred@example.com' | |
| 59 | + expected = set([PUBLISHER]) | ||
| 62 | 60 | policy = self._make_one() | |
| 63 | 61 | with warnings.catch_warnings(): | |
| 64 | 62 | policy.publishers = [PUBLISHER] | |
| 65 | 63 | ||
| 66 | - self.assertEqual(sorted(policy.publishers), [PUBLISHER]) | ||
| 64 | + self.assertEqual(policy.publishers, frozenset(expected)) | ||
| 67 | 65 | self.assertEqual( | |
| 68 | - dict(policy), {PUBSUB_PUBLISHER_ROLE: [PUBLISHER]}) | ||
| 66 | + dict(policy), {PUBSUB_PUBLISHER_ROLE: expected}) | ||
| 69 | 67 | ||
| 70 | 68 | def test_subscribers_setter(self): | |
| 71 | 69 | import warnings | |
| 72 | 70 | from google.cloud.pubsub.iam import ( | |
| 73 | 71 | PUBSUB_SUBSCRIBER_ROLE, | |
| 74 | 72 | ) | |
| 75 | 73 | SUBSCRIBER = 'serviceAccount:1234-abcdef@service.example.com' | |
| 74 | + expected = set([SUBSCRIBER]) | ||
| 76 | 75 | policy = self._make_one() | |
| 77 | 76 | with warnings.catch_warnings(): | |
| 78 | 77 | policy.subscribers = [SUBSCRIBER] | |
| 79 | 78 | ||
| 80 | - self.assertEqual(sorted(policy.subscribers), [SUBSCRIBER]) | ||
| 79 | + self.assertEqual(policy.subscribers, frozenset(expected)) | ||
| 81 | 80 | self.assertEqual( | |
| 82 | - dict(policy), {PUBSUB_SUBSCRIBER_ROLE: [SUBSCRIBER]}) | ||
| 81 | + dict(policy), {PUBSUB_SUBSCRIBER_ROLE: expected}) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments