Skip to content

Commit

Permalink
Add test to reproduce #104
Browse files Browse the repository at this point in the history
  • Loading branch information
sarayourfriend committed Dec 31, 2023
1 parent fac40e9 commit 50c652a
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/unit/mock_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import pytest
import json
import re

import pook
from pook.mock import Mock
from pook.request import Request
from urllib.request import urlopen
from urllib.parse import urlencode


@pytest.fixture
Expand All @@ -17,6 +23,47 @@ def test_mock_url(mock):
assert str(matcher(mock)) == "http://google.es"


@pytest.mark.parametrize(
("param_kwargs", "query_string"),
(
pytest.param({"params": {"x": "1"}}, "?x=1", id="params"),
pytest.param(
{"param": ("y", "pook")},
"?y=pook",
marks=pytest.mark.xfail(
condition=True,
reason="Constructor does not correctly handle multi-argument methods from kwargs",
),
id="param",
),
pytest.param(
{"param_exists": "z"},
# This complexity is needed until https://github.com/h2non/pook/issues/110
# is resolved
f'?{urlencode({"z": re.compile("(.*)")})}',
id="param_exists",
),
),
)
def test_constructor(param_kwargs, query_string):
# Should not raise
mock = Mock(
url="https://httpbin.org/404",
reply_status=200,
response_json={"hello": "from pook"},
**param_kwargs,
)

expected_url = f"https://httpbin.org/404{query_string}"
assert mock._request.rawurl == expected_url

with pook.use():
pook.engine().add_mock(mock)
res = urlopen(expected_url)
assert res.status == 200
assert json.loads(res.read()) == {"hello": "from pook"}


@pytest.mark.parametrize(
"url, params, req, expected",
[
Expand Down

0 comments on commit 50c652a

Please sign in to comment.