Skip to content

Commit

Permalink
feat: add User.add_artist method
Browse files Browse the repository at this point in the history
  • Loading branch information
browniebroke committed May 11, 2023
1 parent ccc7b76 commit 3ad512b
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/deezer/resources/user.py
Expand Up @@ -111,6 +111,15 @@ def get_artists(self, **kwargs) -> PaginatedList[Artist]:
"""
return self.get_paginated_list("artists", **kwargs)

def add_artist(self, artist: Artist | int):
"""
Add an artist to user's favorite artists.
:param artist: an :class:`~deezer.Artist` instance or its ID
:returns: a boolean that tells if the operation was successful
"""
return self.post_relation("artists", artist_id=get_id(artist))

def get_followers(self, **kwargs) -> PaginatedList[User]:
"""
Get user's followers.
Expand Down
56 changes: 56 additions & 0 deletions tests/resources/cassettes/TestUser.test_add_artist_id.yaml
@@ -0,0 +1,56 @@
interactions:
- request:
body: null
headers:
Accept:
- "*/*"
Accept-Encoding:
- identity
Connection:
- keep-alive
Content-Length:
- "0"
User-Agent:
- python-requests/2.30.0
method: POST
uri: https://api.deezer.com/user/me/artists?access_token=dummy&artist_id=27
response:
body:
string: "true"
headers:
Access-Control-Allow-Credentials:
- "true"
Access-Control-Allow-Headers:
- X-Requested-With, Content-Type, Authorization, Origin, Accept, Accept-Encoding
Access-Control-Allow-Methods:
- POST, GET, OPTIONS, DELETE, PUT
Access-Control-Expose-Headers:
- Location
Access-Control-Max-Age:
- "86400"
Cache-Control:
- no-store, no-cache, must-revalidate
Connection:
- keep-alive
Content-Length:
- "4"
Content-Type:
- application/json; charset=utf-8
Expires:
- Thu, 19 Nov 1981 08:52:00 GMT
Pragma:
- no-cache
Server:
- Apache
Strict-Transport-Security:
- max-age=31536000; includeSubDomains
X-Content-Type-Options:
- nosniff
X-Host:
- blm-web-200
x-org:
- FR
status:
code: 200
message: OK
version: 1
56 changes: 56 additions & 0 deletions tests/resources/cassettes/TestUser.test_add_artist_obj.yaml
@@ -0,0 +1,56 @@
interactions:
- request:
body: null
headers:
Accept:
- "*/*"
Accept-Encoding:
- identity
Connection:
- keep-alive
Content-Length:
- "0"
User-Agent:
- python-requests/2.30.0
method: POST
uri: https://api.deezer.com/user/me/artists?access_token=dummy&artist_id=27
response:
body:
string: "true"
headers:
Access-Control-Allow-Credentials:
- "true"
Access-Control-Allow-Headers:
- X-Requested-With, Content-Type, Authorization, Origin, Accept, Accept-Encoding
Access-Control-Allow-Methods:
- POST, GET, OPTIONS, DELETE, PUT
Access-Control-Expose-Headers:
- Location
Access-Control-Max-Age:
- "86400"
Cache-Control:
- no-store, no-cache, must-revalidate
Connection:
- keep-alive
Content-Length:
- "4"
Content-Type:
- application/json; charset=utf-8
Expires:
- Thu, 19 Nov 1981 08:52:00 GMT
Pragma:
- no-cache
Server:
- Apache
Strict-Transport-Security:
- max-age=31536000; includeSubDomains
X-Content-Type-Options:
- nosniff
X-Host:
- blm-web-174
x-org:
- FR
status:
code: 200
message: OK
version: 1
10 changes: 10 additions & 0 deletions tests/resources/test_user.py
Expand Up @@ -101,3 +101,13 @@ def test_remove_track_obj(self, current_user: deezer.User):
json={"id": 3135556, "type": "track"},
)
assert current_user.remove_track(track) is True

def test_add_artist_id(self, current_user: deezer.User):
assert current_user.add_artist(27) is True

def test_add_artist_obj(self, current_user: deezer.User):
artist = deezer.Artist(
current_user.client,
json={"id": 27, "type": "artist"},
)
assert current_user.add_artist(artist) is True

0 comments on commit 3ad512b

Please sign in to comment.