def test_set_refresh_token(self): """ set_refresh_token() should set the variable associated with REFRESH_TOKEN in the given session to the given code. """ session = self.client.session spotify._set_refresh_token(session, 'this_is_a_code') self.assertIs(session.get(spotify.REFRESH_TOKEN), 'this_is_a_code')
def test_is_user_logged_in_false_uri_refresh(self): """ is_user_logged_in() should return whether or not a user is logged in to a given session. If REFRESH_TOKEN is set and USER_ID is not, it should return False. """ session = self.client.session spotify._set_refresh_token(session, 'code1') self.assertFalse(spotify.is_user_logged_in(session))
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_is_user_logged_in_false_invalid_code(self): """ is_user_logged_in() should return whether or not a user is logged in to a given session. If REFRESH_TOKEN and USER_ID are set, but the token is invalid or has expired, it should return False. """ session = self.client.session spotify._set_refresh_token(session, 'code1') spotify._set_user_id(session, 'user') self.assertFalse(spotify.is_user_logged_in(session))
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))
def test_request_authorized_token_bad_refresh_token(self): """ request_authorized_token() needs a valid refresh token from the session to get an access token. If the refresh token is invalid, the function should fail. The refresh token should be unchanged and the access token should still be None. """ session = self.client.session spotify._set_refresh_token(session, 'bad_code') spotify._set_user_id(session, 'user_id') spotify._request_authorized_token(session) self.assertIsNone(session.get(spotify.AUTH_ACCESS_TOKEN)) self.assertIs(session.get(spotify.REFRESH_TOKEN), 'bad_code')