Beispiel #1
0
    def test_track_random_advance_to_listen(self):
        # Add a round to the database
        round = add_round_to_db(description="Trackrecs random round",
                                music_type=MusicType.track,
                                snoozin_rec_type=SnoozinRecType.random,
                                status=RoundStatus.submit)

        # Add a submission to the round
        add_submission_to_db(
            round.id, "John Doe",
            "http://open.spotify.com/track/6rqhFgbbKwnb9MLmUQDhG6")

        # Mock the search_for_music spotify interface
        def _mock_search_for_music(*args, **kwargs):
            track_mock = Mock(spec=SpotifyTrack)
            track_mock.link = "http://open.spotify.com/track/7GhIk7Il098yCjg4BQjzvb"

            return [track_mock]

        spotify_iface.search_for_music = Mock(
            side_effect=_mock_search_for_music)

        # Run the advance to listen test
        self._test_advance_to_listen(
            round, "http://open.spotify.com/track/7GhIk7Il098yCjg4BQjzvb")
Beispiel #2
0
    def test_album_random_advance_to_listen(self):
        # Add a round to the database
        round = add_round_to_db(description="Albumrecs random round",
                                music_type=MusicType.album,
                                snoozin_rec_type=SnoozinRecType.random,
                                status=RoundStatus.submit)

        # Add a submission to the round
        add_submission_to_db(
            round.id, "Nick Jones",
            "https://open.spotify.com/album/3a0UOgDWw2pTajw85QPMiz")

        # Mock the search_for_music spotify interface
        def _mock_search_for_music(*args, **kwargs):
            album_mock = Mock(spec=SpotifyAlbum)
            album_mock.link = "https://open.spotify.com/album/5Z9iiGl2FcIfa3BMiv6OIw"

            return [album_mock]

        spotify_iface.search_for_music = Mock(
            side_effect=_mock_search_for_music)

        # Run the advance to listen test
        self._test_advance_to_listen(
            round, "https://open.spotify.com/album/5Z9iiGl2FcIfa3BMiv6OIw")
Beispiel #3
0
    def test_album_listen(self):
        # Add a round to the database
        round = add_round_to_db(description="Albumrecs random round",
                                music_type=MusicType.album,
                                snoozin_rec_type=SnoozinRecType.random,
                                status=RoundStatus.listen)

        # Add a couple submissions to the round
        add_submission_to_db(
            round.id, "Nick Jones",
            "https://open.spotify.com/album/3a0UOgDWw2pTajw85QPMiz")
        add_submission_to_db(
            round.id, "snoozin",
            "https://open.spotify.com/album/5Z9iiGl2FcIfa3BMiv6OIw")

        # Verify that the round page contains submissions
        response = self.client.get(
            url_for('round.listen', long_id=round.long_id))
        self.assert_200(response)
        self.assertIn(bytes("Nick Jones", 'utf-8'), response.data)
        self.assertIn(
            bytes("https://open.spotify.com/album/3a0UOgDWw2pTajw85QPMiz",
                  'utf-8'), response.data)
        self.assertIn(bytes("snoozin", 'utf-8'), response.data)
        self.assertIn(
            bytes("https://open.spotify.com/album/5Z9iiGl2FcIfa3BMiv6OIw",
                  'utf-8'), response.data)

        # Submit Nick Jones' guess (cheating to make sure it's correct)
        nick_jones_num = get_shuffled_user_name_list(round).index("Nick Jones")
        snoozin_num = get_shuffled_user_name_list(round).index("snoozin")
        response = self.client.post(
            url_for('round.listen', long_id=round.long_id),
            data=dict(name="Nick Jones",
                      guess_field=
                      f"snoozin:{snoozin_num}\nNick Jones: {nick_jones_num}",
                      submit_guess="Submit"),
            follow_redirects=False)

        # Verify that post was successfull, and redirected
        self.assertRedirects(response,
                             url_for('round.listen', long_id=round.long_id))

        # Verify that Nick Jones's guesses were added to the database and are correct
        for guess in Submission.query.filter_by(
                user_name="Nick Jones").first().guesses:
            self.assertEqual(guess.submission_id, 1)
            self.assertEqual(
                get_shuffled_user_name_list(round).index(guess.user_name),
                guess.music_num)
            self.assertEqual(guess.correct, True)
Beispiel #4
0
    def test_album_advance_to_revealed(self):
        # Add a round to the database
        round = add_round_to_db(description="Albumrecs random round",
                                music_type=MusicType.album,
                                snoozin_rec_type=SnoozinRecType.random,
                                status=RoundStatus.listen)

        # Add a submission to the round
        add_submission_to_db(
            round.id, "Nick Jones",
            "https://open.spotify.com/album/3a0UOgDWw2pTajw85QPMiz")

        # Run the advance to revealed test
        self._test_advance_to_revealed(round)
