| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 from components import auth | 5 from components import auth |
| 6 from testing_utils import testing | 6 from testing_utils import testing |
| 7 import mock | 7 import mock |
| 8 | 8 |
| 9 from proto import project_config_pb2 | 9 from proto import project_config_pb2 |
| 10 from test import future | 10 from test import future |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 acls=[ | 43 acls=[ |
| 44 Acl(role=Acl.READER, group='c-readers'), | 44 Acl(role=Acl.READER, group='c-readers'), |
| 45 Acl(role=Acl.READER, identity='user:a@example.com'), | 45 Acl(role=Acl.READER, identity='user:a@example.com'), |
| 46 Acl(role=Acl.WRITER, group='c-writers'), | 46 Acl(role=Acl.WRITER, group='c-writers'), |
| 47 ]) | 47 ]) |
| 48 all_buckets = [bucket_a, bucket_b, bucket_c] | 48 all_buckets = [bucket_a, bucket_b, bucket_c] |
| 49 config.get_buckets_async.return_value = future(all_buckets) | 49 config.get_buckets_async.return_value = future(all_buckets) |
| 50 bucket_map = {b.name: b for b in all_buckets} | 50 bucket_map = {b.name: b for b in all_buckets} |
| 51 | 51 |
| 52 self.mock( | 52 self.mock( |
| 53 config, 'get_bucket_async', lambda name: future(bucket_map.get(name))) | 53 config, 'get_bucket_async', |
| 54 lambda name: future(('chromium', bucket_map.get(name)))) |
| 54 | 55 |
| 55 def mock_is_group_member(self, groups): | 56 def mock_is_group_member(self, groups): |
| 56 # pylint: disable=unused-argument | 57 # pylint: disable=unused-argument |
| 57 def is_group_member(group, identity=None): | 58 def is_group_member(group, identity=None): |
| 58 return group in groups | 59 return group in groups |
| 59 | 60 |
| 60 self.mock(auth, 'is_group_member', is_group_member) | 61 self.mock(auth, 'is_group_member', is_group_member) |
| 61 | 62 |
| 62 def test_has_any_of_roles(self): | 63 def test_has_any_of_roles(self): |
| 63 self.mock_is_group_member(['a-readers']) | 64 self.mock_is_group_member(['a-readers']) |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 | 146 |
| 146 def test_can_bad_input(self): | 147 def test_can_bad_input(self): |
| 147 with self.assertRaises(errors.InvalidInputError): | 148 with self.assertRaises(errors.InvalidInputError): |
| 148 acl.can('bad bucket name', acl.Action.VIEW_BUILD) | 149 acl.can('bad bucket name', acl.Action.VIEW_BUILD) |
| 149 | 150 |
| 150 def test_can_view_build(self): | 151 def test_can_view_build(self): |
| 151 self.mock_has_any_of_roles([Acl.READER]) | 152 self.mock_has_any_of_roles([Acl.READER]) |
| 152 build = model.Build(bucket='bucket') | 153 build = model.Build(bucket='bucket') |
| 153 self.assertTrue(acl.can_view_build(build)) | 154 self.assertTrue(acl.can_view_build(build)) |
| 154 self.assertFalse(acl.can_lease_build(build)) | 155 self.assertFalse(acl.can_lease_build(build)) |
| OLD | NEW |