Пример #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}")
Пример #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)
Пример #3
0
 def test_SerializeMethod_POST_ReturnsString(self):
     self.assertEqual('POST', Method.serialize(Method.POST))
Пример #4
0
 def test_SerializeMethod_GET_ReturnsString(self):
     self.assertEqual('GET', Method.serialize(Method.GET))
Пример #5
0
 def test_ParseMethod_DELETE_MethodIsDELETE(self):
     self.assertEqual(Method.DELETE, Method.parse("DELETE"))
Пример #6
0
 def test_ParseMethod_PUT_MethodIsPUT(self):
     self.assertEqual(Method.PUT, Method.parse("PUT"))
Пример #7
0
 def test_ParseMethod_POST_MethodIsPOST(self):
     self.assertEqual(Method.POST, Method.parse("POST"))
Пример #8
0
 def test_ParseMethod_GET_MethodIsGET(self):
     self.assertEqual(Method.GET, Method.parse("GET"))
Пример #9
0
def step_impl(context, method):
    assert context.request.method == Method.parse(method)
Пример #10
0
def step_impl(context, url_format, method):
    context.command_attributes['url_format'] = url_format
    context.command_attributes['method'] = Method.parse(method)