예제 #1
0
async def test_start_stop(client):
    url = "https://foo.bar/"
    request = respx.add("GET", url, status_code=202)
    assert respx.stats.call_count == 0

    try:
        respx.start()
        response = await client.get(url)
        assert request.called is True
        assert response.status_code == 202
        assert response.text == ""
        assert respx.stats.call_count == 1

        respx.stop(clear=False, reset=False)
        assert len(respx.mock.patterns) == 1
        assert respx.stats.call_count == 1
        assert request.called is True

        respx.reset()
        assert len(respx.mock.patterns) == 1
        assert respx.stats.call_count == 0
        assert request.called is False

        respx.clear()
        assert len(respx.mock.patterns) == 0

    except Exception:  # pragma: nocover
        respx.stop()  # Cleanup global state on error, to not affect other tests
        raise
예제 #2
0
async def test_start_stop(client):
    url = "https://start.stop/"
    request = respx.get(url) % 202

    try:
        respx.start()
        response = await client.get(url)
        assert request.called is True
        assert response.status_code == 202
        assert response.text == ""
        assert respx.calls.call_count == 1

        respx.stop(clear=False, reset=False)
        assert len(respx.routes) == 1
        assert respx.calls.call_count == 1
        assert request.called is True

        respx.reset()
        assert len(respx.routes) == 1
        assert respx.calls.call_count == 0
        assert request.called is False

        respx.clear()
        assert len(respx.routes) == 0

    finally:  # pragma: nocover
        respx.stop(
        )  # Cleanup global state on error, to not affect other tests
예제 #3
0
 def tearDown(self):
     super().tearDown()
     respx.stop()