Exemple #1
0
def run(*, port, callback, pretty=False):
    handler = echohandler
    if callback:
        handler = callback(handler)

    app = create_app(handler, content_type="application/json", pretty=pretty)
    with create_server(app, port=port) as httpd:
        httpd.serve_forever()
Exemple #2
0
def main():
    dirpath = os.path.join(os.path.dirname(__file__), "data/00requests/")
    mirrorhandler = create_mirrorhandler(dirpath)
    port = 55555

    origin_host = "localhost:4444"

    def mirror_redirect(request):
        request.modify_url("http://localhost:55555?_origin={}".format(
            parselib.quote_plus(origin_host)))

    with create_server(create_app(mirrorhandler), port=port) as httpd:
        # th = threading.Thread(target=httpd.serve_forever, daemon=True)
        # th.start()
        # monkeypatch(on_request=mirror_redirect, on_response=print)
        # requests.get("http://localhost:4444/")
        httpd.serve_forever()
Exemple #3
0
 def _makeEchoApp(self):
     from reqtrace.mockserve import create_app
     from reqtrace.mockserve.echohandler import echohandler
     return create_app(echohandler, content_type="application/json")
Exemple #4
0
                           "data/discovery.json")) as rf:
        return json.load(rf), 200


class RedirectStore:
    def __init__(self, url):
        self.url = url

    def __call__(self, request):
        print("@", request.url, "->", url)
        if request.url != url:
            request.url = url


# discovery
with background_server(create_app(discovery_callback)) as url:
    rs = RedirectStore(url)

    def noop(response):
        print(response)

    build_google = create_factory(on_request=rs, on_response=noop)
    service = build_google("slides", "v1")


def callback(environ):
    with open(
            os.path.join(os.path.dirname(__file__),
                         "data/presentations.json")) as rf:
        return json.load(rf), 200
Exemple #5
0
from reqtrace.testing import background_server
from reqtrace.mockserve import create_app
from reqtrace.tracelib.httplib2 import create_factory


def callback(environ):
    return "*ok*"


with background_server(create_app(callback)) as url:

    def coerce_redirect(request):
        request.url = url

    def on_response(response):
        print(response)

    Http = create_factory(on_request=coerce_redirect, on_response=on_response)
    h = Http()
    response, content = h.request("http://www.google.com/",
                                  method="GET",
                                  headers={"content-type": "text/plain"})
    print(response)
    print(content)
Exemple #6
0
 def _makeOne(self, *args, **kwargs):
     from reqtrace.mockserve import create_app
     return create_app(*args, **kwargs)
Exemple #7
0
def delete0(baseurl):
    response = requests.delete(baseurl)
    print(response.content)


def head0(baseurl):
    response = requests.head(baseurl)
    print(response.content)


def options0(baseurl):
    response = requests.options(baseurl)
    print(response.content)


with create_server(create_app(echohandler, content_type="application/json"),
                   port=port) as httpd:
    th = threading.Thread(target=httpd.serve_forever, daemon=True)
    th.start()

    url = "http://localhost:{port}".format(port=port)
    print("----------------------------------------")
    get0(url)
    get1(url)
    get2(url)

    print("----------------------------------------")
    post0(url)
    post1(url)
    post2(url)