From 3dda2e3dc210dfa81625424fdf866172083ac0b8 Mon Sep 17 00:00:00 2001 From: LeOndaz Date: Mon, 11 Oct 2021 02:23:14 +0200 Subject: [PATCH] added tests for fastapi --- sample_apps/fastapi/main.py | 13 +++++++++++++ test_examples/pytest_example/tests.py | 4 ++++ test_examples/unittest_example/tests.py | 5 +++++ 3 files changed, 22 insertions(+) create mode 100644 sample_apps/fastapi/main.py diff --git a/sample_apps/fastapi/main.py b/sample_apps/fastapi/main.py new file mode 100644 index 0000000..7d84b50 --- /dev/null +++ b/sample_apps/fastapi/main.py @@ -0,0 +1,13 @@ +# encoding: utf-8 +from fastapi import FastAPI, Request + +app = FastAPI() + + +@app.get('/') +def home(request: Request): + content = 'Home FastAPI' + if request.url.startswith('https://'): + content += ' SSL' + + return content diff --git a/test_examples/pytest_example/tests.py b/test_examples/pytest_example/tests.py index d2647c4..28010d7 100644 --- a/test_examples/pytest_example/tests.py +++ b/test_examples/pytest_example/tests.py @@ -39,6 +39,10 @@ def abspath(pth): abspath('sample_apps/django/example'), port=PORT ), + 'FastAPI': liveandletdie.FastAPIServer( + abspath('sample_apps/fastapi/main.py'), + port=PORT + ), } diff --git a/test_examples/unittest_example/tests.py b/test_examples/unittest_example/tests.py index 87dca41..e93bdf4 100644 --- a/test_examples/unittest_example/tests.py +++ b/test_examples/unittest_example/tests.py @@ -83,6 +83,11 @@ class TestGAE(unittest.TestCase): app = liveandletdie.GAE(environ['VIRTUAL_ENV'] + '/bin/dev_appserver', abspath('sample_apps/gae'), port=PORT) +@test_decorator +class TestFastAPI(unittest.TestCase): + EXPECTED_TEXT = 'Home FastAPI' + app = liveandletdie.FastAPIServer(abspath('sample_apps/fastapi/main.py'), port=PORT) + if __name__ == '__main__': unittest.main()