示例#1
0
class HttpBin(object):
    base_uri = "https://httpbin.org"
    middleware = [
        request_id(key="x-flabber-id"),
        timeout(1.0),
        accept("application/json"),
        ua("the-fabricator/1.0.0"),
        request_logger(structlog.getLogger()),
    ]
    response_as = json_response

    def get(self):
        return self.request.get("get")

    def post(self, data):
        return self.request.post("post", data=data)

    def put(self, data):
        return self.request.put("put", data=data)

    def delete(self):
        return self.request.delete("delete")

    def get_4xx(self):
        return self.request.get("status/404")

    def post_4xx(self, data):
        return self.request.post("status/404", data=data)

    def put_4xx(self, data):
        return self.request.put("status/404", data=data)

    def delete_4xx(self):
        return self.request.delete("status/404")

    def get_5xx(self):
        return self.request.get("status/501")

    def post_5xx(self, data):
        return self.request.post("status/501", data=data)

    def put_5xx(self, data):
        return self.request.put("status/501", data=data)

    def delete_5xx(self):
        return self.request.delete("status/501")

    def get_3xx(self):
        return self.request.get("status/301")

    def post_3xx(self, data):
        return self.request.post("status/301", data=data)

    def put_3xx(self, data):
        return self.request.put("status/301", data=data)

    def delete_3xx(self):
        return self.request.delete("status/301")
示例#2
0
class HttpBin(object):
    base_uri = "https://httpbin.org"
    middleware = [
        timeout(0.1),
        accept("application/json"),
        ua("the-fabricator/1.0.0"),
        request_logger(structlog.getLogger()),
    ]
    response_as = json_response

    def publish(self, data):
        return self.request.post("post", data=data)
示例#3
0
def test_ua():
    sender = build_sender(middleware=[ua("foobar/1.0.0")])
    sender(
        "get", "http://example.com", headers={"x-custom": "hello"}, params={"v": "1.0"}
    )