Esempio n. 1
0
tracks = []
for i in range(6):
    track = {
        "album": {
            "id": "album{}".format(i),
        },
        "artists": [{
            "id": "artist{}".format(i)
        }],
        "id": "song{}".format(i),
        "popularity": i
    }
    tracks.append(track)

libraries = [SelectionLibrary(tracks[0:4]), SelectionLibrary(tracks[2:6])]
request = {'target_no_songs': 3, 'libraries': libraries}


class TestSelector(TestCase):
    @classmethod
    def setUpClass(cls):
        cls.selector = Selector()
        cls.tracks = cls.selector.choose_tracks(request)

    def test_choose_tracks_invalid_req_type(self):
        """should raise a TypeError if the request is not a dict"""
        with self.assertRaises(TypeError):
            self.selector.choose_tracks("")

    def test_choose_tracks_invalid_req_values(self):
 def test_normal(self):
     lib = SelectionLibrary([test_track])
     tracks = lib.get_tracks()
     self.assertEqual(tracks[0].get_id(), SelectionTrack(test_track).get_id())
 def test_empty_library(self):
     """get_tracks should return [] when the library is empty"""
     lib = SelectionLibrary([])
     self.assertEqual(lib.get_tracks(), [])
 def test_valid(self):
     lib = SelectionLibrary([test_track, test_track])
     self.assertIsInstance(lib, SelectionLibrary)
 def test_no_tracks(self):
     """Creating a SelectionLibrary with no tracks is valid"""
     lib = SelectionLibrary([])
     self.assertIsInstance(lib, SelectionLibrary)
 def test_invalid_tracks(self):
     """Creating a SelectionLibrary where the tracks arg is not a list should raise an error"""
     with self.assertRaises(TypeError):
         SelectionLibrary({})