Skip to content

Commit

Permalink
Test all args of request by http backend suggest call
Browse files Browse the repository at this point in the history
  • Loading branch information
juhoinkinen committed Jun 13, 2024
1 parent 9af6edb commit 011e602
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions tests/test_backend_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,8 @@ def test_http_suggest_with_results(app_project):
assert hits[0].score == 1.0


def test_http_suggest_limit(app_project):
with unittest.mock.patch("requests.post") as mock_request:
# create a mock response whose .json() method returns the list that we
# define here
mock_response = unittest.mock.Mock()
mock_response.json.return_value = [
{"uri": "https://example.org/dummy", "label": "dummy", "score": 1.0}
]
mock_request.return_value = mock_response

def test_http_suggest_post_args(app_project):
with unittest.mock.patch("requests.post"):
http_type = annif.backend.get_backend("http")
http = http_type(
backend_id="http",
Expand All @@ -104,14 +96,13 @@ def test_http_suggest_limit(app_project):
},
project=app_project,
)
result = http.suggest(["this is some text"])[0]
assert len(result) == 1
hits = list(result)
assert hits[0].subject_id is not None
assert hits[0].subject_id == app_project.subjects.by_uri(
"https://example.org/dummy"
)
assert hits[0].score == 1.0
http.suggest(["this is some text"])

assert requests.post.call_args.args == ("https://api.example.org/analyze",)
assert "text" in requests.post.call_args.kwargs["data"]
assert requests.post.call_args.kwargs["data"]["text"] == "this is some text"
assert "project" in requests.post.call_args.kwargs["data"]
assert requests.post.call_args.kwargs["data"]["project"] == "dummy"
assert "limit" in requests.post.call_args.kwargs["data"]
assert requests.post.call_args.kwargs["data"]["limit"] == "42"

Expand Down

0 comments on commit 011e602

Please sign in to comment.