1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
from models.album import Album
def test_instance(database):
album = Album(database, 1)
assert album.id == 1
assert album.name == "Album 1"
assert album.date == "1999-02-04"
def test_artists(database):
album = Album(database, 1)
assert len(album.artists) == 1
assert album.artists[0].name == "Artist 2"
def test_tracks(database):
album = Album(database, 1)
assert len(album.tracks) == 2
assert album.tracks[0].name == "Album track 1"
assert album.tracks[0].tracknumber == 1
assert album.tracks[0].filename == "album/1.mp3"
assert album.tracks[1].name == "Album track 2"
assert album.tracks[1].tracknumber == 2
assert album.tracks[1].grouping == "swing"
assert album.tracks[1].filename == "album/2.mp3"
def test_delete(database):
with database.conn:
cursor = database.cursor()
cursor.execute("INSERT INTO album (name, date) VALUES(?,?)",
("Test album", "2016-02-05"))
album_id = cursor.lastrowid
cursor.close()
album = Album(database, album_id)
assert album.delete()
test_album = Album(database, album_id)
assert not hasattr(test_album, "name")
def test_search(database):
search_payload = {"name": {"data": "Album 1", "operator": "="}}
album_results = Album.search(database, **search_payload)
assert len(album_results) > 0
invalid_search_payload = {"name": {"data": "This album does not exist",
"operator": "="}}
no_album_results = Album.search(database, **invalid_search_payload)
assert len(no_album_results) == 0
def test_all(database):
album_results = Album.all(database)
assert len(album_results) > 0
|