diff --git a/responses/tests/test_responses.py b/responses/tests/test_responses.py index d2bc70c5..7d3af31e 100644 --- a/responses/tests/test_responses.py +++ b/responses/tests/test_responses.py @@ -1,5 +1,4 @@ import inspect -import json import os import re import warnings @@ -2036,83 +2035,31 @@ def run(): assert_reset() -def test_response_and_requests_mock_calls_are_equal(): +def test_response_calls_and_registry_calls_are_equal(): @responses.activate def run(): - rsp = responses.add(responses.GET, "http://www.example.com") + rsp1 = responses.add(responses.GET, "http://www.example.com") rsp2 = responses.add(responses.GET, "http://www.example.com/1") + rsp3 = responses.add( + responses.GET, "http://www.example.com/2" + ) # won't be requested requests.get("http://www.example.com") requests.get("http://www.example.com/1") - - assert len(responses.calls) == 2 - assert rsp.call_count == 1 - assert rsp.calls[0] is responses.calls[0] - assert rsp2.call_count == 1 - assert rsp2.calls[0] is responses.calls[1] - - run() - assert_reset() - - -def test_response_call_request(): - @responses.activate - def run(): - rsp1 = responses.add(responses.GET, "http://www.example.com") - rsp2 = responses.add( - responses.PUT, "http://www.foo.bar/42/", json={"id": 42, "name": "Bazz"} - ) - request_payload = {"name": "Bazz"} - requests.get("http://www.example.com") - requests.get("http://www.example.com?hello=world") - requests.put( - "http://www.foo.bar/42/", - json=request_payload, - ) - - assert rsp1.call_count == 2 - rsp1_request1 = rsp1.calls[0].request - assert rsp1_request1.url == "http://www.example.com/" - assert rsp1_request1.method == "GET" - rsp1_request2 = rsp1.calls[1].request - assert rsp1_request2.url == "http://www.example.com/?hello=world" - assert rsp1_request2.method == "GET" - assert rsp2.call_count == 1 - rsp2_request1 = rsp2.calls[0].request - assert rsp2_request1.url == "http://www.foo.bar/42/" - assert rsp2_request1.method == "PUT" - assert json.loads(rsp2_request1.body) == request_payload - - run() - assert_reset() - - -def test_response_call_response(): - @responses.activate - def run(): - rsp1 = responses.add(responses.GET, "http://www.example.com", body=b"test") - rsp2 = responses.add( - responses.POST, - "http://www.foo.bar/42/", - json={"id": 42, "name": "Bazz"}, - status=201, - ) - requests.get("http://www.example.com") - requests.post( - "http://www.foo.bar/42/", - json={"name": "Bazz"}, + assert len(responses.calls) == len(rsp1.calls) + len(rsp2.calls) + len( + rsp3.calls ) - - assert rsp1.call_count == 1 - rsp1_response = rsp1.calls[0].response - assert rsp1_response.content == b"test" - assert rsp1_response.status_code == 200 + assert rsp1.call_count == 2 + assert len(rsp1.calls) == 2 + assert rsp1.calls[0] is responses.calls[0] + assert rsp1.calls[1] is responses.calls[2] assert rsp2.call_count == 1 - rsp2_response = rsp2.calls[0].response - assert rsp2_response.json() == {"id": 42, "name": "Bazz"} - assert rsp2_response.status_code == 201 + assert len(rsp2.calls) == 1 + assert rsp2.calls[0] is responses.calls[1] + assert rsp3.call_count == 0 + assert len(rsp3.calls) == 0 run() assert_reset()