Exemple #1
0
    def test_fcfs_with_voting_selection(self):
        set_config_value('SELECTION_SCHEME', 'FCFS_VOTE')
        load_config_from_db()
        self.mpd.clear()
        _ensure_mpd_playlist_consistency(self.mpd)
        assert len(self.mpd.playlistinfo()) == 0
        assert len(PlayQueueEntry.query.all()) == 0

        user1 = self.create_test_user()
        user2 = self.create_test_user()

        tracks = []

        for i in range(1, 11):
            st = self.random_sample_track()
            tracks.append(
                add_track_from_spotify_url(self.mpd, st['file'], user1.id))

        # Simulate the callback chain that would occur in the wild
        last_order = []
        while last_order != [i['id'] for i in self.mpd.playlistinfo()]:
            last_order = [i['id'] for i in self.mpd.playlistinfo()]
            _ensure_mpd_playlist_consistency(self.mpd)

        for mpd_track, expected_track in zip(self.mpd.playlistinfo(), tracks):
            assert mpd_track['file'] == expected_track.spotify_url

        r = random.Random()
        pqes = PlayQueueEntry.query.order_by(PlayQueueEntry.time_added).all()
        up_voted = []
        down_voted = []
        for i in range(1, 4):
            pqe = r.choice(pqes)
            pqes.remove(pqe)
            up_voted.append(pqe)
            vote = Vote(user=user2, pqe=pqe, direction=1)
            db.session.add(vote)

        for i in range(1, 4):
            pqe = r.choice(pqes)
            pqes.remove(pqe)
            down_voted.append(pqe)
            vote = Vote(user=user2, pqe=pqe, direction=-1)
            db.session.add(vote)

        db.session.commit()

        up_voted = sorted(up_voted, key=lambda x: x.time_added)
        down_voted = sorted(down_voted, key=lambda x: x.time_added)
        expected_order = up_voted + pqes + down_voted

        # Simulate the callback chain that would occur in the wild
        last_order = []
        while last_order != [i['id'] for i in self.mpd.playlistinfo()]:
            last_order = [i['id'] for i in self.mpd.playlistinfo()]
            _ensure_mpd_playlist_consistency(self.mpd)

        for mpd_track, expected_track in zip(self.mpd.playlistinfo(),
                                             expected_order):
            assert mpd_track['file'] == expected_track.track.spotify_url
Exemple #2
0
    def test_fcfs_selection(self):
        set_config_value('SELECTION_SCHEME', 'FCFS')
        load_config_from_db()
        self.mpd.clear()
        _ensure_mpd_playlist_consistency(self.mpd)
        assert len(self.mpd.playlistinfo()) == 0
        assert len(PlayQueueEntry.query.all()) == 0

        # Simulate 5 users queueing up 10 tracks each in serial
        users = []
        for i in range(1, 4):
            user = self.create_test_user()
            for i in range(1, 4):
                users.append(user)
                track = self.random_sample_track()
                add_track_from_spotify_url(self.mpd, track['file'], user.id)

        # Simulate the callback chain that would occur in the wild
        last_order = []
        while last_order != [i['id'] for i in self.mpd.playlistinfo()]:
            last_order = [i['id'] for i in self.mpd.playlistinfo()]
            _ensure_mpd_playlist_consistency(self.mpd)

        mpd_playlist = self.mpd.playlistinfo()
        db_tracks = PlayQueueEntry.query.order_by(PlayQueueEntry.playback_priority.asc()).all()

        for (pqe, mpd_track) in zip(db_tracks, mpd_playlist):
            assert pqe.playback_priority == mpd_track['pos']

        for (pqe, prop_user) in zip(db_tracks, users):
            assert pqe.user == prop_user
