From aacac6620387c5aa562b16845ee4a5558d39f899 Mon Sep 17 00:00:00 2001 From: Shahar Ilany <31574996+ShaharIlany@users.noreply.github.com> Date: Wed, 24 Aug 2022 22:36:44 +0300 Subject: [PATCH] fix(test_tutorial): fix tests to improve coverage --- .../test_tutorial002.py | 7 +++++++ .../test_tutorial006.py | 20 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/test_tutorial/test_extending_openapi/test_tutorial006.py diff --git a/tests/test_tutorial/test_extending_openapi/test_tutorial002.py b/tests/test_tutorial/test_extending_openapi/test_tutorial002.py index 654db2e4c..e7fd48eec 100644 --- a/tests/test_tutorial/test_extending_openapi/test_tutorial002.py +++ b/tests/test_tutorial/test_extending_openapi/test_tutorial002.py @@ -36,6 +36,13 @@ def test_redoc_html(client: TestClient): assert "/static/redoc.standalone.js" in response.text +def test_elements_html(client: TestClient): + response = client.get("/elements") + assert response.status_code == 200, response.text + assert "/static/web-components.min.js" in response.text + assert "/static/styles.min.css" in response.text + + def test_api(client: TestClient): response = client.get("/users/john") assert response.status_code == 200, response.text diff --git a/tests/test_tutorial/test_extending_openapi/test_tutorial006.py b/tests/test_tutorial/test_extending_openapi/test_tutorial006.py new file mode 100644 index 000000000..34aad3d6e --- /dev/null +++ b/tests/test_tutorial/test_extending_openapi/test_tutorial006.py @@ -0,0 +1,20 @@ +from fastapi.testclient import TestClient + +from docs_src.extending_openapi.tutorial006 import app + +client = TestClient(app) + + +def test_swagger_ui(): + response = client.get("/elements") + assert response.status_code == 200, response.text + assert 'router="history"' in response.text + assert 'layout="sidebar"' in response.text + assert 'tryItCredentialPolicy="omit"' in response.text + + + +def test_get_users(): + response = client.get("/users/foo") + assert response.status_code == 200, response.text + assert response.json() == {"message": "Hello foo"}