Exemple #1
0
    def test_update_artist_frequency_counts_when_two_collections(self):
        a1, a2, a3 = fixtures.artist_1(), fixtures.artist_2(), fixtures.artist_3()
        t1, t2, t3 = fixtures.track_1(), fixtures.track_2(), fixtures.track_3()
        c1, c2 = fixtures.collection_1(), fixtures.collection_2()

        # Wire the collections
        t1.artist.add(a1)
        t2.artist.add(a1, a2)
        t3.artist.add(a1, a2, a3)
        c1.add_tracks([t1, t2])  # a1 + a1+a2
        c2.add_tracks([t2, t3])  # a1+a2 + a1+a2+a3

        l_stat = fixtures.library_stat()
        _ = fixtures.collection_stat(collection=c1)
        _ = fixtures.collection_stat(collection=c2)

        artist_frequency_counts = l_stat.update_artist_frequency_counts()
        self.assertEqual(3, len(artist_frequency_counts))

        #  TODO move this to a Mixin
        a1_result = next(x for x in artist_frequency_counts if x.artist.id == a1.id)
        self.assertEqual(4, a1_result.frequency)

        a2_result = next(x for x in artist_frequency_counts if x.artist.id == a2.id)
        self.assertEqual(3, a2_result.frequency)

        a3_result = next(x for x in artist_frequency_counts if x.artist.id == a3.id)
        self.assertEqual(1, a3_result.frequency)
Exemple #2
0
    def test_collection_property_when_added_to_collections(self):
        t = fixtures.track_1()

        c1 = fixtures.collection_1().add_tracks([t])
        c2 = fixtures.collection_2().add_tracks([t])

        self.assertEqual(t.collections, [c1, c2])
Exemple #3
0
    def test_artist_collections_stat_several_artist(self):
        a1 = fixtures.artist_1()
        a2 = fixtures.artist_2()

        t1 = fixtures.track_1()
        t2 = fixtures.track_2()

        t1.artist.add(a1)
        t2.artist.add(a1, a2)

        t1.save()
        t2.save()

        c1 = fixtures.collection_1()
        c1.add_tracks([t1, t2])
        c1.save()

        c_stat = fixtures.collection_stat(collection=c1)

        artist_frequency_counts = c_stat.update_artist_frequency_counts()

        self.assertEqual(len(artist_frequency_counts), 2)
        a1_result = next(x for x in artist_frequency_counts if x.artist.id == a1.id)
        a2_result = next(x for x in artist_frequency_counts if x.artist.id == a2.id)
        self.assertIsNotNone(a1_result)
        self.assertIsNotNone(a2_result)

        self.assertEqual(a1_result.frequency, 2)
        self.assertEqual(a2_result.frequency, 1)
Exemple #4
0
    def test_track_add_ordinal(self):
        c = fixtures.collection_1()
        t2, t1 = fixtures.track_2(), fixtures.track_1()

        c = c.add_tracks([t1, t2])

        self.assertEqual([t for t in c.tracks], [t1, t2])
Exemple #5
0
    def test_track_add_respects_order_when_called_twice(self):
        c = fixtures.collection_1()
        t1, t2, t3 = fixtures.track_1(), fixtures.track_2(), fixtures.track_3()

        c = c.add_tracks([t1, t2])
        c = c.add_tracks([t3])

        self.assertEqual([t for t in c.tracks], [t1, t2, t3])
Exemple #6
0
    def test_duration_sum(self):
        c = fixtures.collection_1()

        duration1 = datetime.timedelta(minutes=0, seconds=18)
        duration2 = datetime.timedelta(minutes=0, seconds=100)
        t1 = fixtures.track_1(duration=duration1)
        t2 = fixtures.track_2(duration=duration2)

        c.add_tracks([t1, t2])

        actual = c.duration
        expected = t1.duration + t2.duration

        self.assertEqual(actual.seconds, expected.seconds)
Exemple #7
0
 def test_collection_track_constraint(self):
     c = fixtures.collection_1(name="c1")
     TrackInCollection.objects.create(
         track=fixtures.track_1(name="t1"),
         collection=c,
         ordinal=1,
     )
     # Test the constraint for ordinal in the collection
     with self.assertRaises(Exception):
         TrackInCollection.objects.create(
             track=fixtures.track_1(name="t2"),
             collection=c,
             ordinal=1,
         )
Exemple #8
0
    def test_duplicate_tracks_from_two_collections(self):
        a1, a2, a3 = fixtures.artist_1(), fixtures.artist_2(), fixtures.artist_3()
        t1, t2, t3, t4 = fixtures.track_1(), fixtures.track_2(), fixtures.track_3(), fixtures.track_3(name="Track 4")
        c1, c2 = fixtures.collection_1(), fixtures.collection_2()

        # Wire the collections
        t1.artist.add(a1)
        t2.artist.add(a1, a2)
        t3.artist.add(a1, a2, a3)
        t4.artist.add(a1)
        c1.add_tracks([t1, t2, t4])
        c2.add_tracks([t2, t3, t4])

        _ = fixtures.collection_stat(collection=c1)
        _ = fixtures.collection_stat(collection=c2)

        l_stat = fixtures.library_stat()
        duplicate_tracks = l_stat.update_duplicate_tracks()
        track_ids = {dt.track_id for dt in duplicate_tracks}
        self.assertEqual(set([t2.id, t4.id]), track_ids)
Exemple #9
0
    def test_artist_collections_stat_single_artist(self):
        artist = fixtures.artist_1()

        t1 = fixtures.track_1()
        t2 = fixtures.track_2()

        t1.artist.add(artist)
        t2.artist.add(artist)

        t1.save()
        t2.save()

        c1 = fixtures.collection_1()
        c1.add_tracks([t1, t2])
        c1.save()

        c_stat = fixtures.collection_stat(collection=c1)

        artist_frequency_counts = c_stat.update_artist_frequency_counts()

        self.assertEqual(len(artist_frequency_counts), 1)
        artist_frequency_count = artist_frequency_counts[0]
        self.assertEqual(artist_frequency_count.artist, artist)
        self.assertEqual(artist_frequency_count.frequency, 2)
Exemple #10
0
    def test_track_count(self):
        c = fixtures.collection_1()

        c = c.add_tracks([fixtures.track_1(), fixtures.track_2()])

        self.assertEqual(c.number_of_tracks(), 2)
Exemple #11
0
 def test_empty_tracks(self):
     c = fixtures.collection_1()
     self.assertEqual(c.number_of_tracks(), 0)
Exemple #12
0
 def test_empty_collection_duration(self):
     c = fixtures.collection_1()
     self.assertEqual(c.duration.seconds, 0)