music-kraken-core/tests/test_collection.py

128 lines
4.5 KiB
Python
Raw Normal View History

2024-04-12 15:58:18 +00:00
import unittest
2024-04-13 13:36:16 +00:00
from music_kraken.objects import Song, Album, Artist, Collection, Country
2024-04-12 15:58:18 +00:00
class TestCollection(unittest.TestCase):
2024-04-13 13:36:16 +00:00
@staticmethod
def complicated_object() -> Artist:
return Artist(
2024-04-12 15:58:18 +00:00
name="artist",
2024-04-13 13:36:16 +00:00
country=Country.by_alpha_2("DE"),
2024-05-16 12:29:50 +00:00
album_list=[
2024-04-12 15:58:18 +00:00
Album(
title="album",
song_list=[
Song(
title="song",
album_list=[
Album(title="album", albumsort=123),
],
),
Song(
title="other_song",
album_list=[
Album(title="album", albumsort=423),
],
),
]
),
Album(title="album", barcode="1234567890123"),
]
)
2024-04-13 13:36:16 +00:00
def test_song_album_relation(self):
"""
Tests that
album = album.any_song.one_album
is the same object
"""
a = self.complicated_object().album_collection[0]
2024-04-12 15:58:18 +00:00
b = a.song_collection[0].album_collection[0]
c = a.song_collection[1].album_collection[0]
d = b.song_collection[0].album_collection[0]
e = d.song_collection[0].album_collection[0]
f = e.song_collection[0].album_collection[0]
g = f.song_collection[0].album_collection[0]
self.assertTrue(a.id == b.id == c.id == d.id == e.id == f.id == g.id)
self.assertTrue(a.title == b.title == c.title == d.title == e.title == f.title == g.title == "album")
self.assertTrue(a.barcode == b.barcode == c.barcode == d.barcode == e.barcode == f.barcode == g.barcode == "1234567890123")
self.assertTrue(a.albumsort == b.albumsort == c.albumsort == d.albumsort == e.albumsort == f.albumsort == g.albumsort == 123)
d.title = "new_title"
self.assertTrue(a.title == b.title == c.title == d.title == e.title == f.title == g.title == "new_title")
2024-04-13 13:36:16 +00:00
def test_album_artist_relation(self):
"""
Tests that
artist = artist.any_album.any_song.one_artist
is the same object
"""
a = self.complicated_object()
b = a.album_collection[0].artist_collection[0]
c = b.album_collection[0].artist_collection[0]
d = c.album_collection[0].artist_collection[0]
2024-04-13 13:36:16 +00:00
self.assertTrue(a.id == b.id == c.id == d.id)
self.assertTrue(a.name == b.name == c.name == d.name == "artist")
self.assertTrue(a.country == b.country == c.country == d.country)
2024-04-19 15:45:49 +00:00
def test_artist_artist_relation(self):
artist = Artist(
name="artist",
2024-05-16 12:29:50 +00:00
album_list=[
2024-04-19 15:45:49 +00:00
Album(
title="album",
song_list=[
Song(title="song"),
],
artist_list=[
Artist(name="artist"),
]
)
]
)
self.assertTrue(artist.id == artist.album_collection[0].song_collection[0].artist_collection[0].id)
2024-04-19 15:45:49 +00:00
def test_artist_collection_sync(self):
album_1 = Album(
title="album",
song_list=[
2024-05-16 12:29:50 +00:00
Song(title="song", artist_list=[Artist(name="artist")]),
2024-04-19 15:45:49 +00:00
],
artist_list=[
Artist(name="artist"),
]
)
album_2 = Album(
title="album",
song_list=[
2024-05-16 12:29:50 +00:00
Song(title="song", artist_list=[Artist(name="artist")]),
2024-04-19 15:45:49 +00:00
],
artist_list=[
Artist(name="artist"),
]
)
album_1.merge(album_2)
self.assertTrue(id(album_1.artist_collection) == id(album_1.artist_collection) == id(album_1.song_collection[0].artist_collection) == id(album_1.song_collection[0].artist_collection))
2024-04-19 15:45:49 +00:00
2024-04-13 13:36:16 +00:00
def test_song_artist_relations(self):
a = self.complicated_object()
b = a.album_collection[0].song_collection[0].artist_collection[0]
c = b.album_collection[0].song_collection[0].artist_collection[0]
d = c.album_collection[0].song_collection[0].artist_collection[0]
2024-04-13 13:36:16 +00:00
self.assertTrue(a.id == b.id == c.id == d.id)
self.assertTrue(a.name == b.name == c.name == d.name == "artist")
self.assertTrue(a.country == b.country == c.country == d.country)
2024-04-12 15:58:18 +00:00
if __name__ == "__main__":
unittest.main()