Exemple #3
0
    def test_fcfs_selection(self):
        set_config_value('SELECTION_SCHEME', 'FCFS')
        load_config_from_db()
        self.mpd.clear()
        _ensure_mpd_playlist_consistency(self.mpd)
        assert len(self.mpd.playlistinfo()) == 0
        assert len(PlayQueueEntry.query.all()) == 0

        # Simulate 5 users queueing up 10 tracks each in serial
        users = []
        for i in range(1, 4):
            user = self.create_test_user()
            for i in range(1, 4):
                users.append(user)
                track = self.random_sample_track()
                add_track_from_spotify_url(self.mpd, track['file'], user.id)

        # Simulate the callback chain that would occur in the wild
        last_order = []
        while last_order != [i['id'] for i in self.mpd.playlistinfo()]:
            last_order = [i['id'] for i in self.mpd.playlistinfo()]
            _ensure_mpd_playlist_consistency(self.mpd)

        mpd_playlist = self.mpd.playlistinfo()
        db_tracks = PlayQueueEntry.query.order_by(
            PlayQueueEntry.playback_priority.asc()).all()

        for (pqe, mpd_track) in zip(db_tracks, mpd_playlist):
            assert pqe.playback_priority == mpd_track['pos']

        for (pqe, prop_user) in zip(db_tracks, users):
            assert pqe.user == prop_user
Exemple #4
0
    def test_fcfs_with_voting_selection(self):
        set_config_value('SELECTION_SCHEME', 'FCFS_VOTE')
        load_config_from_db()
        self.mpd.clear()
        _ensure_mpd_playlist_consistency(self.mpd)
        assert len(self.mpd.playlistinfo()) == 0
        assert len(PlayQueueEntry.query.all()) == 0

        user1 = self.create_test_user()
        user2 = self.create_test_user()

        tracks = []

        for i in range(1,11):
            st = self.random_sample_track()
            tracks.append(add_track_from_spotify_url(self.mpd, st['file'], user1.id))

        # Simulate the callback chain that would occur in the wild
        last_order = []
        while last_order != [i['id'] for i in self.mpd.playlistinfo()]:
            last_order = [i['id'] for i in self.mpd.playlistinfo()]
            _ensure_mpd_playlist_consistency(self.mpd)

        for mpd_track, expected_track in zip(self.mpd.playlistinfo(), tracks):
            assert mpd_track['file'] == expected_track.spotify_url

        r = random.Random()
        pqes = PlayQueueEntry.query.order_by(PlayQueueEntry.time_added).all()
        up_voted = []
        down_voted = []
        for i in range(1,4):
            pqe = r.choice(pqes)
            pqes.remove(pqe)
            up_voted.append(pqe)
            vote = Vote(user=user2, pqe=pqe, direction=1)
            db.session.add(vote)

        for i in range(1,4):
            pqe = r.choice(pqes)
            pqes.remove(pqe)
            down_voted.append(pqe)
            vote = Vote(user=user2, pqe=pqe, direction=-1)
            db.session.add(vote)

        db.session.commit()

        up_voted = sorted(up_voted, key=lambda x: x.time_added)
        down_voted = sorted(down_voted, key=lambda x: x.time_added)
        expected_order = up_voted + pqes + down_voted

        # Simulate the callback chain that would occur in the wild
        last_order = []
        while last_order != [i['id'] for i in self.mpd.playlistinfo()]:
            last_order = [i['id'] for i in self.mpd.playlistinfo()]
            _ensure_mpd_playlist_consistency(self.mpd)

        for mpd_track, expected_track in zip(self.mpd.playlistinfo(), expected_order):
            assert mpd_track['file'] == expected_track.track.spotify_url
Exemple #5
0
    def test_loaded_types(self):
        load_config_from_db()

        assert isinstance(app.config["DEBUG"], bool)
        assert isinstance(app.config["MPD_SERVER_PORT"], int)
        assert isinstance(app.config["PROFILE"], bool)
        assert isinstance(app.config["SERVER_PORT"], int)
        assert isinstance(app.config["TESTING"], bool)
        set_config_value("TESTING", True)
Exemple #6
0
    def test_loaded_types(self):
        load_config_from_db()

        assert isinstance(app.config["DEBUG"], bool)
        assert isinstance(app.config["MPD_SERVER_PORT"], int)
        assert isinstance(app.config["PROFILE"], bool)
        assert isinstance(app.config["SERVER_PORT"], int)
        assert isinstance(app.config["TESTING"], bool)
        set_config_value("TESTING", True)
Exemple #7
0
def configuration_update():
    configuration_form = ConfigurationForm(request.form)
    
    if configuration_form.validate():
        for key,val in configuration_form.data.iteritems():
            key = key.upper()
            set_config_value(key, val)
        load_config_from_db()
        
    return redirect(url_for('admin_console'))
