コード例 #1
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
コード例 #2
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
コード例 #3
0
    def __init__(
        self,
        api: AbstractGateApi,
        api_code: str = "api_code1",
        host: Optional[str] = None,
        username: Optional[str] = None,
        password: Optional[str] = None,
    ):
        """Init object."""
        self.host: Final = host or api.host
        self.username: Final = username or api.username
        self.password: Final = password or api.password
        self.api_code: Final = api_code
        self.http_status: Final = 200
        self.cipher: Final = api.cipher
        self._info_data: dict = json.loads(
            json.dumps(self._get_info_data(),
                       indent=2,
                       cls=EnhancedJSONEncoder))

        respx.reset()
        respx.get(AbstractGateApi.API_URL_TEMPLATE %
                  self.host).mock(side_effect=self._handle_request)