예제 #1
0
    def test_storage_should_respect_datetime_format(self):
        token = Token(access_token='access_token',
                      expires_on=Token.calc_expires_on(10))
        token_storage = TokenStorage(self.storage_obj)
        token_storage(token)

        expires = token_storage.request_token()[TOKEN_EXPIRES]
        expected = datetime(2015, 1, 1, 10, 12, 20, microsecond=0)
        self.assertEqual(expires, expected)
예제 #2
0
    def test_storage_should_add_token(self):
        token = Token(access_token='access_token',
                      expires_on=Token.calc_expires_on(10))
        token_storage = TokenStorage(self.storage_obj)
        token_storage(token)
        self.assertEqual(self.storage_obj.get(TOKEN_KEY), 'access_token')

        expires = str(token.expires_on)
        self.assertEqual(self.storage_obj.get(TOKEN_EXPIRES), expires,
                         self.storage_obj)
예제 #3
0
 def test_storage_should_add_retrieve_token(self):
     token = Token(access_token='access_token',
                   expires_on=Token.calc_expires_on(10))
     expires = str(token.expires_on)
     token_storage = TokenStorage(self.storage_obj)
     token_storage(token)
     token_requested = token_storage.request_token()
     self.assertEqual(len(token_requested), 2)
     self.assertEqual(self.storage_obj.get(token_storage.token_key), 'access_token')
     self.assertEqual(self.storage_obj.get(token_storage.expires_key), expires, self.storage_obj)
예제 #4
0
    def test_storage_should_add_token(self):
        token = Token(access_token='access_token',
                      expires_on=Token.calc_expires_on(10))
        token_storage = TokenStorage(self.storage_obj, 'test')
        token_storage(token)
        self.assertEqual(self.storage_obj.get(token_storage.token_key), 'access_token')

        expires = str(token.expires_on)
        self.assertEqual(self.storage_obj.get(token_storage.expires_key), expires, self.storage_obj)

        self.assertEqual('test_access_token', token_storage.token_key)
        self.assertEqual('test_expires_on', token_storage.expires_key)
예제 #5
0
    def test_update_token_should_set_a_token_with_data_retrieved_from_storage(
            self, _request_token):
        expires = Token.calc_expires_on(100)
        _request_token.return_value = dict()

        self.manager._token = Token('new_access_token', expires_on=expires)

        self.manager._token_storage(self.manager._token)

        self.manager._update_token()

        self.assertFalse(_request_token.called)

        self.assertEqual(self.manager._token.access_token, 'new_access_token')
        self.assertEqual(self.manager._token.expires_on, expires)
예제 #6
0
 def test_storage_should_add_just_once_same_value(self):
     expires_datetime = Token.calc_expires_on(10)
     token = Token(access_token='access_token', expires_on=expires_datetime)
     token2 = Token(access_token='new_access_token',
                    expires_on=expires_datetime)
     expires = str(token.expires_on)
     token_storage = TokenStorage(self.storage_obj)
     token_storage(token)
     token_storage._access_token = 'new_access_token'
     token_storage(token2)
     token_requested = token_storage.request_token()
     self.assertEqual(len(token_requested), 2)
     self.assertEqual(token_requested.get('access_token'), 'access_token')
     self.assertEqual(self.storage_obj.get('expires_on'), expires,
                      self.storage_obj)
예제 #7
0
    def test_storage_should_respect_datetime_format(self):
        token = Token(access_token='access_token',
                      expires_on=Token.calc_expires_on(10))
        token_storage = TokenStorage(self.storage_obj)
        token_storage(token)

        expires = token_storage.request_token()['expires_on']
        expected = datetime(2015, 1, 1, 10, 12, 20, microsecond=0)
        self.assertEqual(expires, expected)
