Exemple #1
0
    def setUpClass(cls) -> None:
        cls.urls_info = [f"http://localhost:800{i}/mock/info" for i in range(3)]
        cls.urls_image = [f"http://localhost:800{i}/mock/image" for i in range(3)]

        app_1 = WSGIApp()
        app_2 = WSGIApp()
        app_3 = WSGIApp()

        for app in (app_1, app_2, app_3):
            app.route("mock", "info")(MockInfoEndpoint)
            app.route("mock", "image")(MockImageEndpoint)

        form_1 = WSGIServerForm("", 8000, app_1, PATH_SERVER_LOG_1)
        form_2 = WSGIServerForm("", 8001, app_2, PATH_SERVER_LOG_2)
        form_3 = WSGIServerForm("", 8002, app_3, PATH_SERVER_LOG_3)
        cls.executor = WSGITestExecutor(form_1, form_2, form_3).start_serve()
 def setUpClass(cls) -> None:
     form_asgi = ASGIServerForm("", 8000, app_asgi, PATH_ASGI_SERVER_LOG)
     form_wsgi = WSGIServerForm("", 8001, app_wsgi, PATH_WSGI_SERVER_LOG)
     cls.executor_asgi = ASGITestExecutor(form_asgi).start_serve()
     cls.executor_wsgi = WSGITestExecutor(form_wsgi).start_serve()
     cls.uri_asgi = "http://localhost:8000"
     cls.uri_wsgi = "http://localhost:8001"
Exemple #3
0
    def test_routing(self):
        # Make different uris
        paths = list(set(rand_strings(30)))

        def client():
            for i, path in enumerate(paths):
                uri = f"http://localhost:{8000 + i}/{path}"
                with http.get(uri) as res:
                    self.assertEqual(res.body, IDEAL_RESNPONSE)

        forms = []
        for i, path in enumerate(paths):
            app = WSGIApp()
            app.route(path)(MockEndpoint)
            forms.append(WSGIServerForm("", 8000 + i, app, PATH_SERVER_LOG))

        WSGITestExecutor(*forms).exec(client)
Exemple #4
0
 def setUpClass(cls) -> None:
     form = WSGIServerForm("", 8000, app, PATH_SERVER_LOG)
     cls.executor = WSGITestExecutor(form).start_serve()
Exemple #5
0
        for no, command, _, func in COMMANDS:
            if request in (no, command):
                func(uris, email)
                break
        else:
            print("一致するコマンドが存在しません.\n")


# --------------------------------------------------------------------------------

if __name__ == "__main__":

    import sys

    uris = Uris(
        "http://localhost:8000/user",
        "http://localhost:8000/tweet",
    )

    user_controller = UserController(UserModel)
    tweet_controller = TweetController(TweetModel)
    app.set_parcel(UserEndpoint, user_controller)
    app.set_parcel(TweetsEndpoint, tweet_controller)

    if len(sys.argv) == 1:
        form = WSGIServerForm("", 8000, app, "app.log")
        executor = WSGITestExecutor(form)
        executor.exec(request_interact, args=(uris, ))
    elif sys.argv[1] == "client":
        request_interact(uris)
Exemple #6
0
            ))


def request_image(uri: str, path_save: str) -> None:
    with http.get(uri, datacls=MockResponse) as res:
        if res.ok:
            data = res.attach()
            print(f"Date time: {data.datetime}")
            print("Saving image in the response...")
            with open(path_save, "wb") as f:
                f.write(decode2binary(data.image))
        else:
            print("Request failed.", end="\n\n")
            print("headers")
            print("-------")
            for key, val in res.headers.items():
                print(f"{key} : {val}")


if __name__ == "__main__":
    me = "hoge"
    URI = f"http://localhost:8000/{me}/image"
    PATH_IMAGE = "elephant.jpg"
    PATH_SAVE = "received.jpg"

    app.set_parcel(MockServeImageEndpoint, PATH_IMAGE)

    form = WSGIServerForm("", 8000, app, "image_traffic.log")
    executer = WSGITestExecutor(form)
    executer.exec(request_image, (URI, PATH_SAVE))
Exemple #7
0
 def setUpClass(cls) -> None:
     cls.conn = client.HTTPConnection("localhost", 8000)
     form = WSGIServerForm("", 8000, app, PATH_SERVER_LOG)
     cls.executor = WSGITestExecutor(form).start_serve()