def test_set_token(self): """ Make sure NokiaApi.set_token makes the expected changes """ timestamp = int(( datetime.datetime.utcnow() - datetime.datetime(1970, 1, 1) ).total_seconds()) creds = NokiaCredentials(token_expiry=timestamp) api = NokiaApi(creds) token = { 'access_token': 'fakeat', 'refresh_token': 'fakert', 'expires_in': 100, } api.set_token(token) self.assertEqual(api.token, token) self.assertEqual(api.get_credentials().access_token, 'fakeat') self.assertEqual(api.get_credentials().refresh_token, 'fakert') # Need to check 100 or 101 in case a second ticked over during testing self.assertTrue( int(api.credentials.token_expiry) == (timestamp + 100) or int(api.credentials.token_expiry) == (timestamp + 101) )
def test_set_token_refresh_cb(self): """ Make sure set_token calls refresh_cb when specified """ timestamp = int((datetime.datetime.utcnow() - datetime.datetime(1970, 1, 1)).total_seconds()) creds = NokiaCredentials(token_expiry=timestamp) refresh_cb = MagicMock() api = NokiaApi(creds, refresh_cb=refresh_cb) token = { 'access_token': 'fakeat', 'refresh_token': 'fakert', 'expires_in': 100, } api.set_token(token) self.assertEqual(api.token, token) refresh_cb.assert_called_once_with(token)
def test_set_token_refresh_cb(self): """ Make sure set_token calls refresh_cb when specified """ timestamp = int(( datetime.datetime.utcnow() - datetime.datetime(1970, 1, 1) ).total_seconds()) creds = NokiaCredentials(token_expiry=timestamp) refresh_cb = MagicMock() api = NokiaApi(creds, refresh_cb=refresh_cb) token = { 'access_token': 'fakeat', 'refresh_token': 'fakert', 'expires_in': 100, } api.set_token(token) self.assertEqual(api.token, token) refresh_cb.assert_called_once_with(token)
def test_set_token(self): """ Make sure NokiaApi.set_token makes the expected changes """ timestamp = int((datetime.datetime.utcnow() - datetime.datetime(1970, 1, 1)).total_seconds()) creds = NokiaCredentials(token_expiry=timestamp) api = NokiaApi(creds) token = { 'access_token': 'fakeat', 'refresh_token': 'fakert', 'expires_in': 100, } api.set_token(token) self.assertEqual(api.token, token) self.assertEqual(api.get_credentials().access_token, 'fakeat') self.assertEqual(api.get_credentials().refresh_token, 'fakert') # Need to check 100 or 101 in case a second ticked over during testing self.assertTrue( int(api.credentials.token_expiry) == (timestamp + 100) or int(api.credentials.token_expiry) == (timestamp + 101))