예제 #8
0
    def test_storage_should_add_token(self):
        token = Token(access_token='access_token',
                      expires_on=Token.calc_expires_on(10))
        token_storage = TokenStorage(self.storage_obj)
        token_storage(token)
        self.assertEqual(self.storage_obj.get(TOKEN_KEY), 'access_token')

        expires = str(token.expires_on)
        self.assertEqual(self.storage_obj.get(TOKEN_EXPIRES), expires, self.storage_obj)
예제 #9
0
    def test_update_token_should_set_a_token_with_data_retrieved(
            self, _request_token):
        self.manager.reset_token()
        expires = 100
        _request_token.return_value = {
            'access_token': 'new_access_token',
            'expires_in': expires
        }

        self.manager._token = Token('access_token', expires_on=0)

        self.manager._update_token()

        self.assertTrue(_request_token.called)

        self.assertEqual(self.manager._token.access_token, 'new_access_token')
        self.assertEqual(self.manager._token.expires_on,
                         Token.calc_expires_on(expires))
예제 #10
0
    def test_update_token_should_set_a_token_with_data_retrieved(self, _request_token):
        _request_token.return_value = {'access_token': 'new_access_token', 'expires_in': 10}
        self.manager._token = Token('access_token', expires_in=100)

        self.manager._update_token()

        self.assertTrue(_request_token.called)

        self.assertEqual(self.manager._token.access_token, 'new_access_token')
        self.assertEqual(self.manager._token._expires_in, 10)
예제 #11
0
    def test_should_be_able_to_request_a_new_token(self, post):
        post.return_value.json.return_value = {
            'access_token': 'accesstoken',
            'expires_on': Token.calc_expires_on(10),
        }

        self.manager._request_token()

        post.assert_called_with(self.END_POINT,
                                data={'grant_type': 'client_credentials'},
                                auth=(self.CLIENT_ID, self.CLIENT_SECRET))
예제 #12
0
    def test_should_be_able_to_request_a_new_token(self, post):
        post.return_value.json.return_value = {
            'access_token': 'accesstoken',
            'expires_on': Token.calc_expires_on(10),
        }

        self.manager._request_token()

        post.assert_called_with(self.end_point,
                                data={'grant_type': 'client_credentials'},
                                auth=(self.client_id, self.client_secret))
예제 #13
0
    def test_should_be_able_to_request_a_new_token(self, post):
        post.return_value.json.return_value = {
            'access_token': 'accesstoken',
            'expires_on': Token.calc_expires_on(10),
        }

        self.manager._request_token()

        post.assert_called_with(self.END_POINT,
                                timeout=None,
                                data={'grant_type': 'client_credentials'},
                                auth=(self.CLIENT_ID, self.CLIENT_SECRET))
예제 #14
0
    def test_update_token_should_set_a_token_with_data_retrieved_from_storage(self, _request_token):
        expires = Token.calc_expires_on(100)
        _request_token.return_value = dict()

        self.manager._token = Token('new_access_token',
                                    expires_on=expires)

        self.manager._token_storage(self.manager._token)

        self.manager._update_token()

        self.assertFalse(_request_token.called)

        self.assertEqual(self.manager._token.access_token, 'new_access_token')
        self.assertEqual(self.manager._token.expires_on, expires)
예제 #15
0
 def test_storage_should_add_just_once_same_value(self):
     expires_datetime = Token.calc_expires_on(10)
     token = Token(access_token='access_token',
                   expires_on=expires_datetime)
     token2 = Token(access_token='new_access_token',
                    expires_on=expires_datetime)
     expires = token.expires_on
     token_storage = TokenStorage(self.storage_obj)
     token_storage(token)
     token_storage._access_token = 'new_access_token'
     token_storage(token2)
     token_requested = token_storage.request_token()
     self.assertEqual(len(token_requested), 2)
     self.assertEqual(token_requested.get('access_token'), 'access_token')
     self.assertEqual(token_requested.get('expires_on'), expires, self.storage_obj)
