diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_errors.py | 20 | ||||
-rw-r--r-- | tests/test_pagination.py | 20 |
2 files changed, 40 insertions, 0 deletions
diff --git a/tests/test_errors.py b/tests/test_errors.py new file mode 100644 index 0000000..7329507 --- /dev/null +++ b/tests/test_errors.py | |||
@@ -0,0 +1,20 @@ | |||
1 | import pytest | ||
2 | from mastodon.Mastodon import MastodonAPIError | ||
3 | |||
4 | try: | ||
5 | from mock import MagicMock | ||
6 | except ImportError: | ||
7 | from unittest.mock import MagicMock | ||
8 | |||
9 | def test_nonstandard_errors(api): | ||
10 | response = MagicMock() | ||
11 | response.json = MagicMock(return_value= | ||
12 | "I am a non-standard instance and this error is a plain string.") | ||
13 | response.ok = False | ||
14 | session = MagicMock() | ||
15 | session.request = MagicMock(return_value=response) | ||
16 | |||
17 | api.session = session | ||
18 | with pytest.raises(MastodonAPIError): | ||
19 | api.instance() | ||
20 | |||
diff --git a/tests/test_pagination.py b/tests/test_pagination.py index 599b2f4..d2c0bd5 100644 --- a/tests/test_pagination.py +++ b/tests/test_pagination.py | |||
@@ -1,5 +1,10 @@ | |||
1 | import pytest | 1 | import pytest |
2 | from contextlib import contextmanager | 2 | from contextlib import contextmanager |
3 | try: | ||
4 | from mock import MagicMock | ||
5 | except ImportError: | ||
6 | from unittest.mock import MagicMock | ||
7 | import requests_mock | ||
3 | 8 | ||
4 | UNLIKELY_HASHTAG = "fgiztsshwiaqqiztpmmjbtvmescsculuvmgjgopwoeidbcrixp" | 9 | UNLIKELY_HASHTAG = "fgiztsshwiaqqiztpmmjbtvmescsculuvmgjgopwoeidbcrixp" |
5 | 10 | ||
@@ -44,3 +49,18 @@ def test_fetch_remaining(api): | |||
44 | hashtag_remaining = api.fetch_remaining(hashtag) | 49 | hashtag_remaining = api.fetch_remaining(hashtag) |
45 | assert hashtag_remaining | 50 | assert hashtag_remaining |
46 | assert len(hashtag_remaining) >= 30 | 51 | assert len(hashtag_remaining) >= 30 |
52 | |||
53 | def test_link_headers(api): | ||
54 | rmock = requests_mock.Adapter() | ||
55 | api.session.mount(api.api_base_url, rmock) | ||
56 | |||
57 | _id='abc1234' | ||
58 | |||
59 | rmock.register_uri('GET', requests_mock.ANY, json=[{"foo": "bar"}], headers={"link":""" | ||
60 | <{base}/api/v1/timelines/tag/{tag}?max_id={_id}>; rel="next", <{base}/api/v1/timelines/tag/{tag}?since_id={_id}>; rel="prev" | ||
61 | """.format(base=api.api_base_url, tag=UNLIKELY_HASHTAG, _id=_id).strip() | ||
62 | }) | ||
63 | |||
64 | resp = api.timeline_hashtag(UNLIKELY_HASHTAG) | ||
65 | assert resp[0]._pagination_next['max_id'] == _id | ||
66 | assert resp[0]._pagination_prev['since_id'] == _id | ||