]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
:white_check_mark: Add tests for metadata
authorSebastián Ramírez <tiangolo@gmail.com>
Sat, 22 Dec 2018 14:47:05 +0000 (18:47 +0400)
committerSebastián Ramírez <tiangolo@gmail.com>
Sat, 22 Dec 2018 14:47:05 +0000 (18:47 +0400)
docs/src/application_configuration/tutorial001.py [moved from docs/src/application-configuration/tutorial001.py with 100% similarity]
docs/src/application_configuration/tutorial002.py [moved from docs/src/application-configuration/tutorial002.py with 100% similarity]
docs/src/application_configuration/tutorial003.py [moved from docs/src/application-configuration/tutorial003.py with 100% similarity]
docs/tutorial/application-configuration.md
tests/test_tutorial/test_application_configuration/__init__.py [new file with mode: 0644]
tests/test_tutorial/test_application_configuration/test_tutorial001.py [new file with mode: 0644]
tests/test_tutorial/test_query_params_str_validations/__init__.py [new file with mode: 0644]
tests/test_tutorial/test_query_params_str_validations/test_tutorial001.py [new file with mode: 0644]

index f9e3b83f0ba3cfede94721d19a36967e47106ee8..296c34272c3f5ad5f819f256980e6a82dc3c5a71 100644 (file)
@@ -1,13 +1,13 @@
 Coming soon...
 
 ```Python
-{!./src/application-configuration/tutorial001.py!}
+{!./src/application_configuration/tutorial001.py!}
 ```
 
 ```Python
-{!./src/application-configuration/tutorial002.py!}
+{!./src/application_configuration/tutorial002.py!}
 ```
 
 ```Python
-{!./src/application-configuration/tutorial003.py!}
+{!./src/application_configuration/tutorial003.py!}
 ```
diff --git a/tests/test_tutorial/test_application_configuration/__init__.py b/tests/test_tutorial/test_application_configuration/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/test_tutorial/test_application_configuration/test_tutorial001.py b/tests/test_tutorial/test_application_configuration/test_tutorial001.py
new file mode 100644 (file)
index 0000000..3f5b7fb
--- /dev/null
@@ -0,0 +1,34 @@
+from starlette.testclient import TestClient
+
+from application_configuration.tutorial001 import app
+
+client = TestClient(app)
+
+openapi_schema = {
+    "openapi": "3.0.2",
+    "info": {
+        "title": "My Super Project",
+        "version": "2.5.0",
+        "description": "This is a very fancy project, with auto docs for the API and everything",
+    },
+    "paths": {
+        "/items/": {
+            "get": {
+                "responses": {
+                    "200": {
+                        "description": "Successful Response",
+                        "content": {"application/json": {"schema": {}}},
+                    }
+                },
+                "summary": "Read Items Get",
+                "operationId": "read_items_items__get",
+            }
+        }
+    },
+}
+
+
+def test_openapi_scheme():
+    response = client.get("/openapi.json")
+    assert response.status_code == 200
+    assert response.json() == openapi_schema
diff --git a/tests/test_tutorial/test_query_params_str_validations/__init__.py b/tests/test_tutorial/test_query_params_str_validations/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/test_tutorial/test_query_params_str_validations/test_tutorial001.py b/tests/test_tutorial/test_query_params_str_validations/test_tutorial001.py
new file mode 100644 (file)
index 0000000..5c8ecb2
--- /dev/null
@@ -0,0 +1,86 @@
+from starlette.testclient import TestClient
+
+from query_params_str_validations.tutorial010 import app
+
+client = TestClient(app)
+
+openapi_schema = {
+    "openapi": "3.0.2",
+    "info": {"title": "Fast API", "version": "0.1.0"},
+    "paths": {
+        "/items/": {
+            "get": {
+                "responses": {
+                    "200": {
+                        "description": "Successful Response",
+                        "content": {"application/json": {"schema": {}}},
+                    },
+                    "422": {
+                        "description": "Validation Error",
+                        "content": {
+                            "application/json": {
+                                "schema": {
+                                    "$ref": "#/components/schemas/HTTPValidationError"
+                                }
+                            }
+                        },
+                    },
+                },
+                "summary": "Read Items Get",
+                "operationId": "read_items_items__get",
+                "parameters": [
+                    {
+                        "description": "Query string for the items to search in the database that have a good match",
+                        "required": False,
+                        "deprecated": True,
+                        "schema": {
+                            "title": "Query string",
+                            "maxLength": 50,
+                            "minLength": 3,
+                            "pattern": "^fixedquery$",
+                            "type": "string",
+                            "description": "Query string for the items to search in the database that have a good match",
+                        },
+                        "name": "item-query",
+                        "in": "query",
+                    }
+                ],
+            }
+        }
+    },
+    "components": {
+        "schemas": {
+            "ValidationError": {
+                "title": "ValidationError",
+                "required": ["loc", "msg", "type"],
+                "type": "object",
+                "properties": {
+                    "loc": {
+                        "title": "Location",
+                        "type": "array",
+                        "items": {"type": "string"},
+                    },
+                    "msg": {"title": "Message", "type": "string"},
+                    "type": {"title": "Error Type", "type": "string"},
+                },
+            },
+            "HTTPValidationError": {
+                "title": "HTTPValidationError",
+                "type": "object",
+                "properties": {
+                    "detail": {
+                        "title": "Detail",
+                        "type": "array",
+                        "items": {"$ref": "#/components/schemas/ValidationError"},
+                    }
+                },
+            },
+        }
+    },
+}
+
+
+def test_openapi_scheme():
+    response = client.get("/openapi.json")
+    assert response.status_code == 200
+    assert response.json() == openapi_schema