Exemple #8
0
def configuration_update():
    """Updates the configuration values provided by the configuration form
    presented by :func:`admin_console`.
    """
    configuration_form = ConfigurationForm(request.form)

    if configuration_form.validate():
        for key, val in configuration_form.data.iteritems():
            key = key.upper()
            set_config_value(key, val)
        load_config_from_db()

    return redirect(url_for('admin_console'))
Exemple #9
0
def configuration_update():
    """Updates the configuration values provided by the configuration form
    presented by :func:`admin_console`.
    """
    configuration_form = ConfigurationForm(request.form)
    
    if configuration_form.validate():
        for key,val in configuration_form.data.iteritems():
            key = key.upper()
            set_config_value(key, val)
        load_config_from_db()
        
    return redirect(url_for('admin_console'))
Exemple #10
0
def on_startup():
    try:
        load_config_from_db()
    except:
        init_db()
        load_config_from_db()
    ipc.init_times()
    ipc.init_desired_player_state()
    ipc.init_mpd_lock()
    ensure_mpd_playlist_consistency()
    ipc.update_time('playlist', time.time())

    # Start the process which subscribes to MPD events using the IDLE command
    mpd_event_listener = Process(target=on_playlist_update)
    mpd_event_listener.start()
Exemple #11
0
def on_startup():
    """Performs all of the actions needed to get the web server up and running."""
    try:
        load_config_from_db()
    except:
        init_db()
        load_config_from_db()
    ipc.init_times()
    ipc.init_desired_player_state()
    ipc.init_mpd_lock()
    ensure_mpd_playlist_consistency()
    ipc.update_time('playlist', time.time())

    # Start the process which subscribes to MPD events using the IDLE command
    if not app.config['TESTING']:
        mpd_event_listener = Process(target=on_playlist_update)
        mpd_event_listener.start()
Exemple #12
0
def on_startup():
    """Performs all of the actions needed to get the web server up and running."""
    try:
        load_config_from_db()
    except:
        init_db()
        load_config_from_db()
    ipc.init_times()
    ipc.init_desired_player_state()
    ipc.init_mpd_lock()
    ensure_mpd_playlist_consistency()
    ipc.update_time('playlist', time.time())

    # Start the process which subscribes to MPD events using the IDLE command
    if not app.config['TESTING']:
        mpd_event_listener = Process(target=on_playlist_update)
        mpd_event_listener.start()
Exemple #13
0
    def test_sensible_defaults(self):
        # Remove any existing configuration values for the stuff we get defaults for

        for key in ("DEBUG", "LASTFM_API_KEY", "LASTFM_API_SECRET", "MPD_SERVER_HOSTNAME",
            "MPD_SERVER_PORT", "PROFILE", "SERVER"):
            fields = ConfigurationField.query.filter(ConfigurationField.field_name == key).all()
            for field in fields:
                db.session.delete(field)
        db.session.commit()

        load_config_from_db()

        assert app.config["DEBUG"] == True
        assert app.config["LASTFM_API_KEY"] == ""
        assert app.config["LASTFM_API_SECRET"] == ""
        assert app.config["MPD_SERVER_HOSTNAME"] == "localhost"
        assert app.config["MPD_SERVER_PORT"] == 6600
        assert app.config["PROFILE"] == False
        assert app.config["SERVER"] == "tornado"

        set_config_value("TESTING", True)
Exemple #14
0
    def test_sensible_defaults(self):
        # Remove any existing configuration values for the stuff we get defaults for

        for key in ("DEBUG", "LASTFM_API_KEY", "LASTFM_API_SECRET",
                    "MPD_SERVER_HOSTNAME", "MPD_SERVER_PORT", "PROFILE",
                    "SERVER"):
            fields = ConfigurationField.query.filter(
                ConfigurationField.field_name == key).all()
            for field in fields:
                db.session.delete(field)
        db.session.commit()

        load_config_from_db()

        assert app.config["DEBUG"] == True
        assert app.config["LASTFM_API_KEY"] == ""
        assert app.config["LASTFM_API_SECRET"] == ""
        assert app.config["MPD_SERVER_HOSTNAME"] == "localhost"
        assert app.config["MPD_SERVER_PORT"] == 6600
        assert app.config["PROFILE"] == False
        assert app.config["SERVER"] == "tornado"

        set_config_value("TESTING", True)