Beispiel #1
0
 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'),
         ]))
Beispiel #2
0
    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)