Skip to content

Commit

Permalink
more fetcher tests
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverSherouse committed Jan 9, 2024
1 parent 1730630 commit b023ebf
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion tests/test_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,47 @@ def test_get_request_content(mocked_fetcher):
return_value=MockHTTPResponse(value=expected)
)
result = mocked_fetcher._get_response_body(url=url, params=params)
assert mocked_fetcher.session.get.called_once_with(url=url, params=params)
mocked_fetcher.session.get.assert_called_once_with(url=url, params=params)
assert json.loads(result) == expected


@pytest.mark.parametrize(
["url", "params", "response", "expected"],
(
pytest.param(
"http://foo.bar",
{"baz": "bat"},
[{"page": "1", "pages": "1"}, [{"hello": "there"}]],
fetcher.ParsedResponse(
rows=[{"hello": "there"}],
page=1,
pages=1,
last_updated=None,
),
id="No date",
),
pytest.param(
"http://foo.bar",
{"baz": "bat"},
[
{"page": "1", "pages": "1", "lastupdated": "01/02/2023"},
[{"hello": "there"}],
],
fetcher.ParsedResponse(
rows=[{"hello": "there"}],
page=1,
pages=1,
last_updated="01/02/2023",
),
id="with date",
),
),
)
def test_get_response(url, params, response, expected, mocked_fetcher):
mocked_fetcher.session.get = mock.Mock(
return_value=MockHTTPResponse(value=response)
)
got = mocked_fetcher._get_response(url=url, params=params)
mocked_fetcher.session.get.assert_called_once_with(url=url, params=params)
assert got == expected
assert mocked_fetcher.cache[(url), (("baz", "bat"),)] == json.dumps(response)

0 comments on commit b023ebf

Please sign in to comment.