Beispiel #1
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 #2
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 #3
0
    def test_submit_rec_album_similar(self):
        round = add_round_to_db(
            description="Albumrecs similar round",
            music_type=MusicType.album,
            snoozin_rec_type=SnoozinRecType.similar,
        )

        self._test_submit_rec(
            round_long_id=round.long_id,
            rec_name="Jonie Nixon",
            rec_spotify_link=
            "https://open.spotify.com/album/3a0UOgDWw2pTajw85QPMiz")
Beispiel #4
0
    def test_submit_rec_album_random(self):
        round = add_round_to_db(
            description="Albumrecs random round",
            music_type=MusicType.album,
            snoozin_rec_type=SnoozinRecType.random,
        )

        self._test_submit_rec(
            round_long_id=round.long_id,
            rec_name="Nick Jones",
            rec_spotify_link=
            "https://open.spotify.com/album/3a0UOgDWw2pTajw85QPMiz")
Beispiel #5
0
    def test_submit_rec_track_similar(self):
        round = add_round_to_db(
            description="Trackrecs similar round",
            music_type=MusicType.track,
            snoozin_rec_type=SnoozinRecType.similar,
        )

        self._test_submit_rec(
            round_long_id=round.long_id,
            rec_name="Dory Johnson",
            rec_spotify_link=
            "http://open.spotify.com/track/6rqhFgbbKwnb9MLmUQDhG6")
Beispiel #6
0
    def test_submit_rec_track_random(self):
        round = add_round_to_db(
            description="Trackrecs random round",
            music_type=MusicType.track,
            snoozin_rec_type=SnoozinRecType.random,
        )

        self._test_submit_rec(
            round_long_id=round.long_id,
            rec_name="John Doe",
            rec_spotify_link=
            "http://open.spotify.com/track/6rqhFgbbKwnb9MLmUQDhG6")
Beispiel #7
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 #8
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 #9
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 #10
0
def index():
    new_round_form = NewRoundForm()

    if new_round_form.validate_on_submit():
        # Add the round to the database
        new_round = add_round_to_db(new_round_form.description.data,
                                    new_round_form.music_type.data,
                                    new_round_form.snoozin_rec_type.data)

        # Go to the page for the new round
        return redirect(url_for('round.index', long_id=new_round.long_id))

    elif new_round_form.errors:
        flash("There were errors in your new round submission", "warning")

    return render_template('index.html', new_round_form=new_round_form)
Beispiel #11
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 #12
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 #13
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)