| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The LUCI Authors. All rights reserved. | 2 # Copyright 2015 The LUCI Authors. All rights reserved. |
| 3 # Use of this source code is governed under the Apache License, Version 2.0 | 3 # Use of this source code is governed under the Apache License, Version 2.0 |
| 4 # that can be found in the LICENSE file. | 4 # that can be found in the LICENSE file. |
| 5 | 5 |
| 6 import base64 | 6 import base64 |
| 7 import datetime | 7 import datetime |
| 8 import httplib | 8 import httplib |
| 9 | 9 |
| 10 import test_env | 10 import test_env |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 lambda pids: {pid: pid != 'secret' for pid in pids} | 36 lambda pids: {pid: pid != 'secret' for pid in pids} |
| 37 ) | 37 ) |
| 38 | 38 |
| 39 self.mock( | 39 self.mock( |
| 40 acl, 'has_services_access', lambda sids: {sid: True for sid in sids}) | 40 acl, 'has_services_access', lambda sids: {sid: True for sid in sids}) |
| 41 self.mock(projects, 'get_projects', mock.Mock()) | 41 self.mock(projects, 'get_projects', mock.Mock()) |
| 42 projects.get_projects.return_value = [ | 42 projects.get_projects.return_value = [ |
| 43 service_config_pb2.Project(id='chromium'), | 43 service_config_pb2.Project(id='chromium'), |
| 44 service_config_pb2.Project(id='v8'), | 44 service_config_pb2.Project(id='v8'), |
| 45 ] | 45 ] |
| 46 self.mock(projects, 'get_metadata', mock.Mock()) | 46 self.mock(projects, 'get_metadata_async', mock.Mock(return_value=future({ |
| 47 projects.get_metadata.return_value = { | |
| 48 'chromium': project_config_pb2.ProjectCfg(), | 47 'chromium': project_config_pb2.ProjectCfg(), |
| 49 'v8': project_config_pb2.ProjectCfg(), | 48 'v8': project_config_pb2.ProjectCfg(), |
| 50 } | 49 }))) |
| 51 self.mock(projects, 'get_repos', mock.Mock()) | 50 self.mock(projects, 'get_repos_async', mock.Mock(return_value=future({ |
| 52 projects.get_repos.return_value = { | |
| 53 'chromium': ( | 51 'chromium': ( |
| 54 projects.RepositoryType.GITILES, 'https://chromium.example.com'), | 52 projects.RepositoryType.GITILES, 'https://chromium.example.com'), |
| 55 'v8': ( | 53 'v8': ( |
| 56 projects.RepositoryType.GITILES, 'https://v8.example.com'), | 54 projects.RepositoryType.GITILES, 'https://v8.example.com'), |
| 57 } | 55 }))) |
| 58 | 56 |
| 59 def mock_config(self, mock_content=True): | 57 def mock_config(self, mock_content=True): |
| 60 self.mock(storage, 'get_config_hashes_async', mock.Mock()) | 58 self.mock(storage, 'get_config_hashes_async', mock.Mock()) |
| 61 storage.get_config_hashes_async.return_value = future({ | 59 storage.get_config_hashes_async.return_value = future({ |
| 62 'services/luci-config': ('deadbeef', 'abc0123'), | 60 'services/luci-config': ('deadbeef', 'abc0123'), |
| 63 }) | 61 }) |
| 64 | 62 |
| 65 if mock_content: | 63 if mock_content: |
| 66 self.mock(storage, 'get_configs_by_hashes_async', mock.Mock()) | 64 self.mock(storage, 'get_configs_by_hashes_async', mock.Mock()) |
| 67 storage.get_configs_by_hashes_async.return_value = future({ | 65 storage.get_configs_by_hashes_async.return_value = future({ |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 ############################################################################## | 485 ############################################################################## |
| 488 # get_projects | 486 # get_projects |
| 489 | 487 |
| 490 def test_get_projects(self): | 488 def test_get_projects(self): |
| 491 projects.get_projects.return_value = [ | 489 projects.get_projects.return_value = [ |
| 492 service_config_pb2.Project(id='chromium'), | 490 service_config_pb2.Project(id='chromium'), |
| 493 service_config_pb2.Project(id='v8'), | 491 service_config_pb2.Project(id='v8'), |
| 494 service_config_pb2.Project(id='inconsistent'), | 492 service_config_pb2.Project(id='inconsistent'), |
| 495 service_config_pb2.Project(id='secret'), | 493 service_config_pb2.Project(id='secret'), |
| 496 ] | 494 ] |
| 497 projects.get_metadata.return_value = { | 495 projects.get_metadata_async.return_value = future({ |
| 498 'chromium': project_config_pb2.ProjectCfg( | 496 'chromium': project_config_pb2.ProjectCfg( |
| 499 name='Chromium, the best browser', access='all'), | 497 name='Chromium, the best browser', access='all'), |
| 500 'v8': project_config_pb2.ProjectCfg(access='all'), | 498 'v8': project_config_pb2.ProjectCfg(access='all'), |
| 501 'inconsistent': project_config_pb2.ProjectCfg(access='all'), | 499 'inconsistent': project_config_pb2.ProjectCfg(access='all'), |
| 502 'secret': project_config_pb2.ProjectCfg(access='administrators'), | 500 'secret': project_config_pb2.ProjectCfg(access='administrators'), |
| 503 } | 501 }) |
| 504 projects.get_repos.return_value = { | 502 projects.get_repos_async.return_value = future({ |
| 505 'chromium': ( | 503 'chromium': ( |
| 506 projects.RepositoryType.GITILES, 'https://chromium.example.com'), | 504 projects.RepositoryType.GITILES, 'https://chromium.example.com'), |
| 507 'v8': (projects.RepositoryType.GITILES, 'https://v8.example.com'), | 505 'v8': (projects.RepositoryType.GITILES, 'https://v8.example.com'), |
| 508 'inconsistent': (None, None), | 506 'inconsistent': (None, None), |
| 509 'secret': (projects.RepositoryType.GITILES, 'https://localhost/secret'), | 507 'secret': (projects.RepositoryType.GITILES, 'https://localhost/secret'), |
| 510 } | 508 }) |
| 511 | 509 |
| 512 resp = self.call_api('get_projects', {}).json_body | 510 resp = self.call_api('get_projects', {}).json_body |
| 513 | 511 |
| 514 self.assertEqual(resp, { | 512 self.assertEqual(resp, { |
| 515 'projects': [ | 513 'projects': [ |
| 516 { | 514 { |
| 517 'id': 'chromium', | 515 'id': 'chromium', |
| 518 'name': 'Chromium, the best browser', | 516 'name': 'Chromium, the best browser', |
| 519 'repo_type': 'GITILES', | 517 'repo_type': 'GITILES', |
| 520 'repo_url': 'https://chromium.example.com', | 518 'repo_url': 'https://chromium.example.com', |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 self.call_api('get_refs', req) | 566 self.call_api('get_refs', req) |
| 569 | 567 |
| 570 ############################################################################## | 568 ############################################################################## |
| 571 # get_project_configs | 569 # get_project_configs |
| 572 | 570 |
| 573 def test_get_config_multi(self): | 571 def test_get_config_multi(self): |
| 574 projects.get_projects.return_value.extend([ | 572 projects.get_projects.return_value.extend([ |
| 575 service_config_pb2.Project(id='inconsistent'), | 573 service_config_pb2.Project(id='inconsistent'), |
| 576 service_config_pb2.Project(id='secret'), | 574 service_config_pb2.Project(id='secret'), |
| 577 ]) | 575 ]) |
| 578 projects.get_metadata.return_value.update({ | 576 projects.get_metadata_async.return_value.get_result().update({ |
| 579 'inconsistent': project_config_pb2.ProjectCfg(access='all'), | 577 'inconsistent': project_config_pb2.ProjectCfg(access='all'), |
| 580 'secret': project_config_pb2.ProjectCfg(access='administrators'), | 578 'secret': project_config_pb2.ProjectCfg(access='administrators'), |
| 581 }) | 579 }) |
| 582 projects.get_repos.return_value.update({ | 580 projects.get_repos_async.return_value.get_result().update({ |
| 583 'inconsistent': (None, None), | 581 'inconsistent': (None, None), |
| 584 'secret': (projects.RepositoryType.GITILES, 'https://localhost/secret'), | 582 'secret': (projects.RepositoryType.GITILES, 'https://localhost/secret'), |
| 585 }) | 583 }) |
| 586 | 584 |
| 587 self.mock(storage, 'get_latest_configs_async', mock.Mock()) | 585 self.mock(storage, 'get_latest_configs_async', mock.Mock()) |
| 588 storage.get_latest_configs_async.return_value = future({ | 586 storage.get_latest_configs_async.return_value = future({ |
| 589 'projects/chromium': ('deadbeef', 'abc0123', 'config text'), | 587 'projects/chromium': ('deadbeef', 'abc0123', 'config text'), |
| 590 'projects/v8': ('beefdead', 'ccc123', None), # no content | 588 'projects/v8': ('beefdead', 'ccc123', None), # no content |
| 591 'projects/secret': ('badcoffee', 'abcabc', 'abcsdjksl'), | 589 'projects/secret': ('badcoffee', 'abcabc', 'abcsdjksl'), |
| 592 }) | 590 }) |
| 593 | 591 |
| 594 req = {'path': 'cq.cfg'} | 592 req = {'path': 'cq.cfg'} |
| 595 resp = self.call_api('get_project_configs', req).json_body | 593 resp = self.call_api('get_project_configs', req).json_body |
| 596 | 594 |
| 597 self.assertEqual(resp, { | 595 self.assertEqual(resp, { |
| 598 'configs': [{ | 596 'configs': [{ |
| 599 'config_set': 'projects/chromium', | 597 'config_set': 'projects/chromium', |
| 600 'revision': 'deadbeef', | 598 'revision': 'deadbeef', |
| 601 'content_hash': 'abc0123', | 599 'content_hash': 'abc0123', |
| 602 'content': base64.b64encode('config text'), | 600 'content': base64.b64encode('config text'), |
| 603 }], | 601 }], |
| 604 }) | 602 }) |
| 605 | 603 |
| 606 def test_get_config_multi_hashes_only(self): | 604 def test_get_config_multi_hashes_only(self): |
| 607 projects.get_projects.return_value.extend([ | 605 projects.get_projects.return_value.extend([ |
| 608 service_config_pb2.Project(id='inconsistent'), | 606 service_config_pb2.Project(id='inconsistent'), |
| 609 service_config_pb2.Project(id='secret'), | 607 service_config_pb2.Project(id='secret'), |
| 610 ]) | 608 ]) |
| 611 projects.get_metadata.return_value.update({ | 609 projects.get_metadata_async.return_value.get_result().update({ |
| 612 'inconsistent': project_config_pb2.ProjectCfg(access='all'), | 610 'inconsistent': project_config_pb2.ProjectCfg(access='all'), |
| 613 'secret': project_config_pb2.ProjectCfg(access='administrators'), | 611 'secret': project_config_pb2.ProjectCfg(access='administrators'), |
| 614 }) | 612 }) |
| 615 projects.get_repos.return_value.update({ | 613 projects.get_repos_async.return_value.get_result().update({ |
| 616 'inconsistent': (None, None), | 614 'inconsistent': (None, None), |
| 617 'secret': (projects.RepositoryType.GITILES, 'https://localhost/secret'), | 615 'secret': (projects.RepositoryType.GITILES, 'https://localhost/secret'), |
| 618 }) | 616 }) |
| 619 | 617 |
| 620 self.mock(storage, 'get_latest_configs_async', mock.Mock()) | 618 self.mock(storage, 'get_latest_configs_async', mock.Mock()) |
| 621 storage.get_latest_configs_async.return_value = future({ | 619 storage.get_latest_configs_async.return_value = future({ |
| 622 'projects/chromium': ('deadbeef', 'abc0123', None), | 620 'projects/chromium': ('deadbeef', 'abc0123', None), |
| 623 'projects/v8': ('beefdead', None, None), # no content hash | 621 'projects/v8': ('beefdead', None, None), # no content hash |
| 624 'projects/secret': ('badcoffee', 'abcabc', None), | 622 'projects/secret': ('badcoffee', 'abcabc', None), |
| 625 }) | 623 }) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 self.mock(acl, 'is_admin', mock.Mock(return_value=True)) | 671 self.mock(acl, 'is_admin', mock.Mock(return_value=True)) |
| 674 self.mock(gitiles_import, 'import_config_set', mock.Mock()) | 672 self.mock(gitiles_import, 'import_config_set', mock.Mock()) |
| 675 gitiles_import.import_config_set.side_effect = gitiles_import.Error | 673 gitiles_import.import_config_set.side_effect = gitiles_import.Error |
| 676 req = {'config_set': 'services/x'} | 674 req = {'config_set': 'services/x'} |
| 677 with self.call_should_fail(500): | 675 with self.call_should_fail(500): |
| 678 self.call_api('reimport', req) | 676 self.call_api('reimport', req) |
| 679 | 677 |
| 680 | 678 |
| 681 if __name__ == '__main__': | 679 if __name__ == '__main__': |
| 682 test_env.main() | 680 test_env.main() |
| OLD | NEW |