def test_spotipy_initialization(self, patched_server, patched_browser, patched_threading): sp_oauth = Mock() self.navigator.lifecycle.get_spotipy_oauth.return_value = sp_oauth sp_oauth.get_authorize_url.return_value = 'http://irdn.is/' menu = menus.LogIntoSpotipy(self.navigator) menu.initialize() sp_oauth.get_authorize_url.assert_called_once_with() patched_server().start.assert_called_once_with() patched_browser.open.assert_called_once_with( sp_oauth.get_authorize_url.return_value) self.assertIsNone(menu.message_from_spotipy) patched_server.reset_mock() patched_browser.reset_mock() sp_oauth.reset_mock() patched_server().server = None menu = menus.LogIntoSpotipy(self.navigator) menu.initialize() sp_oauth.get_authorize_url.assert_called_once_with() patched_server().start.assert_called_once_with() patched_browser.open.assert_not_called() self.assertIsNotNone(menu.message_from_spotipy)
def test_spotipy_get_response_up(self, patched_chargetter): menu = menus.LogIntoSpotipy(self.navigator) menu.oauth_server = Mock() for quitchar in b'q', b'u': patched_chargetter.return_value = quitchar self.assertEqual(menu.get_response(), responses.UP) menu.oauth_server.shutdown.assert_called_once_with() menu.oauth_server.reset_mock()
def test_spotipy_get_response_response_parts_error(self, patched_chargetter): menu = menus.LogIntoSpotipy(self.navigator) menu.oauth_server = Mock() menu.sp_oauth = Mock() patched_chargetter.return_value = None menu._spotipy_response_parts = {'error': ['foobar']} self.assertEqual(menu.get_response(), responses.NOOP) menu.oauth_server.shutdown.assert_called_once_with() self.navigator.lifecycle.set_spotipy_token.assert_not_called() self.assertIn('foobar', menu.message_from_spotipy)
def test_spotipy_get_response_response_parts_code(self, patched_chargetter): menu = menus.LogIntoSpotipy(self.navigator) menu.oauth_server = Mock() menu.sp_oauth = Mock() patched_chargetter.return_value = None menu._spotipy_response_parts = {'code': ['foobar']} self.assertEqual(menu.get_response(), responses.UP) menu.oauth_server.shutdown.assert_called_once_with() self.navigator.lifecycle.set_spotipy_token.assert_called_once_with( menu.sp_oauth.get_access_token('foobar')) self.navigator.refresh_spotipy_client.assert_called_once_with()