Exemplo n.º 1
0
    def test_expires_in_is_refreshed(self):
        time = MagicMock()
        time.time.side_effect = [0, 1]

        with patch('tekore.auth.expiring.time', time):
            token = Token(make_token_dict())
            self.assertEqual(token.expires_in, 3599)
Exemplo n.º 2
0
    def test_old_token_is_expiring(self):
        time = MagicMock()
        time.time.side_effect = [0, 3600]

        with patch('tekore.auth.expiring.time', time):
            token = Token(make_token_dict())
            self.assertEqual(token.is_expiring, True)
Exemplo n.º 3
0
    def test_expires_in_set_time(self):
        time = MagicMock()
        time.time.return_value = 0

        with patch('tekore.auth.expiring.time', time):
            token = Token(make_token_dict())
            self.assertEqual(token.expires_in, 3600)
Exemplo n.º 4
0
    def test_access_token_returned(self):
        time = MagicMock()
        time.time.return_value = 0

        with patch('tekore.auth.expiring.time', time):
            token = Token(make_token_dict())
            self.assertEqual(token.access_token, 'accesstoken')
Exemplo n.º 5
0
    def test_token_attributes(self):
        d = make_token_dict()
        t = Token(d)

        with self.subTest('token_type'):
            self.assertEqual(t.token_type, d['token_type'])
        with self.subTest('scope'):
            self.assertEqual(t.scope, d['scope'])
Exemplo n.º 6
0
    def test_refreshing_token_expiration_attributes(self):
        token_info = MagicMock()
        token = Token(token_info)
        token._expires_at = 0

        auto_token = RefreshingToken(token, MagicMock())
        with self.subTest('is_expiring is False'):
            self.assertFalse(auto_token.is_expiring)
        with self.subTest('expires_in is None'):
            self.assertIsNone(auto_token.expires_in)
        with self.subTest('expires_at is None'):
            self.assertIsNone(auto_token.expires_at)
Exemplo n.º 7
0
    def test_refreshing_token_has_same_attributes_as_regular(self):
        token_info = MagicMock()
        token = Token(token_info)
        token._expires_at = 3000
        auto_token = RefreshingToken(token, MagicMock())

        token_attributes = [a for a in dir(token) if not a.startswith('_')]
        auto_attributes = [a for a in dir(auto_token) if not a.startswith('_')]

        for attribute in token_attributes:
            with self.subTest(f'Attribute: `{attribute}`'):
                auto_token.__getattribute__(attribute)
                self.assertTrue(attribute in auto_attributes)