Exemple #1
0
    def test_method_uses_cached_return_value_if_present(
            self, mock_cache, mock_song_lookup):
        genres = ['foo']
        mock_cache.return_value = genres

        expected_genres = [('', '-----------'), ('foo', 'Foo')]
        returned_genres = get_genre_choices()

        self.assertEqual(returned_genres, expected_genres)
        mock_song_lookup.assert_not_called()
Exemple #2
0
    def test_method_omits_empty_genre(self):
        song_with_genre = MoodyUtil.create_song(genre='hiphop')
        MoodyUtil.create_song(genre='')

        expected_choices = [
            default_option[0],
            (song_with_genre.genre, song_with_genre.genre.capitalize()),
        ]

        choices = get_genre_choices()

        self.assertEqual(choices, expected_choices)
Exemple #3
0
    def test_method_returns_all_song_genres(self):
        hiphop_song = MoodyUtil.create_song(genre='hiphop')
        rock_song = MoodyUtil.create_song(genre='rock')

        expected_choices = [
            default_option[0],
            (hiphop_song.genre, hiphop_song.genre.capitalize()),
            (rock_song.genre, rock_song.genre.capitalize())
        ]

        choices = get_genre_choices()

        self.assertEqual(choices, expected_choices)
Exemple #4
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.fields['genre'].choices = get_genre_choices()