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)
示例#2
0
  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)
示例#3
0
    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))
示例#4
0
    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))