Beispiel #1
0
def test_tornado_load(mock_httpclient_fetch):
    cache = stub(get=lambda url: None, add=lambda url, content: None)
    response = HTTPResponse(HTTPRequest("http://tests.python-zeep.org/test.xml"), 200)
    response.buffer = True
    response._body = "x"
    mock_httpclient_fetch.return_value = response

    transport = TornadoAsyncTransport(cache=cache)

    result = transport.load("http://tests.python-zeep.org/test.xml")

    assert result == "x"
    def test_load(self, mock_httpclient_fetch):
        cache = stub(get=lambda url: None, add=lambda url, content: None)
        response = HTTPResponse(HTTPRequest('http://tests.python-zeep.org/test.xml'), 200)
        response.buffer = True
        response._body = 'x'
        mock_httpclient_fetch.return_value = response

        transport = TornadoAsyncTransport(cache=cache)

        result = transport.load('http://tests.python-zeep.org/test.xml')

        assert result == 'x'
Beispiel #3
0
    def fetch_mock(self, request):
        """Fetch a mocked request

        Arguments:
            request (HTTPRequest): the request to fetch
        Returns:
            HTTPResponse constructed from the info stored in the mocks
        Raises:
            HTTPError if the cached response has status >= 400
        """
        mock_data = self.mocks[self.url_key(request.url)]
        code = mock_data.get('code', 200)
        headers = HTTPHeaders(mock_data.get('headers', {}))
        response = HTTPResponse(request, code, headers=headers)
        response.buffer = io.BytesIO(mock_data['body'].encode('utf8'))
        if code >= 400:
            raise HTTPError(mock_data['code'], response=response)

        return response
Beispiel #4
0
    def fetch_mock(self, request, raise_error=True):
        """Fetch a mocked request

        Arguments:
            request (HTTPRequest): the request to fetch
        Returns:
            HTTPResponse constructed from the info stored in the mocks
        Raises:
            HTTPError if the cached response has status >= 400
        """
        mock_data = self.mocks[self.url_key(request.url)]
        code = mock_data.get("code", 200)
        headers = HTTPHeaders(mock_data.get("headers", {}))
        response = HTTPResponse(request, code, headers=headers)
        response.buffer = io.BytesIO(mock_data["body"].encode("utf8"))
        if code >= 400 and raise_error:
            raise HTTPError(mock_data["code"], response=response)

        return response
    def test_post(self, mock_httpclient_fetch):
        cache = stub(get=lambda url: None, add=lambda url, content: None)

        response = HTTPResponse(HTTPRequest('http://tests.python-zeep.org/test.xml'), 200)
        response.buffer = True
        response._body = 'x'
        http_fetch_future = Future()
        http_fetch_future.set_result(response)
        mock_httpclient_fetch.return_value = http_fetch_future

        transport = TornadoAsyncTransport(cache=cache)

        envelope = etree.Element('Envelope')

        result = yield transport.post_xml(
            'http://tests.python-zeep.org/test.xml',
            envelope=envelope,
            headers={})

        assert result.content == 'x'
        assert result.status_code == 200
Beispiel #6
0
    def test_post(self, mock_httpclient_fetch):
        cache = stub(get=lambda url: None, add=lambda url, content: None)

        response = HTTPResponse(
            HTTPRequest("http://tests.python-zeep.org/test.xml"), 200
        )
        response.buffer = True
        response._body = "x"
        http_fetch_future = Future()
        http_fetch_future.set_result(response)
        mock_httpclient_fetch.return_value = http_fetch_future

        transport = TornadoAsyncTransport(cache=cache)

        envelope = etree.Element("Envelope")

        result = yield transport.post_xml(
            "http://tests.python-zeep.org/test.xml", envelope=envelope, headers={}
        )

        assert result.content == "x"
        assert result.status_code == 200
Beispiel #7
0
async def mocked_requests(*args, **kwargs):
    response = HTTPResponse(HTTPRequest("kek"), 200)
    response._body = {"status": "success"}
    response.buffer = "trash"
    return response