Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aguilerapy committed Jun 23, 2020
1 parent c313156 commit 15543ed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 4 additions & 2 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
from kingfisher_scrapy.base_spider import BaseSpider


def response_fixture(**kwargs):
request = Request('http://example.com', meta={'file_name': 'test', 'depth': 0})
def response_fixture(meta=None, **kwargs):
if meta is None:
meta = {'file_name': 'test'}
request = Request('http://example.com', meta=meta)
if 'status' not in kwargs:
kwargs['status'] = 200
if 'body' not in kwargs:
Expand Down
8 changes: 7 additions & 1 deletion tests/test_links_spider.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ def test_parse_200():
def test_next_link_not_found():
spider = spider_with_crawler(spider_class=LinksSpider)
spider.next_page_formatter = lambda url: 'next.json'
body = '{"links": {"next": ""}}'

with pytest.raises(KingfisherScrapyError) as e:
assert spider.next_link(response_fixture(body='{"links": {"next": ""}}'))
meta = {'file_name': 'test', 'depth': 0}
assert spider.next_link(response_fixture(meta=meta, body=body))
assert str(e.value) == 'next link not found on the first page: http://example.com'

meta = {'file_name': 'test', 'depth': 10}
response = spider.next_link(response_fixture(meta=meta, body=body))
assert response is None

0 comments on commit 15543ed

Please sign in to comment.