def test_get_self_config(self): expected = service_config_pb2.AclCfg(project_access_group='group') self.mock(storage, 'get_config_hash_async', mock.Mock()) self.mock(storage, 'get_config_by_hash_async', mock.Mock()) storage.get_config_hash_async.return_value = future( ('deadbeef', 'beefdead')) storage.get_config_by_hash_async.return_value = future( 'project_access_group: "group"') actual = storage.get_self_config_async( 'acl.cfg', service_config_pb2.AclCfg).get_result() self.assertEqual(expected, actual) storage.get_config_hash_async.assert_called_once_with( 'services/sample-app', 'acl.cfg') storage.get_config_by_hash_async.assert_called_once_with('beefdead') # memcached: storage.get_config_hash_async.reset_mock() storage.get_config_by_hash_async.reset_mock() actual = storage.get_latest_as_message_async( 'services/sample-app', 'acl.cfg', service_config_pb2.AclCfg).get_result() self.assertEqual(expected, actual) self.assertFalse(storage.get_config_hash_async.called) self.assertFalse(storage.get_config_by_hash_async.called)
def test_get_self_config(self): expected = service_config_pb2.AclCfg(project_access_group='group') self.mock(storage, 'get_config_hashes_async', mock.Mock()) self.mock(storage, 'get_configs_by_hashes_async', mock.Mock()) storage.get_config_hashes_async.return_value = future({ storage.get_self_config_set(): ('deadbeef', 'file://config', 'beefdead'), }) storage.get_configs_by_hashes_async.return_value = future({ 'beefdead': 'project_access_group: "group"', }) actual = storage.get_self_config_async( 'acl.cfg', service_config_pb2.AclCfg).get_result() self.assertEqual(expected, actual) storage.get_config_hashes_async.assert_called_once_with( {storage.get_self_config_set(): None}, 'acl.cfg') storage.get_configs_by_hashes_async.assert_called_once_with( ['beefdead']) # memcached: storage.get_config_hashes_async.reset_mock() storage.get_configs_by_hashes_async.reset_mock() actual = storage.get_self_config_async( 'acl.cfg', service_config_pb2.AclCfg).get_result() self.assertEqual(expected, actual) self.assertFalse(storage.get_config_hashes_async.called) self.assertFalse(storage.get_configs_by_hashes_async.called)
def setUp(self): super(ApiTest, self).setUp() self.mock(acl, 'has_projects_access', mock.Mock()) acl.has_projects_access.side_effect = ( lambda pids: {pid: pid != 'secret' for pid in pids}) self.mock(acl, 'has_services_access', lambda sids: {sid: True for sid in sids}) self.mock(projects, 'get_projects', mock.Mock()) projects.get_projects.return_value = [ service_config_pb2.Project(id='chromium'), service_config_pb2.Project(id='v8'), ] self.mock( projects, 'get_metadata_async', mock.Mock( return_value=future({ 'chromium': project_config_pb2.ProjectCfg(), 'v8': project_config_pb2.ProjectCfg(), }))) self.mock( projects, 'get_repos_async', mock.Mock(return_value=future({ 'chromium': (projects.RepositoryType.GITILES, 'https://chromium.example.com'), 'v8': (projects.RepositoryType.GITILES, 'https://v8.example.com'), })))
def setUp(self): super(AclTestCase, self).setUp() self.mock(auth, "get_current_identity", mock.Mock()) auth.get_current_identity.return_value = auth.Anonymous self.mock(auth, "is_admin", lambda *_: False) self.mock(auth, "is_group_member", mock.Mock(return_value=False)) self.mock(services, "get_service_async", mock.Mock()) services.get_service_async.side_effect = lambda sid: future(None) acl_cfg = service_config_pb2.AclCfg(project_access_group="project-admins") self.mock(storage, "get_self_config_async", lambda *_: future(acl_cfg))
def mock_config(self, mock_content=True): self.mock(storage, 'get_config_hashes_async', mock.Mock()) storage.get_config_hashes_async.return_value = future({ 'services/luci-config': ('deadbeef', 'https://x.com/+/deadbeef', 'abc0123'), }) if mock_content: self.mock(storage, 'get_configs_by_hashes_async', mock.Mock()) storage.get_configs_by_hashes_async.return_value = future({ 'abc0123': 'config text', })
def setUp(self): super(AclTestCase, self).setUp() self.mock(auth, 'get_current_identity', mock.Mock()) auth.get_current_identity.return_value = auth.Anonymous self.mock(auth, 'is_admin', lambda *_: False) self.mock(auth, 'is_group_member', mock.Mock(return_value=False)) self.mock(services, 'get_service_async', mock.Mock()) services.get_service_async.side_effect = lambda sid: future(None) acl_cfg = service_config_pb2.AclCfg( project_access_group='project-admins', ) self.mock(storage, 'get_self_config_async', lambda *_: future(acl_cfg))
def setUp(self): super(AclTestCase, self).setUp() self.mock(auth, 'get_current_identity', mock.Mock()) auth.get_current_identity.return_value = auth.Anonymous self.mock(auth, 'is_group_member', mock.Mock(return_value=False)) self.mock(services, 'get_services_async', mock.Mock(return_value=future([]))) acl_cfg = service_config_pb2.AclCfg( project_access_group='project-admins', ) self.mock(projects, '_filter_existing', lambda pids: pids) self.mock(storage, 'get_self_config_async', lambda *_: future(acl_cfg))
def test_get_config_by_hash(self): self.mock(storage, 'get_config_by_hash_async', mock.Mock()) storage.get_config_by_hash_async.return_value = future('some content') req = {'content_hash': 'deadbeef'} resp = self.call_api('get_config_by_hash', req).json_body self.assertEqual(resp, { 'content': base64.b64encode('some content'), }) storage.get_config_by_hash_async.return_value = future(None) with self.call_should_fail(httplib.NOT_FOUND): self.call_api('get_config_by_hash', req)
def test_update_service_metadata_async_different(self): self.mock_metadata_entity() self.mock(net, 'json_request_async', mock.Mock()) dict = { 'version': '1.0', 'validation': { 'url': 'https://a.com/different_validate', 'patterns': [ { 'config_set': 'projects/bar', 'path': 'foo.cfg' }, { 'config_set': 'regex:services/.+', 'path': 'regex:.+' }, ] } } net.json_request_async.return_value = future(dict) self.mock(logging, 'info', mock.Mock()) mock_service = mock.Mock() mock_service.id = 'deadbeef' mock_service.metadata_url = 'https://a.com/validate' services._update_service_metadata_async(mock_service).get_result() self.assertTrue(logging.info.called)
def test_get_gitiles_config_corrupted(self): self.mock(storage, 'get_latest_configs_async', mock.Mock()) storage.get_latest_configs_async.return_value = future({ storage.get_self_config_set(): ('rev', 'file://config', 'content_hash', 'garbage'), }) gitiles_import.get_gitiles_config()
def test_update_service_metadata_async_jwt(self): self.mock_metadata_entity() self.mock(net, 'json_request_async', mock.Mock()) dct = { 'version': '1.0', 'validation': { 'url': 'https://a.com/validate', 'patterns': [ {'config_set': 'projects/foo', 'path': 'bar.cfg'}, {'config_set': 'regex:services/.+', 'path': 'regex:.+'}, ] } } net.json_request_async.return_value = future(dct) self.mock(logging, 'info', mock.Mock()) svc = self.service_proto( jwt_auth=service_config_pb2.Service.JWTAuth( audience='https://service.example.com')) services._update_service_metadata_async(svc).get_result() self.assertFalse(logging.info.called) net.json_request_async.assert_called_once_with( 'https://a.com/metadata', method='GET', payload=None, deadline=50, scopes=None, use_jwt_auth=True, audience='https://service.example.com')
def test_get_config_one(self): self.mock(storage, 'get_config_sets_async', mock.Mock()) storage.get_config_sets_async.return_value = future([ storage.ConfigSet( id='services/x', location='https://x.googlesource.com/x', latest_revision='deadbeef', latest_revision_url='https://x.googlesource.com/x/+/deadbeef', latest_revision_time=datetime.datetime(2016, 1, 1), latest_revision_committer_email='*****@*****.**', ), ]) req = { 'config_set': 'services/x', } resp = self.call_api('get_config_sets', req).json_body storage.get_config_sets_async.assert_called_once_with( config_set='services/x') self.assertEqual(resp, { 'config_sets': [ { 'config_set': 'services/x', 'location': 'https://x.googlesource.com/x', 'revision': { 'id': 'deadbeef', 'url': 'https://x.googlesource.com/x/+/deadbeef', 'timestamp': '1451606400000000', 'committer_email': '*****@*****.**', }, }, ], })
def test_get_config_all_partially_forbidden(self): self.mock(storage, 'get_config_sets_async', mock.Mock()) storage.get_config_sets_async.return_value = future([ storage.ConfigSet( id='services/x', location='https://x.googlesource.com/x', latest_revision='deadbeef', ), storage.ConfigSet( id='projects/y', location='https://y.googlesource.com/y', latest_revision='badcoffee', ), ]) self.mock(acl, 'can_read_config_sets', mock.Mock(return_value={ 'services/x': True, 'projects/y': False, })) resp = self.call_api('get_config_sets', {}).json_body self.assertEqual(resp, { 'config_sets': [ { 'config_set': 'services/x', 'location': 'https://x.googlesource.com/x', 'revision': { 'id': 'deadbeef', } }, ], })
def test_update_service_metadata_async_same(self): self.mock_metadata_entity() self.mock(net, 'json_request_async', mock.Mock()) dct = { 'version': '1.0', 'validation': { 'url': 'https://a.com/validate', 'patterns': [ {'config_set': 'projects/foo', 'path': 'bar.cfg'}, {'config_set': 'regex:services/.+', 'path': 'regex:.+'}, ] } } net.json_request_async.return_value = future(dct) self.mock(logging, 'info', mock.Mock()) services._update_service_metadata_async(self.service_proto()).get_result() self.assertFalse(logging.info.called) net.json_request_async.assert_called_once_with( 'https://a.com/metadata', method='GET', payload=None, scopes=net.EMAIL_SCOPE, use_jwt_auth=False, audience=None)
def test_has_service_access(self): self.assertFalse(acl.can_read_config_set("services/swarming")) service_cfg = service_config_pb2.Service(id="swarming", access=["group:swarming-app"]) services.get_service_async.side_effect = lambda sid: future(service_cfg) auth.is_group_member.side_effect = lambda g: g == "swarming-app" self.assertTrue(acl.can_read_config_set("services/swarming"))
def test_get_projects(self): projects.get_projects.return_value = [ service_config_pb2.Project(id='chromium'), service_config_pb2.Project(id='v8'), service_config_pb2.Project(id='inconsistent'), service_config_pb2.Project(id='secret'), ] projects.get_metadata_async.return_value = future({ 'chromium': project_config_pb2.ProjectCfg(name='Chromium, the best browser', access='all'), 'v8': project_config_pb2.ProjectCfg(access='all'), 'inconsistent': project_config_pb2.ProjectCfg(access='all'), 'secret': project_config_pb2.ProjectCfg(access='administrators'), }) projects.get_repos_async.return_value = future({ 'chromium': (projects.RepositoryType.GITILES, 'https://chromium.example.com'), 'v8': (projects.RepositoryType.GITILES, 'https://v8.example.com'), 'inconsistent': (None, None), 'secret': (projects.RepositoryType.GITILES, 'https://localhost/secret'), }) resp = self.call_api('get_projects', {}).json_body self.assertEqual( resp, { 'projects': [ { 'id': 'chromium', 'name': 'Chromium, the best browser', 'repo_type': 'GITILES', 'repo_url': 'https://chromium.example.com', }, { 'id': 'v8', 'repo_type': 'GITILES', 'repo_url': 'https://v8.example.com', }, ], })
def test_get_metadata_async(self): self.mock(storage, 'get_self_config_async', mock.Mock()) storage.get_self_config_async.return_value = future( service_config_pb2.ServicesCfg(services=[ service_config_pb2.Service( id='foo', metadata_url='https://foo.com/metadata') ])) self.mock(net, 'json_request_async', mock.Mock()) net.json_request_async.return_value = future({ 'version': '1.0', 'validation': { 'url': 'https://a.com/validate', 'patterns': [ { 'config_set': 'projects/foo', 'path': 'bar.cfg' }, { 'config_set': 'regex:services/.+', 'path': 'regex:.+' }, ] } }) metadata = services.get_metadata_async('foo').get_result() self.assertEqual( metadata, service_config_pb2.ServiceDynamicMetadata( validation=service_config_pb2.Validator( url='https://a.com/validate', patterns=[ service_config_pb2.ConfigPattern( config_set='projects/foo', path='bar.cfg'), service_config_pb2.ConfigPattern( config_set='regex:services/.+', path='regex:.+'), ]))) net.json_request_async.assert_called_once_with( 'https://foo.com/metadata', scopes=net.EMAIL_SCOPE) storage.get_self_config_async.assert_called_once_with( common.SERVICES_REGISTRY_FILENAME, service_config_pb2.ServicesCfg)
def test_has_service_access(self): self.assertFalse(acl.can_read_config_set('services/swarming')) service_cfg = service_config_pb2.Service( id='swarming', access=['group:swarming-app']) services.get_service_async.side_effect = lambda sid: future(service_cfg) auth.is_group_member.side_effect = lambda g, *_: g == 'swarming-app' self.assertTrue(acl.can_read_config_set('services/swarming'))
def setUp(self): super(ProjectsTestCase, self).setUp() self.mock(storage, 'get_self_config_async', mock.Mock()) storage.get_self_config_async.return_value = future( service_config_pb2.ServicesCfg(services=[ service_config_pb2.Service( id='foo', metadata_url='https://foo.com/metadata'), service_config_pb2.Service(id='metadataless'), ]))
def test_message_field_merge(self): default_msg = service_config_pb2.ImportCfg( gitiles=service_config_pb2.ImportCfg.Gitiles(fetch_log_deadline=42)) self.mock(storage, 'get_latest_async', mock.Mock()) storage.get_latest_async.return_value = future( 'gitiles { fetch_archive_deadline: 10 }') msg = storage.get_self_config_async( 'import.cfg', lambda: default_msg).get_result() self.assertEqual(msg.gitiles.fetch_log_deadline, 42)
def test_get_config_with_include_files( self, mock_get_config_sets_async, mock_get_file_keys): mock_get_config_sets_async.return_value = future([ storage.ConfigSet( id='services/x', location='https://x.googlesource.com/x', latest_revision='deadbeef', latest_revision_url='https://x.googlesource.com/x/+/deadbeef', latest_revision_time=datetime.datetime(2016, 1, 1), latest_revision_committer_email='*****@*****.**', ), ]) class Key: def __init__(self, name): self.name = name def id(self): return self.name mock_get_file_keys.return_value = [ Key('README.md'), Key('rick.morty'), Key('pied.piper') ] req = { 'config_set': 'services/x', 'include_files': True, } resp = self.call_api('get_config_sets', req).json_body self.assertEqual(resp, { 'config_sets': [ { 'config_set': 'services/x', 'files': [ { 'path': 'README.md' }, { 'path': 'rick.morty' }, { 'path': 'pied.piper' } ], 'location': 'https://x.googlesource.com/x', 'revision': { 'committer_email': '*****@*****.**', 'id': 'deadbeef', 'timestamp': '1451606400000000', 'url': 'https://x.googlesource.com/x/+/deadbeef' } } ] })
def test_get_config_not_found(self): self.mock( storage, 'get_config_hash_async', lambda *_, **__: future((None, None))) req = { 'config_set': 'services/x', 'path': 'a.cfg', } with self.call_should_fail(httplib.NOT_FOUND): self.call_api('get_config', req)
def test_get_config_blob_not_found(self): self.mock_config() storage.get_config_by_hash_async.return_value = future(None) req = { 'config_set': 'services/luci-config', 'path': 'my.cfg', } with self.call_should_fail(httplib.NOT_FOUND): self.call_api('get_config', req)
def test_has_project_access_identity(self): self.mock(projects, 'get_metadata_async', mock.Mock(return_value=future({ 'secret': project_config_pb2.ProjectCfg( access=['group:googlers', '*****@*****.**']), }))) self.assertFalse(can_read_config_set('projects/secret')) auth.get_current_identity.return_value = auth.Identity('user', '*****@*****.**') self.assertTrue(can_read_config_set('projects/secret'))
def test_get_metadata_async(self): self.mock(storage, 'get_self_config_async', mock.Mock()) storage.get_self_config_async.return_value = future( service_config_pb2.ServicesCfg( services=[ service_config_pb2.Service( id='foo', metadata_url='https://foo.com/metadata') ] )) self.mock(net, 'json_request_async', mock.Mock()) net.json_request_async.return_value = future({ 'version': '1.0', 'validation': { 'url': 'https://a.com/validate', 'patterns': [ {'config_set': 'projects/foo', 'path': 'bar.cfg'}, {'config_set': 'regex:services/.+', 'path': 'regex:.+'}, ] } }) metadata = services.get_metadata_async('foo').get_result() self.assertEqual( metadata, service_config_pb2.ServiceDynamicMetadata( validation=service_config_pb2.Validator( url='https://a.com/validate', patterns=[ service_config_pb2.ConfigPattern( config_set='projects/foo', path='bar.cfg'), service_config_pb2.ConfigPattern( config_set='regex:services/.+', path='regex:.+'), ] ) ) ) net.json_request_async.assert_called_once_with( 'https://foo.com/metadata', scopes=net.EMAIL_SCOPE) storage.get_self_config_async.assert_called_once_with( common.SERVICES_REGISTRY_FILENAME, service_config_pb2.ServicesCfg)
def test_get_config_not_found(self): self.mock(storage, 'get_config_hash_async', lambda *_, **__: future( (None, None))) req = { 'config_set': 'services/x', 'path': 'a.cfg', } with self.call_should_fail(httplib.NOT_FOUND): self.call_api('get_config', req)
def test_has_service_access(self): self.assertFalse(can_read_config_set('services/swarming')) services.get_services_async.return_value = future([ service_config_pb2.Service( id='swarming', access=['group:swarming-app']), ]) auth.is_group_member.side_effect = lambda g, *_: g == 'swarming-app' self.assertTrue(can_read_config_set('services/swarming'))
def setUp(self): super(ProjectsTestCase, self).setUp() self.mock(storage, 'get_self_config_async', mock.Mock()) storage.get_self_config_async.return_value = future( service_config_pb2.ServicesCfg( services=[ service_config_pb2.Service( id='foo', metadata_url='https://foo.com/metadata'), service_config_pb2.Service(id='metadataless'), ] ))
def test_has_project_access_group(self): self.mock(projects, 'get_metadata_async', mock.Mock(return_value=future({ 'secret': project_config_pb2.ProjectCfg( access=['group:googlers', '*****@*****.**']), }))) self.assertFalse(can_read_config_set('projects/secret')) auth.is_group_member.side_effect = lambda name, *_: name == 'googlers' self.assertTrue(can_read_config_set('projects/secret')) auth.is_group_member.side_effect = lambda name, *_: name == 'project-admins' self.assertTrue(can_read_config_set('projects/secret'))
def test_get_self_config(self): expected = service_config_pb2.AclCfg(project_access_group="group") self.mock(storage, "get_config_hash_async", mock.Mock()) self.mock(storage, "get_config_by_hash_async", mock.Mock()) storage.get_config_hash_async.return_value = future(("deadbeef", "beefdead")) storage.get_config_by_hash_async.return_value = future('project_access_group: "group"') actual = storage.get_self_config_async("acl.cfg", service_config_pb2.AclCfg).get_result() self.assertEqual(expected, actual) storage.get_config_hash_async.assert_called_once_with("services/sample-app", "acl.cfg") storage.get_config_by_hash_async.assert_called_once_with("beefdead") # memcached: storage.get_config_hash_async.reset_mock() storage.get_config_by_hash_async.reset_mock() actual = storage.get_latest_as_message_async( "services/sample-app", "acl.cfg", service_config_pb2.AclCfg ).get_result() self.assertEqual(expected, actual) self.assertFalse(storage.get_config_hash_async.called) self.assertFalse(storage.get_config_by_hash_async.called)
def test_schemas(self): self.mock(storage, "get_self_config_async", mock.Mock()) storage.get_self_config_async.return_value = future( service_config_pb2.SchemasCfg( schemas=[ service_config_pb2.SchemasCfg.Schema(name="projects/refs.cfg", url="http://somehost/refs.proto") ] ) ) response = self.app.get("/schemas/projects/refs.cfg", status=302) self.assertEqual("http://somehost/refs.proto", response.headers.get("Location")) self.app.get("/schemas/non-existent", status=404)
def test_schemas(self): self.mock(storage, 'get_self_config_async', mock.Mock()) storage.get_self_config_async.return_value = future( service_config_pb2.SchemasCfg(schemas=[ service_config_pb2.SchemasCfg.Schema( name='projects/refs.cfg', url='http://somehost/refs.proto', ) ], )) response = self.app.get('/schemas/projects/refs.cfg', status=302) self.assertEqual('http://somehost/refs.proto', response.headers.get('Location')) self.app.get('/schemas/non-existent', status=404)
def test_get_config_multi(self): projects.get_projects.return_value.extend([ service_config_pb2.Project(id='inconsistent'), service_config_pb2.Project(id='secret'), ]) projects.get_metadata_async.return_value.get_result().update({ 'inconsistent': project_config_pb2.ProjectCfg(access='all'), 'secret': project_config_pb2.ProjectCfg(access='administrators'), }) projects.get_repos_async.return_value.get_result().update({ 'inconsistent': (None, None), 'secret': (projects.RepositoryType.GITILES, 'https://localhost/secret'), }) self.mock(storage, 'get_latest_configs_async', mock.Mock()) storage.get_latest_configs_async.return_value = future({ 'projects/chromium': ( 'deadbeef', 'https://x.com/+/deadbeef', 'abc0123', 'config text' ), 'projects/v8': ( 'beefdead', 'https://x.com/+/beefdead', 'ccc123', None # no content ), 'projects/secret': ( 'badcoffee', 'https://x.com/+/badcoffee', 'abcabc', 'abcsdjksl' ), }) req = {'path': 'cq.cfg'} resp = self.call_api('get_project_configs', req).json_body self.assertEqual(resp, { 'configs': [{ 'config_set': 'projects/chromium', 'revision': 'deadbeef', 'content_hash': 'abc0123', 'content': base64.b64encode('config text'), 'url': 'https://x.com/+/deadbeef', }], })
def test_schemas(self): self.mock(storage, 'get_self_config_async', mock.Mock()) storage.get_self_config_async.return_value = future( service_config_pb2.SchemasCfg( schemas=[ service_config_pb2.SchemasCfg.Schema( name='projects/refs.cfg', url='http://somehost/refs.proto', )], )) response = self.app.get('/schemas/projects/refs.cfg', status=302) self.assertEqual( 'http://somehost/refs.proto', response.headers.get('Location')) self.app.get('/schemas/non-existent', status=404)
def test_get_config_all_partially_forbidden(self): self.mock(storage, 'get_mapping_async', mock.Mock()) storage.get_mapping_async.return_value = future({ 'services/x': 'http://x', 'services/y': 'http://y', }) self.mock(acl, 'can_read_config_set', mock.Mock(side_effect=[True, False])) resp = self.call_api('get_mapping', {}).json_body self.assertEqual(resp, { 'mappings': [ { 'config_set': 'services/x', 'location': 'http://x', }, ], })
def test_get_mapping_all_partially_forbidden(self): self.mock(storage, 'get_config_sets_async', mock.Mock()) storage.get_config_sets_async.return_value = future([ storage.ConfigSet(id='services/x', location='http://x'), storage.ConfigSet(id='services/y', location='http://y'), ]) self.mock(acl, 'can_read_config_set', mock.Mock(side_effect=[True, False])) resp = self.call_api('get_mapping', {}).json_body self.assertEqual(resp, { 'mappings': [ { 'config_set': 'services/x', 'location': 'http://x', }, ], })
def test_get_mapping_all(self): self.mock(storage, 'get_config_sets_async', mock.Mock()) storage.get_config_sets_async.return_value = future([ storage.ConfigSet(id='services/x', location='https://x'), storage.ConfigSet(id='services/y', location='https://y'), ]) resp = self.call_api('get_mapping', {}).json_body self.assertEqual(resp, { 'mappings': [ { 'config_set': 'services/x', 'location': 'https://x', }, { 'config_set': 'services/y', 'location': 'https://y', }, ], })
def test_get_config_multi(self): self.mock_refs() projects.get_projects.return_value.extend([ service_config_pb2.Project(id='inconsistent'), service_config_pb2.Project(id='secret'), ]) self.mock(storage, 'get_latest_multi_async', mock.Mock()) storage.get_latest_multi_async.return_value = future([ { 'config_set': 'projects/chromium', 'revision': 'deadbeef', 'content_hash': 'abc0123', 'content': 'config text', }, { 'config_set': 'projects/v8', 'revision': 'beefdead', 'content_hash': 'ccc123', # No content }, { 'config_set': 'projects/secret', 'revision': 'badcoffee', 'content_hash': 'abcabc', 'content': 'abcsdjksl', }, ]) req = {'path': 'cq.cfg'} resp = self.call_api('get_project_configs', req).json_body self.assertEqual( resp, { 'configs': [{ 'config_set': 'projects/chromium', 'revision': 'deadbeef', 'content_hash': 'abc0123', 'content': base64.b64encode('config text'), }], })
def test_get_config_one(self): self.mock(storage, 'get_mapping_async', mock.Mock()) storage.get_mapping_async.return_value = future({ 'services/x': 'http://x', }) req = { 'config_set': 'services/x', } resp = self.call_api('get_mapping', req).json_body storage.get_mapping_async.assert_called_once_with(config_set='services/x') self.assertEqual(resp, { 'mappings': [ { 'config_set': 'services/x', 'location': 'http://x', }, ], })
def test_get_config_all(self): self.mock(storage, 'get_mapping_async', mock.Mock()) storage.get_mapping_async.return_value = future({ 'services/x': 'http://x', 'services/y': 'http://y', }) resp = self.call_api('get_mapping', {}).json_body self.assertEqual(resp, { 'mappings': [ { 'config_set': 'services/x', 'location': 'http://x', }, { 'config_set': 'services/y', 'location': 'http://y', }, ], })
def test_get_config_multi(self): self.mock_refs() projects.get_projects.return_value.extend([ service_config_pb2.Project(id='inconsistent'), service_config_pb2.Project(id='secret'), ]) self.mock(storage, 'get_latest_multi_async', mock.Mock()) storage.get_latest_multi_async.return_value = future([ { 'config_set': 'projects/chromium', 'revision': 'deadbeef', 'content_hash': 'abc0123', 'content': 'config text', }, { 'config_set': 'projects/v8', 'revision': 'beefdead', 'content_hash': 'ccc123', # No content }, { 'config_set': 'projects/secret', 'revision': 'badcoffee', 'content_hash': 'abcabc', 'content': 'abcsdjksl', }, ]) req = {'path': 'cq.cfg'} resp = self.call_api('get_project_configs', req).json_body self.assertEqual(resp, { 'configs': [{ 'config_set': 'projects/chromium', 'revision': 'deadbeef', 'content_hash': 'abc0123', 'content': base64.b64encode('config text'), }], })
def test_schemas_no_schemas_cfg(self): self.mock(storage, "get_latest_as_message_async", mock.Mock()) storage.get_latest_as_message_async.return_value = future(None) self.app.get("/schemas/non-existent", status=404)
def mock_config(self): self.mock(storage, 'get_config_hash_async', mock.Mock()) self.mock(storage, 'get_config_by_hash_async', mock.Mock()) storage.get_config_hash_async.return_value = future(('deadbeef', 'abc0123')) storage.get_config_by_hash_async.return_value = future('config text')
def test_get_gitiles_config_corrupted(self): self.mock(storage, 'get_latest_async', mock.Mock()) storage.get_latest_async.return_value = future('garbage') gitiles_import.get_gitiles_config()
def setUp(self): super(ValidationTestCase, self).setUp() self.services = [] self.mock(services, 'get_services_async', lambda: future(self.services))