Beispiel #5
0
    def test_track_advance_to_revealed(self):
        # Add a round to the database
        round = add_round_to_db(description="Trackrecs random round",
                                music_type=MusicType.track,
                                snoozin_rec_type=SnoozinRecType.random,
                                status=RoundStatus.listen)

        # Add a submission to the round
        add_submission_to_db(
            round.id, "John Doe",
            "http://open.spotify.com/track/6rqhFgbbKwnb9MLmUQDhG6")

        # Run the advance to revealed test
        self._test_advance_to_revealed(round)
Beispiel #6
0
def submit(long_id):
    # Get the round from the long id
    round = Round.query.filter_by(long_id=long_id).first()

    # Make sure this is the correct handler for the round's current status
    if round.status != RoundStatus.submit:
        raise MusicrecsAlert(f"This round is currently in the {round.status.name} phase...",
                             redirect_location=url_for(f'round.{round.status.name}', long_id=round.long_id))

    # Get data from the rec form
    if round.music_type == MusicType.album:
        rec_form = AlbumrecForm(round)
    elif round.music_type == MusicType.track:
        rec_form = TrackrecForm(round)
    else:
        raise MusicrecsError(f"Unknown music type {round.music_type}")

    # Process the submission form
    if rec_form.validate_on_submit():
        # Add the submission to the database
        add_submission_to_db(round.id, rec_form.name.data, rec_form.spotify_link.data)

        # Alert the user that the form was successfully submitted
        flash("Successfully submitted your recommendation: "
              f"{spotify_iface.get_music_from_link(round.music_type, rec_form.spotify_link.data)}",
              "success")

        # Redirect back to the round after successful submission
        return redirect(url_for('round.submit', long_id=long_id))

    elif rec_form.errors:
        flash("There were errors in your rec submission", "warning")

    return render_template('round/submit_phase.html',
                           round_link=get_abs_round_link(round),
                           rec_form=rec_form,
                           round=round)
Beispiel #7
0
    def test_track_revealed(self):
        # Add a round to the database
        round = add_round_to_db(description="Albumrecs random round",
                                music_type=MusicType.track,
                                snoozin_rec_type=SnoozinRecType.random,
                                status=RoundStatus.revealed)

        # Add a few submissions to the round
        add_submission_to_db(
            round.id, "John Doe",
            "http://open.spotify.com/track/6rqhFgbbKwnb9MLmUQDhG6")
        add_submission_to_db(
            round.id, "Dory Johnson",
            "https://open.spotify.com/track/354K3xQPgALQEOiIYzAMat")
        add_submission_to_db(
            round.id, "snoozin",
            "http://open.spotify.com/track/7GhIk7Il098yCjg4BQjzvb")

        # Get the correct shuffled user name order
        shuffled_user_names = get_shuffled_user_name_list(round)

        # Add a John Doe's guesses to the round, mixing up Dory and snoozin
        # (NOTE: There is no testing as of now to verify that these
        # guesses added to the database are displayed correctly)
        add_guess_to_db(1, "Dory Johnson",
                        shuffled_user_names.index("snoozin"), False)
        add_guess_to_db(1, "snoozin",
                        shuffled_user_names.index("Dory Johnson"), False)
        add_guess_to_db(1, "John Doe", shuffled_user_names.index("John Doe"),
                        True)

        # Verify that the round page contains the correct pairings of link with submitter
        response = self.client.get(
            url_for('round.revealed', long_id=round.long_id))
        self.assert_200(response)
        href_results = re.findall(r'<a href=(.+?)</a>', str(response.data))
        for href_result in href_results:
            if "http://open.spotify.com/track/6rqhFgbbKwnb9MLmUQDhG6" in href_result:
                self.assertIn("John Doe", href_result)
            elif "https://open.spotify.com/track/354K3xQPgALQEOiIYzAMat" in href_result:
                self.assertIn("Dory Johnson", href_result)
            elif "http://open.spotify.com/track/7GhIk7Il098yCjg4BQjzvb" in href_result:
                self.assertIn("snoozin", href_result)
            else:
                raise Exception(f"Unknown link in href {href_result}")
