File: test_artist.py

package info (click to toggle)
pylast 2.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 296 kB
  • sloc: python: 2,564; makefile: 10
file content (296 lines) | stat: -rwxr-xr-x 8,172 bytes parent folder | download
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
#!/usr/bin/env python
"""
Integration (not unit) tests for pylast.py
"""
import unittest

import pylast

from .test_pylast import TestPyLastWithLastFm


class TestPyLastArtist(TestPyLastWithLastFm):
    def test_repr(self):
        # Arrange
        artist = pylast.Artist("Test Artist", self.network)

        # Act
        representation = repr(artist)

        # Assert
        self.assertTrue(representation.startswith("pylast.Artist('Test Artist',"))

    def test_artist_is_hashable(self):
        # Arrange
        test_artist = self.network.get_artist("Test Artist")
        artist = test_artist.get_similar(limit=2)[0].item
        self.assertIsInstance(artist, pylast.Artist)

        # Act/Assert
        self.helper_is_thing_hashable(artist)

    def test_bio_published_date(self):
        # Arrange
        artist = pylast.Artist("Test Artist", self.network)

        # Act
        bio = artist.get_bio_published_date()

        # Assert
        self.assertIsNotNone(bio)
        self.assertGreaterEqual(len(bio), 1)

    def test_bio_content(self):
        # Arrange
        artist = pylast.Artist("Test Artist", self.network)

        # Act
        bio = artist.get_bio_content(language="en")

        # Assert
        self.assertIsNotNone(bio)
        self.assertGreaterEqual(len(bio), 1)

    def test_bio_summary(self):
        # Arrange
        artist = pylast.Artist("Test Artist", self.network)

        # Act
        bio = artist.get_bio_summary(language="en")

        # Assert
        self.assertIsNotNone(bio)
        self.assertGreaterEqual(len(bio), 1)

    def test_artist_top_tracks(self):
        # Arrange
        # Pick an artist with plenty of plays
        artist = self.network.get_top_artists(limit=1)[0].item

        # Act
        things = artist.get_top_tracks(limit=2)

        # Assert
        self.helper_two_different_things_in_top_list(things, pylast.Track)

    def test_artist_top_albums(self):
        # Arrange
        # Pick an artist with plenty of plays
        artist = self.network.get_top_artists(limit=1)[0].item

        # Act
        things = artist.get_top_albums(limit=2)

        # Assert
        self.helper_two_different_things_in_top_list(things, pylast.Album)

    def test_artist_top_albums_limit_1(self):
        # Arrange
        limit = 1
        # Pick an artist with plenty of plays
        artist = self.network.get_top_artists(limit=1)[0].item

        # Act
        things = artist.get_top_albums(limit=limit)

        # Assert
        self.assertEqual(len(things), 1)

    def test_artist_top_albums_limit_50(self):
        # Arrange
        limit = 50
        # Pick an artist with plenty of plays
        artist = self.network.get_top_artists(limit=1)[0].item

        # Act
        things = artist.get_top_albums(limit=limit)

        # Assert
        self.assertEqual(len(things), 50)

    def test_artist_top_albums_limit_100(self):
        # Arrange
        limit = 100
        # Pick an artist with plenty of plays
        artist = self.network.get_top_artists(limit=1)[0].item

        # Act
        things = artist.get_top_albums(limit=limit)

        # Assert
        self.assertEqual(len(things), 100)

    def test_artist_listener_count(self):
        # Arrange
        artist = self.network.get_artist("Test Artist")

        # Act
        count = artist.get_listener_count()

        # Assert
        self.assertIsInstance(count, int)
        self.assertGreater(count, 0)

    def test_tag_artist(self):
        # Arrange
        artist = self.network.get_artist("Test Artist")
        # artist.clear_tags()

        # Act
        artist.add_tag("testing")

        # Assert
        tags = artist.get_tags()
        self.assertGreater(len(tags), 0)
        found = False
        for tag in tags:
            if tag.name == "testing":
                found = True
                break
        self.assertTrue(found)

    def test_remove_tag_of_type_text(self):
        # Arrange
        tag = "testing"  # text
        artist = self.network.get_artist("Test Artist")
        artist.add_tag(tag)

        # Act
        artist.remove_tag(tag)

        # Assert
        tags = artist.get_tags()
        found = False
        for tag in tags:
            if tag.name == "testing":
                found = True
                break
        self.assertFalse(found)

    def test_remove_tag_of_type_tag(self):
        # Arrange
        tag = pylast.Tag("testing", self.network)  # Tag
        artist = self.network.get_artist("Test Artist")
        artist.add_tag(tag)

        # Act
        artist.remove_tag(tag)

        # Assert
        tags = artist.get_tags()
        found = False
        for tag in tags:
            if tag.name == "testing":
                found = True
                break
        self.assertFalse(found)

    def test_remove_tags(self):
        # Arrange
        tags = ["removetag1", "removetag2"]
        artist = self.network.get_artist("Test Artist")
        artist.add_tags(tags)
        artist.add_tags("1more")
        tags_before = artist.get_tags()

        # Act
        artist.remove_tags(tags)

        # Assert
        tags_after = artist.get_tags()
        self.assertEqual(len(tags_after), len(tags_before) - 2)
        found1, found2 = False, False
        for tag in tags_after:
            if tag.name == "removetag1":
                found1 = True
            elif tag.name == "removetag2":
                found2 = True
        self.assertFalse(found1)
        self.assertFalse(found2)

    def test_set_tags(self):
        # Arrange
        tags = ["sometag1", "sometag2"]
        artist = self.network.get_artist("Test Artist 2")
        artist.add_tags(tags)
        tags_before = artist.get_tags()
        new_tags = ["settag1", "settag2"]

        # Act
        artist.set_tags(new_tags)

        # Assert
        tags_after = artist.get_tags()
        self.assertNotEqual(tags_before, tags_after)
        self.assertEqual(len(tags_after), 2)
        found1, found2 = False, False
        for tag in tags_after:
            if tag.name == "settag1":
                found1 = True
            elif tag.name == "settag2":
                found2 = True
        self.assertTrue(found1)
        self.assertTrue(found2)

    def test_artists(self):
        # Arrange
        artist1 = self.network.get_artist("Radiohead")
        artist2 = self.network.get_artist("Portishead")

        # Act
        url = artist1.get_url()
        mbid = artist1.get_mbid()
        image = artist1.get_cover_image()
        playcount = artist1.get_playcount()
        streamable = artist1.is_streamable()
        name = artist1.get_name(properly_capitalized=False)
        name_cap = artist1.get_name(properly_capitalized=True)

        # Assert
        self.assertIn("https", image)
        self.assertGreater(playcount, 1)
        self.assertNotEqual(artist1, artist2)
        self.assertEqual(name.lower(), name_cap.lower())
        self.assertEqual(url, "https://www.last.fm/music/radiohead")
        self.assertEqual(mbid, "a74b1b7f-71a5-4011-9441-d0b5e4122711")
        self.assertIsInstance(streamable, bool)

    def test_artist_eq_none_is_false(self):
        # Arrange
        artist1 = None
        artist2 = pylast.Artist("Test Artist", self.network)

        # Act / Assert
        self.assertNotEqual(artist1, artist2)

    def test_artist_ne_none_is_true(self):
        # Arrange
        artist1 = None
        artist2 = pylast.Artist("Test Artist", self.network)

        # Act / Assert
        self.assertNotEqual(artist1, artist2)

    def test_artist_get_correction(self):
        # Arrange
        artist = pylast.Artist("guns and roses", self.network)

        # Act
        corrected_artist_name = artist.get_correction()

        # Assert
        self.assertEqual(corrected_artist_name, "Guns N' Roses")

    def test_get_userplaycount(self):
        # Arrange
        artist = pylast.Artist("John Lennon", self.network, username=self.username)

        # Act
        playcount = artist.get_userplaycount()

        # Assert
        self.assertGreaterEqual(playcount, 0)


if __name__ == "__main__":
    unittest.main(failfast=True)