Ejemplo n.º 1
0
    def test_request_raises_ClientError_if_response_status_code_is_not_2xx(
            self, transport):
        when(transport).request(
            url=m.any(),
            method=m.any(),
            headers=m.any(),
            data=m.any(),
        ).thenReturn(Response(400, {}, ''))

        client = Client(transport)

        with pytest.raises(ClientError) as exc:
            client.request('/foo')
        assert exc.value.status_code == 400
Ejemplo n.º 2
0
    def test_request_returns_None_if_response_status_code_is_404(
            self, transport):
        when(transport).request(
            url=m.any(),
            method=m.any(),
            headers=m.any(),
            data=m.any(),
        ).thenReturn(Response(404, {}, ''))

        client = Client(transport)
        assert client.request('/foo') is None
Ejemplo n.º 3
0
    def test_request_returns_None_if_body_is_empty(self, transport):
        data = {'foo': 'hello', 'bar': 123}

        when(transport).request(
            url='/foo',
            method='GET',
            headers=m.any(),
            data=m.any(),
        ).thenReturn(Response(200, {}, ''))

        client = Client(transport)
        assert client.request('/foo') is None
Ejemplo n.º 4
0
    def test_request_returns_parsed_json(self, transport):
        data = {'foo': 'hello', 'bar': 123}

        when(transport).request(
            url='/foo',
            method='GET',
            headers=m.any(),
            data=m.any(),
        ).thenReturn(Response(200, {}, json.dumps(data)))

        client = Client(transport)
        assert client.request('/foo') == data