Exemplo n.º 1
0
    def test_get_active_users_to_process(self):
        db_user.create(2, 'newspotifyuser')
        db_spotify.create_spotify(
            user_id=2,
            user_token='token',
            refresh_token='refresh_token',
            token_expires_ts=int(time.time()),
        )
        users = db_spotify.get_active_users_to_process()
        self.assertEqual(len(users), 2)
        self.assertEqual(users[0]['user_id'], 1)
        self.assertEqual(users[1]['user_id'], 2)

        # check order, the users should be sorted by latest_listened_at timestamp
        db_user.create(3, 'newnewspotifyuser')
        db_spotify.create_spotify(
            user_id=3,
            user_token='tokentoken',
            refresh_token='newrefresh_token',
            token_expires_ts=int(time.time()),
        )
        t = int(time.time())
        db_spotify.update_latest_listened_at(2, t + 20)
        db_spotify.update_latest_listened_at(1, t + 10)
        users = db_spotify.get_active_users_to_process()
        self.assertEqual(len(users), 3)
        self.assertEqual(users[0]['user_id'], 2)
        self.assertEqual(users[1]['user_id'], 1)
        self.assertEqual(users[2]['user_id'], 3)

        db_spotify.add_update_error(2, 'something broke')
        db_spotify.add_update_error(3, 'oops.')
        users = db_spotify.get_active_users_to_process()
        self.assertEqual(len(users), 1)
        self.assertEqual(users[0]['user_id'], 1)
    def test_get_active_users_to_process(self):
        db_user.create(2, 'newspotifyuser')
        db_spotify.create_spotify(
            user_id=2,
            user_token='token',
            refresh_token='refresh_token',
            token_expires_ts=int(time.time()),
        )
        users = db_spotify.get_active_users_to_process()
        self.assertEqual(len(users), 2)
        self.assertEqual(users[0]['user_id'], 1)
        self.assertEqual(users[1]['user_id'], 2)

        # check order, the users should be sorted by latest_listened_at timestamp
        db_user.create(3, 'newnewspotifyuser')
        db_spotify.create_spotify(
            user_id=3,
            user_token='tokentoken',
            refresh_token='newrefresh_token',
            token_expires_ts=int(time.time()),
        )
        t = int(time.time())
        db_spotify.update_latest_listened_at(2, t + 20)
        db_spotify.update_latest_listened_at(1, t + 10)
        users = db_spotify.get_active_users_to_process()
        self.assertEqual(len(users), 3)
        self.assertEqual(users[0]['user_id'], 2)
        self.assertEqual(users[1]['user_id'], 1)
        self.assertEqual(users[2]['user_id'], 3)

        db_spotify.add_update_error(2, 'something broke')
        db_spotify.add_update_error(3, 'oops.')
        users = db_spotify.get_active_users_to_process()
        self.assertEqual(len(users), 1)
        self.assertEqual(users[0]['user_id'], 1)
Exemplo n.º 3
0
def get_active_users_to_process():
    """ Returns a list of Spotify user instances that need their Spotify listens imported.
    """
    return [
        Spotify.from_dbrow(row)
        for row in db_spotify.get_active_users_to_process()
    ]
Exemplo n.º 4
0
    def test_get_active_users_to_process(self):
        db_user.create(2, 'newspotifyuser')
        db_oauth.save_token(
            user_id=2,
            service=ExternalServiceType.SPOTIFY,
            access_token='token',
            refresh_token='refresh_token',
            token_expires_ts=int(time.time()),
            record_listens=True,
            scopes=['user-read-recently-played']
        )
        users = db_spotify.get_active_users_to_process()
        self.assertEqual(len(users), 2)
        self.assertEqual(users[0]['user_id'], 1)
        self.assertEqual(users[0]['musicbrainz_row_id'], 1)
        self.assertEqual(users[1]['user_id'], 2)
        self.assertEqual(users[1]['musicbrainz_row_id'], 2)

        # check order, the users should be sorted by latest_listened_at timestamp
        db_user.create(3, 'newnewspotifyuser')
        db_oauth.save_token(
            user_id=3,
            service=ExternalServiceType.SPOTIFY,
            access_token='tokentoken',
            refresh_token='newrefresh_token',
            token_expires_ts=int(time.time()),
            record_listens=True,
            scopes=['user-read-recently-played']
        )
        t = int(time.time())
        db_import.update_latest_listened_at(2, ExternalServiceType.SPOTIFY, t + 20)
        db_import.update_latest_listened_at(1, ExternalServiceType.SPOTIFY, t + 10)
        users = db_spotify.get_active_users_to_process()
        self.assertEqual(len(users), 3)
        self.assertEqual(users[0]['user_id'], 2)
        self.assertEqual(users[1]['user_id'], 1)
        self.assertEqual(users[2]['user_id'], 3)

        db_import.update_import_status(2, ExternalServiceType.SPOTIFY, 'something broke')
        db_import.update_import_status(3, ExternalServiceType.SPOTIFY, 'oops.')
        users = db_spotify.get_active_users_to_process()
        self.assertEqual(len(users), 1)
        self.assertEqual(users[0]['user_id'], 1)
Exemplo n.º 5
0
 def get_active_users_to_process(self):
     """ Returns a list of Spotify user instances that need their Spotify listens imported.
     """
     return spotify.get_active_users_to_process()
Exemplo n.º 6
0
def get_active_users_to_process():
    """ Returns a list of Spotify user instances that need their Spotify listens imported.
    """
    return [Spotify.from_dbrow(row) for row in db_spotify.get_active_users_to_process()]