Skip to content

Commit dd7b873

Browse files
committed
fix missing header detection for the non-strict case
1 parent 89d7f37 commit dd7b873

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

responses/matchers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ def _compare_with_regex(request_headers: Union[Mapping[Any, Any], Any]) -> bool:
421421
else:
422422
if not v == request_headers[k]:
423423
return False
424-
elif strict_match:
424+
else:
425425
return False
426426

427427
return True

responses/tests/test_matchers.py

+22-1
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ def run():
626626
assert_reset()
627627

628628

629-
def test_request_matches_headers_no_match():
629+
def test_request_header_value_mismatch_raises():
630630
@responses.activate
631631
def run():
632632
url = "http://example.com/"
@@ -650,6 +650,27 @@ def run():
650650
assert_reset()
651651

652652

653+
def test_request_headers_missing_raises():
654+
@responses.activate
655+
def run():
656+
url = "http://example.com/"
657+
responses.add(
658+
method=responses.GET,
659+
url=url,
660+
json={"success": True},
661+
match=[matchers.header_matcher({"x-custom-header": "foo"})],
662+
)
663+
664+
with pytest.raises(ConnectionError) as excinfo:
665+
requests.get(url, headers={})
666+
667+
msg = str(excinfo.value)
668+
assert ("Headers do not match: {} doesn't match {x-custom-header: foo}") in msg
669+
670+
run()
671+
assert_reset()
672+
673+
653674
def test_request_matches_headers_strict_match():
654675
@responses.activate
655676
def run():

0 commit comments

Comments
 (0)