Пример #1
0
class Google(object):
    base_uri = "https://google.com"
    middleware = [request_logger(structlog.getLogger())]
    response_as = html_response

    def search(self, text):
        return self.request.get("/", params=Query(text))
Пример #2
0
def get_test_stack(logger):
    now = lambda: datetime.datetime(2018, 12, 4, 16, 25, 28, 183004)
    return [
        request_id(idgen=lambda: "req-1"),
        context(getpid=lambda: "pid-1", gettid=lambda: "tid-1"),
        request_duration(now=now),
        request_logger(logger),
    ]
Пример #3
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")
Пример #4
0
class Github(object):
    base_uri = "https://api.github.com/"
    middleware = [request_logger(structlog.getLogger())]
    response_as = json_response

    def stargazers(self, owner, repo):
        return self.request.get("repos/:owner/:repo/stargazers",
                                params=Query(owner, repo))

    def download(self, release):
        pass
Пример #5
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)
Пример #6
0
class Breaker(object):
    base_uri = "https://example.com"
    middleware = [
        timeout(1),
        circuit_breaker(logger, "breaker-1", reset_timeout=10),
        trigger_breaker_if(lambda res: res.status_code == 200),
        request_logger(logger),
    ]
    response_as = html_response

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