def test_get_auth_access_token_exists(self): """ If a token exists in the given session's AUTH_ACCESS_TOKEN, get_auth_access_token() should return that token. """ session = self.client.session spotify._set_auth_access_token(session, 'token123', 1) self.assertEqual(spotify._get_auth_access_token(session), 'token123')
def test_set_auth_access_token(self): """ set_auth_access_token() should set the variable associated with AUTH_ACCESS_TOKEN in the given session to the given token. """ session = self.client.session spotify._set_auth_access_token(session, 'token123', 1) self.assertEqual(session.get(spotify.AUTH_ACCESS_TOKEN), 'token123')
def test_clear_auth_access_token(self): """ _clear_auth_access_token() should delete any saved token in the session's AUTH_ACCESS_TOKEN. """ session = self.client.session spotify._set_auth_access_token(session, 'token123', 1) spotify._clear_auth_access_token(session) self.assertIsNone(session.get(spotify.AUTH_ACCESS_TOKEN))
def setUp(self): """ Creates a fresh session with the authorized data retrieved in setUpClass(). """ self.session = create_session_store() spotify._set_refresh_token(self.session, self.refresh_token) spotify._set_user_id(self.session, self.user_id) spotify._set_auth_access_token(self.session, self.auth_access_token, 10)
def test_set_auth_access_token_timeout(self): """ _set_auth_access_token() should save the given token in the given session under AUTH_ACCESS_TOKEN, and should delete it after the given timeout (in seconds). """ session = self.client.session spotify._set_auth_access_token(session, 'token123', 1) time.sleep(1) self.assertIsNone(session.get(spotify.AUTH_ACCESS_TOKEN))
def test_logout_logged_in(self): """ logout() should set all the user's session variables to None. """ session = self.client.session spotify._set_refresh_token(session, 'this_is_a_code') spotify._set_user_id(session, 'user_id') spotify._set_auth_access_token(session, 'token123', 3) spotify.logout(session) self.assertIsNone(session.get(spotify.REFRESH_TOKEN)) self.assertIsNone(session.get(spotify.USER_ID)) self.assertIsNone(session.get(spotify.AUTH_ACCESS_TOKEN))