Exemplo n.º 1
0
def get_response(request, route_context):
    final_url = base_url + request.url
    client = HTTPClient()
    print(f"Request URL: {final_url}")
    http_request = HTTPRequest(final_url,
                               method=Method.serialize(request.method),
                               body=request.body)
    print(f"HTTP request: {http_request!s}")
    try:
        http_response = client.fetch(http_request)
        responses = json.loads(http_response.buffer.getvalue().decode("utf-8"))
        print("Responses: {}".format(responses))
        return [(route_context.response_channel(r), r) for r in responses]
    except Exception as e:
        print(f"HTTP Response Error: {e}")
Exemplo n.º 2
0
    def make_request(self, request, route_context):
        def response_callback(http_response):
            if http_response.error:
                print("HTTP Response Error: {}".format(http_response.error))
            else:
                response = json.loads(
                    http_response.buffer.getvalue().decode("utf-8"))
                print("Response: {}".format(response))
                for r in response:
                    route_context.route(r)

        final_url = self.base_url + request.url
        client = AsyncHTTPClient()
        http_request = HTTPRequest(final_url,
                                   method=Method.serialize(request.method),
                                   body=request.body)
        client.fetch(http_request, response_callback)
Exemplo n.º 3
0
 def test_SerializeMethod_POST_ReturnsString(self):
     self.assertEqual('POST', Method.serialize(Method.POST))
Exemplo n.º 4
0
 def test_SerializeMethod_GET_ReturnsString(self):
     self.assertEqual('GET', Method.serialize(Method.GET))
Exemplo n.º 5
0
 def test_ParseMethod_DELETE_MethodIsDELETE(self):
     self.assertEqual(Method.DELETE, Method.parse("DELETE"))
Exemplo n.º 6
0
 def test_ParseMethod_PUT_MethodIsPUT(self):
     self.assertEqual(Method.PUT, Method.parse("PUT"))
Exemplo n.º 7
0
 def test_ParseMethod_POST_MethodIsPOST(self):
     self.assertEqual(Method.POST, Method.parse("POST"))
Exemplo n.º 8
0
 def test_ParseMethod_GET_MethodIsGET(self):
     self.assertEqual(Method.GET, Method.parse("GET"))
Exemplo n.º 9
0
def step_impl(context, method):
    assert context.request.method == Method.parse(method)
Exemplo n.º 10
0
def step_impl(context, url_format, method):
    context.command_attributes['url_format'] = url_format
    context.command_attributes['method'] = Method.parse(method)