-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: create tests for
Album
endpoint
* (tests): tests for `.get_album()` of `Album` * (tests): tests for `.create()` of `Album` * (tests): add fixtures for album get and post methods
- Loading branch information
1 parent
bdb7af0
commit c0af464
Showing
5 changed files
with
135 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{ | ||
"data": { | ||
"id": "{{ id }}", | ||
"title": "{{ title or 'Test album' }}", | ||
"description": "lorem ipsum dolor sit amet", | ||
"datetime": {{ datetime or range(1000000000, 1899999999) | random}}, | ||
"cover": null, | ||
"cover_edited": null, | ||
"cover_width": null, | ||
"cover_height": null, | ||
"account_url": null, | ||
"account_id": {{ account_id or range(1000000, 99999999) | random }}, | ||
"privacy": "hidden", | ||
"layout": "blog", | ||
"views": 0, | ||
"link": "https://imgur.com/a/{{ id }}", | ||
"favorite": false, | ||
"nsfw": false, | ||
"section": null, | ||
"images_count": 0, | ||
"in_gallery": false, | ||
"is_ad": false, | ||
"include_album_ads": false, | ||
"is_album": true, | ||
"deletehash": "{{ delete_hash or 'abcdefghijklmno' }}", | ||
"images": [], | ||
"ad_config": { | ||
"safeFlags": [ | ||
"not_in_gallery", | ||
"share" | ||
], | ||
"highRiskFlags": [], | ||
"unsafeFlags": [ | ||
"updated_date" | ||
], | ||
"wallUnsafeFlags": [], | ||
"showsAds": false, | ||
"showAdLevel": 1, | ||
"safe_flags": [ | ||
"not_in_gallery", | ||
"share" | ||
], | ||
"high_risk_flags": [], | ||
"unsafe_flags": [ | ||
"updated_date" | ||
], | ||
"wall_unsafe_flags": [], | ||
"show_ads": false, | ||
"show_ad_level": 1, | ||
"nsfw_score": 0 | ||
} | ||
}, | ||
"success": true, | ||
"status": 200 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"data": { | ||
"id": "{{ id }}", | ||
"deletehash": "{{ delete_hash or 'abcdefghijklmno' }}" | ||
}, | ||
"success": true, | ||
"status": 200 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from unittest.mock import patch | ||
|
||
from pyimgurapi.endpoints import Album | ||
from pyimgurapi.utils import DynamicResponseData | ||
|
||
|
||
class TestAlbum: | ||
@patch("urllib.request.urlopen") | ||
def test_get_album(self, urlopen_mock, imgur_album_get_200_response): | ||
urlopen_mock.return_value = imgur_album_get_200_response | ||
album_id = ( | ||
imgur_album_get_200_response.json().get("data", {}).get("id") | ||
) | ||
|
||
album = Album() | ||
res = album.get_album(album_id) | ||
|
||
urlopen_mock.assert_called_once() | ||
assert urlopen_mock.call_args[0][0].method == "GET" | ||
assert album_id in urlopen_mock.call_args[0][0].full_url | ||
assert isinstance(res, DynamicResponseData) | ||
assert res.data.id == album_id | ||
|
||
@patch("urllib.request.urlopen") | ||
def test_create( | ||
self, | ||
urlopen_mock, | ||
imgur_album_post_200_response, | ||
title_fixture, | ||
description_fixture, | ||
): | ||
urlopen_mock.return_value = imgur_album_post_200_response | ||
|
||
album = Album() | ||
res = album.create( | ||
title=title_fixture, description=description_fixture | ||
) | ||
|
||
urlopen_mock.assert_called_once() | ||
assert urlopen_mock.call_args[0][0].method == "POST" | ||
assert urlopen_mock.call_args[0][0].full_url.endswith("/album") | ||
assert isinstance(res, DynamicResponseData) | ||
assert title_fixture in urlopen_mock.call_args[0][0].data.decode( | ||
"utf-8" | ||
) | ||
assert description_fixture in urlopen_mock.call_args[0][0].data.decode( | ||
"utf-8" | ||
) |