Ejemplo n.º 1
0
    def test_save_bearer_tokens(self):
        expiry_in_1_hour = datetime.datetime.utcnow() + datetime.timedelta(hours=1)
        token1 = authenticated_test_service.create_token(expiry_in_1_hour)
        cache.add_bearer_token('key1', token1)

        expiry_in_2_hour = datetime.datetime.utcnow() + datetime.timedelta(hours=2)
        token2 = authenticated_test_service.create_token(expiry_in_2_hour)
        cache.add_bearer_token('key2', token2)

        same_cache = requests_auth.JsonTokenFileCache('test_tokens.cache')
        self.assertEqual(same_cache.get_token('key1'), token1)
        self.assertEqual(same_cache.get_token('key2'), token2)
Ejemplo n.º 2
0
    def test_add_bearer_tokens(self):
        expiry_in_1_hour = datetime.datetime.utcnow() + datetime.timedelta(hours=1)
        token1 = authenticated_test_service.create_token(expiry_in_1_hour)
        cache.add_bearer_token('key1', token1)

        expiry_in_2_hour = datetime.datetime.utcnow() + datetime.timedelta(hours=2)
        token2 = authenticated_test_service.create_token(expiry_in_2_hour)
        cache.add_bearer_token('key2', token2)

        # Assert that tokens can be retrieved properly even after other token were inserted
        self.assertEqual(cache.get_token('key1'), token1)
        self.assertEqual(cache.get_token('key2'), token2)

        # Assert that tokens are not removed from the cache on retrieval
        self.assertEqual(cache.get_token('key1'), token1)
        self.assertEqual(cache.get_token('key2'), token2)
Ejemplo n.º 3
0
 def test_missing_token_function(self):
     expiry_in_1_hour = datetime.datetime.utcnow() + datetime.timedelta(
         hours=1)
     token = authenticated_test_service.create_token(expiry_in_1_hour)
     retrieved_token = cache.get_token('key1', lambda: ('key1', token))
     self.assertEqual(retrieved_token, token)