aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcodl <[email protected]>2019-04-15 15:48:45 +0200
committercodl <[email protected]>2019-04-15 15:52:30 +0200
commita815c10f9bb390aadc88fe0f35ee141ba96cfb45 (patch)
treea41c459345865e77a06ce8bfa70144c8551243fd
parenteca31ea732d1c2c8f0491a138b2940e828a45973 (diff)
downloadmastodon.py-a815c10f9bb390aadc88fe0f35ee141ba96cfb45.tar.gz
add test for link headers. this adds requests-mock as a dependency
-rw-r--r--Pipfile1
-rw-r--r--Pipfile.lock8
-rw-r--r--tests/test_pagination.py20
3 files changed, 29 insertions, 0 deletions
diff --git a/Pipfile b/Pipfile
index 365589a..d0d3ce5 100644
--- a/Pipfile
+++ b/Pipfile
@@ -13,3 +13,4 @@ pytest-cov = "*"
13vcrpy = "*" 13vcrpy = "*"
14pytest-vcr = "<1" 14pytest-vcr = "<1"
15pytest-mock = "*" 15pytest-mock = "*"
16requests-mock = "*"
diff --git a/Pipfile.lock b/Pipfile.lock
index d1939fc..db1193b 100644
--- a/Pipfile.lock
+++ b/Pipfile.lock
@@ -313,6 +313,14 @@
313 ], 313 ],
314 "version": "==2.20.1" 314 "version": "==2.20.1"
315 }, 315 },
316 "requests-mock": {
317 "hashes": [
318 "sha256:7a5fa99db5e3a2a961b6f20ed40ee6baeff73503cf0a553cc4d679409e6170fb",
319 "sha256:8ca0628dc66d3f212878932fd741b02aa197ad53fd2228164800a169a4a826af"
320 ],
321 "index": "pypi",
322 "version": "==1.5.2"
323 },
316 "six": { 324 "six": {
317 "hashes": [ 325 "hashes": [
318 "sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9", 326 "sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9",
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 @@
1import pytest 1import pytest
2from contextlib import contextmanager 2from contextlib import contextmanager
3try:
4 from mock import MagicMock
5except ImportError:
6 from unittest.mock import MagicMock
7import requests_mock
3 8
4UNLIKELY_HASHTAG = "fgiztsshwiaqqiztpmmjbtvmescsculuvmgjgopwoeidbcrixp" 9UNLIKELY_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
53def 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
Powered by cgit v1.2.3 (git 2.41.0)