Skip to content

Commit

Permalink
fix missing header detection for the non-strict case
Browse files Browse the repository at this point in the history
  • Loading branch information
woodyza committed Jan 26, 2024
1 parent 89d7f37 commit dd7b873
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion responses/matchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def _compare_with_regex(request_headers: Union[Mapping[Any, Any], Any]) -> bool:
else:
if not v == request_headers[k]:
return False
elif strict_match:
else:
return False

return True
Expand Down
23 changes: 22 additions & 1 deletion responses/tests/test_matchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ def run():
assert_reset()


def test_request_matches_headers_no_match():
def test_request_header_value_mismatch_raises():
@responses.activate
def run():
url = "http://example.com/"
Expand All @@ -650,6 +650,27 @@ def run():
assert_reset()


def test_request_headers_missing_raises():
@responses.activate
def run():
url = "http://example.com/"
responses.add(
method=responses.GET,
url=url,
json={"success": True},
match=[matchers.header_matcher({"x-custom-header": "foo"})],
)

with pytest.raises(ConnectionError) as excinfo:
requests.get(url, headers={})

msg = str(excinfo.value)
assert ("Headers do not match: {} doesn't match {x-custom-header: foo}") in msg

run()
assert_reset()


def test_request_matches_headers_strict_match():
@responses.activate
def run():
Expand Down

0 comments on commit dd7b873

Please sign in to comment.