def test_update_latest_listened_at(self): spotify_user = db_spotify.get_user_import_details(self.user_id) self.assertIsNone(spotify_user['latest_listened_at']) self.assertIsNone(spotify_user['last_updated']) t = int(time.time()) db_import.update_latest_listened_at(self.user_id, ExternalServiceType.SPOTIFY, t) spotify_user = db_spotify.get_user_import_details(self.user_id) self.assertEqual(t, int(spotify_user['latest_listened_at'].strftime('%s'))) self.assertIsNotNone(spotify_user['last_updated'])
def test_update_import_status(self): db_import.update_import_status(self.user_id, ExternalServiceType.SPOTIFY, 'test error message') spotify_user = db_spotify.get_user_import_details(self.user_id) self.assertEqual(spotify_user['error_message'], 'test error message') self.assertIsNotNone(spotify_user['last_updated']) db_import.update_import_status(self.user_id, ExternalServiceType.SPOTIFY) spotify_user = db_spotify.get_user_import_details(self.user_id) self.assertIsNone(spotify_user['error_message']) self.assertIsNotNone(spotify_user['last_updated'])
def test_delete_token_unlink(self): db_oauth.delete_token(self.user['id'], ExternalServiceType.SPOTIFY, remove_import_log=True) self.assertIsNone( db_oauth.get_token(self.user['id'], ExternalServiceType.SPOTIFY)) self.assertIsNone(db_spotify.get_user_import_details(self.user['id']))
def get_user_connection_details(self, user_id: int): user = spotify.get_user_import_details(user_id) if user: def date_to_iso(date): return date.isoformat() + "Z" if date else None user['latest_listened_at_iso'] = date_to_iso( user['latest_listened_at']) user['last_updated_iso'] = date_to_iso(user['last_updated']) return user
def test_get_user_import_details(self): user = db_spotify.get_user_import_details(self.user['id']) self.assertEqual(user['user_id'], self.user['id']) self.assertIn('last_updated', user) self.assertIn('latest_listened_at', user) self.assertIn('error_message', user)