Beispiel #8
0
    def test_album_revealed(self):
        # Add a round to the database
        round = add_round_to_db(description="Albumrecs random round",
                                music_type=MusicType.album,
                                snoozin_rec_type=SnoozinRecType.random,
                                status=RoundStatus.revealed)

        # Add a couple submissions to the round
        add_submission_to_db(
            round.id, "Nick Jones",
            "https://open.spotify.com/album/3a0UOgDWw2pTajw85QPMiz")
        add_submission_to_db(
            round.id, "Jonie Nixon",
            "https://open.spotify.com/album/1vz94WpXDVYIEGja8cjFNa")
        add_submission_to_db(
            round.id, "snoozin",
            "https://open.spotify.com/album/5Z9iiGl2FcIfa3BMiv6OIw")

        # Get the correct shuffled user name order
        shuffled_user_names = get_shuffled_user_name_list(round)

        # Add Nick Jones's guesses to the round, mixing up Jonie and snoozin
        # (NOTE: There is no testing as of now to verify that these
        # guesses added to the database are displayed correctly)
        add_guess_to_db(1, "Jonie Nixon", shuffled_user_names.index("snoozin"),
                        False)
        add_guess_to_db(1, "snoozin", shuffled_user_names.index("Jonie Nixon"),
                        False)
        add_guess_to_db(1, "Nick Jones",
                        shuffled_user_names.index("Nick Jones"), True)

        # Verify that the round page contains the correct pairings of link with submitter
        response = self.client.get(
            url_for('round.revealed', long_id=round.long_id))
        self.assert_200(response)
        href_results = re.findall(r'<a href=(.+?)</a>', str(response.data))
        for href_result in href_results:
            if "https://open.spotify.com/album/3a0UOgDWw2pTajw85QPMiz" in href_result:
                self.assertIn("Nick Jones", href_result)
            elif "https://open.spotify.com/album/1vz94WpXDVYIEGja8cjFNa" in href_result:
                self.assertIn("Jonie Nixon", href_result)
            elif "https://open.spotify.com/album/5Z9iiGl2FcIfa3BMiv6OIw" in href_result:
                self.assertIn("snoozin", href_result)
            else:
                raise Exception(f"Unknown link in href {href_result}")
Beispiel #9
0
    def test_track_listen(self):
        # Add a round to the database
        round = add_round_to_db(description="Trackrecs random round",
                                music_type=MusicType.track,
                                snoozin_rec_type=SnoozinRecType.random,
                                status=RoundStatus.listen)

        # Add a couple submissions to the round
        add_submission_to_db(
            round.id, "John Doe",
            "http://open.spotify.com/track/6rqhFgbbKwnb9MLmUQDhG6")
        add_submission_to_db(
            round.id, "snoozin",
            "http://open.spotify.com/track/7GhIk7Il098yCjg4BQjzvb")

        # Verify that the round page contains submissions
        response = self.client.get(
            url_for('round.listen', long_id=round.long_id))
        self.assert_200(response)
        self.assertIn(bytes("John Doe", 'utf-8'), response.data)
        self.assertIn(
            bytes("http://open.spotify.com/track/6rqhFgbbKwnb9MLmUQDhG6",
                  'utf-8'), response.data)
        self.assertIn(bytes("snoozin", 'utf-8'), response.data)
        self.assertIn(
            bytes("http://open.spotify.com/track/7GhIk7Il098yCjg4BQjzvb",
                  'utf-8'), response.data)

        # Mock the required spotify interfaces for creating a playlist
        playlist_mock = Mock(spec=SpotifyPlaylist)
        playlist_mock.link = "https://open.spotify.com/playlist/32O0SSXDNWDrMievPkV0Im"

        def _mock_create_playlist(*args, **kwargs):
            if "name" in kwargs:
                playlist_mock.name = kwargs["name"]
            else:
                playlist_mock.name = args[0]

            return playlist_mock

        spotify_user.create_playlist = Mock(side_effect=_mock_create_playlist)

        spotify_iface.get_playlist_from_link = Mock(return_value=playlist_mock)

        # Make a post to create a playlist
        response = self.client.post(
            url_for('round.listen', long_id=round.long_id),
            data=dict(name="john doe and snoozin make a playlist",
                      submit_playlist="Submit"),
            follow_redirects=False)

        # Verify that post was successfull, and redirected
        self.assertRedirects(response,
                             url_for('round.listen', long_id=round.long_id))

        # Verify that the playlist link was added to the db
        self.assertEqual(
            round.playlist_link,
            "https://open.spotify.com/playlist/32O0SSXDNWDrMievPkV0Im")

        # Verify that the round page now contains the playlist name
        response = self.client.get(
            url_for('round.listen', long_id=round.long_id))
        self.assert_200(response)
        self.assertIn(bytes("john doe and snoozin make a playlist", 'utf-8'),
                      response.data)

        # Submit John Doe's guess
        john_doe_num = get_shuffled_user_name_list(round).index("John Doe")
        snoozin_num = get_shuffled_user_name_list(round).index("snoozin")
        response = self.client.post(
            url_for('round.listen', long_id=round.long_id),
            data=dict(
                name="John Doe",
                guess_field=f"snoozin:{snoozin_num}\nJohn Doe: {john_doe_num}",
                submit_guess="Submit"),
            follow_redirects=False)

        # Verify that post was successfull, and redirected
        self.assertRedirects(response,
                             url_for('round.listen', long_id=round.long_id))

        # Verify that John Doe's guesses were added to the database and are correct
        for guess in Submission.query.filter_by(
                user_name="John Doe").first().guesses:
            self.assertEqual(guess.submission_id, 1)
            self.assertEqual(
                get_shuffled_user_name_list(round).index(guess.user_name),
                guess.music_num)
            self.assertEqual(guess.correct, True)