def test_update_latest_listened_at(self): old_spotify_user = db_spotify.get_user(self.user['id']) self.assertIsNone(old_spotify_user['latest_listened_at']) t = int(time.time()) db_spotify.update_latest_listened_at(self.user['id'], t) spotify_user = db_spotify.get_user(self.user['id']) self.assertEqual(t, int(spotify_user['latest_listened_at'].strftime('%s')))
def test_update_latest_listened_at(self): old_spotify_user = db_spotify.get_user(self.user['id']) self.assertIsNone(old_spotify_user['latest_listened_at']) t = int(time.time()) db_spotify.update_latest_listened_at(self.user['id'], t) spotify_user = db_spotify.get_user(self.user['id']) self.assertEqual( t, int(spotify_user['latest_listened_at'].strftime('%s')))
def test_add_update_error(self): old_spotify_user = db_spotify.get_user(self.user['id']) self.assertTrue(old_spotify_user['active']) db_spotify.add_update_error(self.user['id'], 'test error message') spotify_user = db_spotify.get_user(self.user['id']) self.assertFalse(spotify_user['active']) self.assertEqual(spotify_user['error_message'], 'test error message') self.assertIsNotNone(spotify_user['last_updated'])
def test_add_update_error(self): old_spotify_user = db_spotify.get_user(self.user['id']) self.assertTrue(old_spotify_user['active']) db_spotify.add_update_error(self.user['id'], 'test error message') spotify_user = db_spotify.get_user(self.user['id']) self.assertFalse(spotify_user['active']) self.assertEqual(spotify_user['error_message'], 'test error message') self.assertIsNotNone(spotify_user['last_updated'])
def test_update_token(self): old_spotify_user = db_spotify.get_user(self.user['id']) db_spotify.update_token( user_id=self.user['id'], access_token='testtoken', refresh_token='refreshtesttoken', expires_at=int(time.time()), ) spotify_user = db_spotify.get_user(self.user['id']) self.assertEqual(spotify_user['user_token'], 'testtoken') self.assertEqual(spotify_user['refresh_token'], 'refreshtesttoken')
def test_update_token(self): old_spotify_user = db_spotify.get_user(self.user['id']) db_spotify.update_token( user_id=self.user['id'], access_token='testtoken', refresh_token='refreshtesttoken', expires_at=int(time.time()), ) spotify_user = db_spotify.get_user(self.user['id']) self.assertEqual(spotify_user['user_token'], 'testtoken') self.assertEqual(spotify_user['refresh_token'], 'refreshtesttoken')
def test_update_last_updated(self): old_spotify_user = db_spotify.get_user(self.user['id']) db_spotify.update_last_updated(self.user['id']) spotify_user = db_spotify.get_user(self.user['id']) self.assertTrue(spotify_user['active']) self.assertIsNotNone(spotify_user['last_updated']) db_spotify.update_last_updated(self.user['id'], success=False) new_spotify_user = db_spotify.get_user(self.user['id']) self.assertFalse(new_spotify_user['active']) self.assertGreater(new_spotify_user['last_updated'], spotify_user['last_updated'])
def test_update_last_updated(self): old_spotify_user = db_spotify.get_user(self.user['id']) db_spotify.update_last_updated(self.user['id']) spotify_user = db_spotify.get_user(self.user['id']) self.assertTrue(spotify_user['active']) self.assertIsNotNone(spotify_user['last_updated']) db_spotify.update_last_updated(self.user['id'], success=False) new_spotify_user = db_spotify.get_user(self.user['id']) self.assertFalse(new_spotify_user['active']) self.assertGreater(new_spotify_user['last_updated'], spotify_user['last_updated'])
def get_user(user_id): """ Returns a Spotify instance corresponding to the specified LB row ID. If the user_id is not present in the spotify table, returns None Args: user_id (int): the ListenBrainz row ID of the user """ row = db_spotify.get_user(user_id) if row: return Spotify.from_dbrow(row) return None
def get_user(user_id): """ Returns a Spotify instance corresponding to the specified LB row ID. If the user_id is not present in the spotify table, returns None Args: user_id (int): the ListenBrainz row ID of the user """ row = db_spotify.get_user(user_id) if row: return Spotify.from_dbrow(row) return None
def get_user(self, user_id: int) -> Optional[dict]: return spotify.get_user(user_id)