예제 #16
0
    def test_update_token_should_set_a_token_with_data_retrieved(self, _request_token):
        self.manager.reset_token()
        expires = 100
        _request_token.return_value = {'access_token': 'new_access_token',
                                       'expires_in': expires}

        self.manager._token = Token('access_token',
                                    expires_on=0)

        self.manager._update_token()

        self.assertTrue(_request_token.called)

        self.assertEqual(self.manager._token.access_token, 'new_access_token')
        self.assertEqual(self.manager._token.expires_on, Token.calc_expires_on(expires))
예제 #17
0
 def test_should_know_when_it_has_expired(self):
     token = Token(access_token='access_token', expires_on=0)
     self.assertFalse(token.is_valid(), self.storage_obj)
예제 #18
0
 def test_should_have_an_access_token(self):
     token = Token(access_token='access_token')
     self.assertEqual(token.access_token, 'access_token')
예제 #19
0
 def test_expires_on_works(self):
     expires = Token.calc_expires_on(10)
     self.assertEqual(datetime.now() + timedelta(seconds=10), expires)
예제 #20
0
    def test_should_reset_token(self):
        self.manager.reset_token()

        self.assertEqual(self.manager._token.access_token, '')
        self.assertEqual(self.manager._token.expires_on,
                         Token.calc_expires_on(0))
예제 #21
0
 def test_should_return_token_value(self):
     self.manager._token = Token('access_token',
                                 expires_on=Token.calc_expires_on(10))
     self.assertEqual(self.manager.get_token(), 'access_token')
예제 #22
0
 def test_should_know_when_it_is_valid(self):
     token = Token(access_token='access_token',
                   expires_on=Token.calc_expires_on(10))
     self.assertTrue(token.is_valid(), self.storage_obj)
예제 #23
0
 def test_should_return_token_value(self):
     self.manager._token = Token('access_token', expires_on=Token.calc_expires_on(10))
     self.assertEqual(self.manager.get_token(), 'access_token')
예제 #24
0
 def test_should_respect_valid_token(self):
     self.manager._token = Token('', expires_in=10)
     self.assertTrue(self.manager._has_token())
예제 #25
0
파일: test_token.py 프로젝트: aflag/alf
 def test_should_know_when_it_has_expired(self):
     token = Token(access_token='access_token', expires_in=0)
     self.assertFalse(token.is_valid())
예제 #26
0
파일: test_token.py 프로젝트: aflag/alf
 def test_should_know_when_it_is_valid(self):
     token = Token(access_token='access_token', expires_in=10)
     self.assertTrue(token.is_valid())
예제 #27
0
    def test_should_reset_token(self):
        self.manager.reset_token()

        self.assertEqual(self.manager._token.access_token, '')
        self.assertEqual(self.manager._token.expires_on,
                         Token.calc_expires_on(0))
예제 #28
0
 def test_expires_on_works(self):
     expires = Token.calc_expires_on(10)
     self.assertEqual(datetime.now() + timedelta(seconds=10), expires)
예제 #29
0
 def test_should_detect_expired_token(self):
     self.manager._token = Token('', expires_on=Token.calc_expires_on(0))
     self.assertFalse(self.manager._has_token())
예제 #30
0
 def test_should_know_when_it_is_valid(self):
     token = Token(access_token='access_token',
                   expires_on=Token.calc_expires_on(10))
     self.assertTrue(token.is_valid(), self.storage_obj)
예제 #31
0
 def test_should_detect_expired_token(self):
     self.manager._token = Token('', expires_on=Token.calc_expires_on(0))
     self.assertFalse(self.manager._has_token())
예제 #32
0
 def test_should_respect_valid_token(self):
     self.manager._token = Token('', expires_on=Token.calc_expires_on(10))
     self.assertTrue(self.manager._has_token())
예제 #33
0
 def test_should_respect_valid_token(self):
     self.manager._token = Token('', expires_on=Token.calc_expires_on(10))
     self.assertTrue(self.manager._has_token())
예제 #34
0
 def test_should_know_when_it_is_valid(self):
     token = Token(access_token='access_token', expires_in=10)
     self.assertTrue(token.is_valid())