Skip to content

Commit

Permalink
feat: add support to rate an album
Browse files Browse the repository at this point in the history
  • Loading branch information
browniebroke committed Oct 9, 2021
1 parent 1c72557 commit c8dc771
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
9 changes: 9 additions & 0 deletions deezer/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ def iter_tracks(self, **kwargs):
"""
return self.iter_relation("tracks", **kwargs)

def rate(self, note: int) -> bool:
"""
Rate the album with the given note.
:param note: rating to give.
:return: boolean, whether the album was rated
"""
return self.client.rate_album(album_id=self.id, note=note)


class Artist(Resource):
"""
Expand Down
54 changes: 54 additions & 0 deletions tests/cassettes/TestAlbum.test_rate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- identity
Connection:
- keep-alive
Content-Length:
- '0'
User-Agent:
- python-requests/2.26.0
method: POST
uri: https://api.deezer.com/album/302127?note=3&access_token=dummy
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
P3P:
- policyref="/w3c/p3p.xml" CP="IDC DSP COR CURa ADMa OUR IND PHY ONL COM STA"
Pragma:
- no-cache
Server:
- Apache
X-Content-Type-Options:
- nosniff
X-Host:
- blm-web-59
x-org:
- FR
status:
code: 200
message: OK
version: 1
5 changes: 5 additions & 0 deletions tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ def test_as_dict(self, client):
album = client.get_album(302127)
assert album.as_dict()["id"] == 302127

def test_rate(self, client_token):
album = deezer.resources.Album(client_token, {"id": 302127})
result = album.rate(3)
assert result is True


class TestArtist:
def test_artist_attributes(self, client):
Expand Down

0 comments on commit c8dc771

Please sign in to comment.