add test for link headers. this adds requests-mock as a dependency

This commit is contained in:
codl 2019-04-15 15:48:45 +02:00
pare eca31ea732
commit a815c10f9b
No se encontró ninguna clave conocida en la base de datos para esta firma
ID de clave GPG: 6CD7C8891ED1233A
S'han modificat 3 arxius amb 29 adicions i 0 eliminacions

Veure arxiu

@ -13,3 +13,4 @@ pytest-cov = "*"
vcrpy = "*" vcrpy = "*"
pytest-vcr = "<1" pytest-vcr = "<1"
pytest-mock = "*" pytest-mock = "*"
requests-mock = "*"

8
Pipfile.lock generado
Veure arxiu

@ -313,6 +313,14 @@
], ],
"version": "==2.20.1" "version": "==2.20.1"
}, },
"requests-mock": {
"hashes": [
"sha256:7a5fa99db5e3a2a961b6f20ed40ee6baeff73503cf0a553cc4d679409e6170fb",
"sha256:8ca0628dc66d3f212878932fd741b02aa197ad53fd2228164800a169a4a826af"
],
"index": "pypi",
"version": "==1.5.2"
},
"six": { "six": {
"hashes": [ "hashes": [
"sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9", "sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9",

Veure arxiu

@ -1,5 +1,10 @@
import pytest import pytest
from contextlib import contextmanager from contextlib import contextmanager
try:
from mock import MagicMock
except ImportError:
from unittest.mock import MagicMock
import requests_mock
UNLIKELY_HASHTAG = "fgiztsshwiaqqiztpmmjbtvmescsculuvmgjgopwoeidbcrixp" UNLIKELY_HASHTAG = "fgiztsshwiaqqiztpmmjbtvmescsculuvmgjgopwoeidbcrixp"
@ -44,3 +49,18 @@ def test_fetch_remaining(api):
hashtag_remaining = api.fetch_remaining(hashtag) hashtag_remaining = api.fetch_remaining(hashtag)
assert hashtag_remaining assert hashtag_remaining
assert len(hashtag_remaining) >= 30 assert len(hashtag_remaining) >= 30
def test_link_headers(api):
rmock = requests_mock.Adapter()
api.session.mount(api.api_base_url, rmock)
_id='abc1234'
rmock.register_uri('GET', requests_mock.ANY, json=[{"foo": "bar"}], headers={"link":"""
<{base}/api/v1/timelines/tag/{tag}?max_id={_id}>; rel="next", <{base}/api/v1/timelines/tag/{tag}?since_id={_id}>; rel="prev"
""".format(base=api.api_base_url, tag=UNLIKELY_HASHTAG, _id=_id).strip()
})
resp = api.timeline_hashtag(UNLIKELY_HASHTAG)
assert resp[0]._pagination_next['max_id'] == _id
assert resp[0]._pagination_prev['since_id'] == _id