-
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.
- Loading branch information
Showing
4 changed files
with
71 additions
and
6 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,59 @@ | ||
import pathlib | ||
|
||
import pytest | ||
import requests_mock | ||
|
||
from eas.api.tiktok import InvalidURL, NotFoundError, get_comments | ||
|
||
RESPONSES_PATH = pathlib.Path(__file__, "..", "data").resolve() | ||
SUCCESS_RESPONSE = RESPONSES_PATH.joinpath("lamatok-success-response.json").read_text() | ||
|
||
|
||
@pytest.fixture | ||
def requestsm(): | ||
with requests_mock.Mocker() as m: | ||
yield m | ||
|
||
|
||
def test_success_response(requestsm): | ||
url = "https://www.tiktok.com/@fanmallorcashopping/video/7385245034506964257" | ||
requestsm.get( | ||
"https://api.lamatok.com/v1/media/comments/by/id", text=SUCCESS_RESPONSE | ||
) | ||
comments = get_comments(url) | ||
assert len(comments) == 20 | ||
|
||
|
||
def test_post_no_comments(requestsm): | ||
url = "https://www.tiktok.com/@echaloasuerte/video/7382573284749102368" | ||
requestsm.get( | ||
"https://api.lamatok.com/v1/media/comments/by/id", | ||
status_code=404, | ||
text='{"detail":"Comments (or media) Not found","exc_type":"CommentsNotFoundError","tt_status_code":0}', | ||
) | ||
with pytest.raises(NotFoundError): | ||
get_comments(url) | ||
|
||
|
||
def test_fail_on_fake_url(requestsm): | ||
url = "https://www.tiktok.com/@echaloasuerte/video/7382573284749102369" | ||
requestsm.get( | ||
"https://api.lamatok.com/v1/media/comments/by/id", | ||
status_code=404, | ||
text='{"detail":"Comments (or media) Not found","exc_type":"CommentsNotFoundError","tt_status_code":0}', | ||
) | ||
with pytest.raises(NotFoundError): | ||
get_comments(url) | ||
|
||
|
||
def test_min_mentions_filter(requestsm): | ||
url = "https://www.tiktok.com/@fanmallorcashopping/video/7385245034506964257" | ||
requestsm.get( | ||
"https://api.lamatok.com/v1/media/comments/by/id", text=SUCCESS_RESPONSE | ||
) | ||
comments = get_comments(url, min_mentions=1) | ||
assert len(comments) == 17 | ||
comments = get_comments(url, min_mentions=2) | ||
assert len(comments) == 13 | ||
comments = get_comments(url, min_mentions=3) | ||
assert len(comments) == 0 |
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