def test_get_tenant_calls_returns_none(self):
        with patch.object(
                NativeProxy, 'cache_exists', self.cache_false):
            tenant_cache = TenantCache()
            tenant = tenant_cache.get_tenant(self.tenant_id)

        self.assertIs(tenant, None)
    def test_delete_tenant_calls_cache_del(self):
        with patch.object(NativeProxy, 'cache_exists',
                          self.cache_true), patch.object(
                              NativeProxy, 'cache_del', self.cache_del):
            tenant_cache = TenantCache()
            tenant_cache.delete_tenant(self.tenant_id)

        self.cache_del.assert_called_once_with(self.tenant_id, CACHE_TENANT)
    def test_delete_tenant_calls_cache_del(self):
        with patch.object(
                NativeProxy, 'cache_exists', self.cache_true
        ), patch.object(NativeProxy, 'cache_del', self.cache_del):
            tenant_cache = TenantCache()
            tenant_cache.delete_tenant(self.tenant_id)

        self.cache_del.assert_called_once_with(
            self.tenant_id, CACHE_TENANT)
    def test_delete_tenant_does_not_call_cache_del(self):
        with patch.object(
                NativeProxy, 'cache_exists', self.cache_false
        ), patch.object(NativeProxy, 'cache_del', self.cache_del):
            tenant_cache = TenantCache()
            tenant_cache.delete_tenant(self.tenant_id)

        with self.assertRaises(AssertionError):
            self.cache_del.assert_called_once_with(
                self.tenant_id, CACHE_TENANT)
    def test_get_tenant_calls_returns_tenant(self):
        with patch.object(
                NativeProxy, 'cache_exists', self.cache_true
        ), patch.object(NativeProxy, 'cache_get',  self.cache_get_tenant):
            tenant_cache = TenantCache()
            tenant = tenant_cache.get_tenant(self.tenant_id)

        self.cache_get_tenant.assert_called_once_with(
            self.tenant_id, CACHE_TENANT)
        self.assertIsInstance(tenant, Tenant)
    def test_set_tenant_calls_cache_set(self):
        with patch.object(
                NativeProxy, 'cache_exists', self.cache_false
        ), patch.object(NativeProxy, 'cache_set', self.cache_set):
            tenant_cache = TenantCache()
            tenant_cache.set_tenant(self.tenant)

        self.cache_set.assert_called_once_with(
            self.tenant_id, jsonutils.dumps(self.tenant.format()),
            DEFAULT_EXPIRES, CACHE_TENANT)
    def test_delete_tenant_does_not_call_cache_del(self):
        with patch.object(NativeProxy, 'cache_exists',
                          self.cache_false), patch.object(
                              NativeProxy, 'cache_del', self.cache_del):
            tenant_cache = TenantCache()
            tenant_cache.delete_tenant(self.tenant_id)

        with self.assertRaises(AssertionError):
            self.cache_del.assert_called_once_with(self.tenant_id,
                                                   CACHE_TENANT)
    def test_get_tenant_calls_returns_tenant(self):
        with patch.object(NativeProxy, 'cache_exists',
                          self.cache_true), patch.object(
                              NativeProxy, 'cache_get', self.cache_get_tenant):
            tenant_cache = TenantCache()
            tenant = tenant_cache.get_tenant(self.tenant_id)

        self.cache_get_tenant.assert_called_once_with(self.tenant_id,
                                                      CACHE_TENANT)
        self.assertIsInstance(tenant, Tenant)
    def test_set_tenant_calls_cache_set(self):
        with patch.object(NativeProxy, 'cache_exists',
                          self.cache_false), patch.object(
                              NativeProxy, 'cache_set', self.cache_set):
            tenant_cache = TenantCache()
            tenant_cache.set_tenant(self.tenant)

        self.cache_set.assert_called_once_with(
            self.tenant_id, jsonutils.dumps(self.tenant.format()),
            DEFAULT_EXPIRES, CACHE_TENANT)
示例#10
0
    def get_validated_tenant(self):
        """
        returns a validated tenant object from cache or from coordinator
        """
        token_cache = TokenCache()
        tenant_cache = TenantCache()

        #check if the token is in the cache
        token = token_cache.get_token(self.tenant_id)
        if token:
            #validate token
            if not token.validate_token(self.message_token):
                raise errors.MessageAuthenticationError(
                    'Message not authenticated, check your tenant id '
                    'and or message token for validity')

            #get the tenant object from cache
            tenant = tenant_cache.get_tenant(self.tenant_id)

            #if tenant is not in cache, ask the coordinator
            if not tenant:
                tenant = self._get_tenant_from_coordinator()
                token_cache.set_token(self.tenant_id, tenant.token)
                tenant_cache.set_tenant(tenant)
        else:
            self._validate_token_with_coordinator()

            #get tenant from coordinator
            tenant = self._get_tenant_from_coordinator()
            token_cache.set_token(self.tenant_id, tenant.token)
            tenant_cache.set_tenant(tenant)

        return tenant
示例#11
0
    def get_validated_tenant(self):
        """
        returns a validated tenant object from cache or from coordinator
        """
        token_cache = TokenCache()
        tenant_cache = TenantCache()

        #check if the token is in the cache
        token = token_cache.get_token(self.tenant_id)
        if token:
            #validate token
            if not token.validate_token(self.message_token):
                raise errors.MessageAuthenticationError(
                    'Message not authenticated, check your tenant id '
                    'and or message token for validity')

            #get the tenant object from cache
            tenant = tenant_cache.get_tenant(self.tenant_id)

            #if tenant is not in cache, ask the coordinator
            if not tenant:
                tenant = self._get_tenant_from_coordinator()
                token_cache.set_token(self.tenant_id, tenant.token)
                tenant_cache.set_tenant(tenant)
        else:
            self._validate_token_with_coordinator()

            #get tenant from coordinator
            tenant = self._get_tenant_from_coordinator()
            token_cache.set_token(self.tenant_id, tenant.token)
            tenant_cache.set_tenant(tenant)

        return tenant
 def test_clear_calls_cache_clear(self):
     with patch.object(NativeProxy, 'cache_clear', self.cache_clear):
         tenant_cache = TenantCache()
         tenant_cache.clear()
     self.cache_clear.assert_called_once_with(CACHE_TENANT)
示例#13
0
    def test_get_tenant_calls_returns_none(self):
        with patch.object(NativeProxy, 'cache_exists', self.cache_false):
            tenant_cache = TenantCache()
            tenant = tenant_cache.get_tenant(self.tenant_id)

        self.assertIs(tenant, None)
示例#14
0
 def test_clear_calls_cache_clear(self):
     with patch.object(NativeProxy, 'cache_clear', self.cache_clear):
         tenant_cache = TenantCache()
         tenant_cache.clear()
     self.cache_clear.assert_called_once_with(CACHE_TENANT)