From 8b37a141315983c416879353cb84b8b431d183b9 Mon Sep 17 00:00:00 2001 From: collerek Date: Tue, 27 Oct 2020 18:18:09 +0100 Subject: [PATCH] update docs and bump version --- docs/fastapi.md | 25 +++++++++++++++++++++++-- docs_src/fastapi/docs001.py | 4 +++- mkdocs.yml | 6 +++--- ormar/__init__.py | 2 +- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/docs/fastapi.md b/docs/fastapi.md index 9ae1dad..d451fee 100644 --- a/docs/fastapi.md +++ b/docs/fastapi.md @@ -45,7 +45,7 @@ Those models will be used insted of pydantic ones. Define your desired endpoints, note how `ormar` models are used both as `response_model` and as a requests parameters. -```python hl_lines="50-77" +```python hl_lines="50-79" --8<-- "../docs_src/fastapi/docs001.py" ``` @@ -57,6 +57,23 @@ as `response_model` and as a requests parameters. ## Test the application +### Run fastapi + +If you want to run this script and play with fastapi swagger install uvicorn first + +`pip install uvicorn` + +And launch the fastapi. + +`uvicorn :app --reload` + +Now you can navigate to your browser (by default fastapi address is `127.0.0.1:8000/docs`) and play with the api. + +!!!info + You can read more about running fastapi in [fastapi][fastapi] docs. + +### Test with pytest + Here you have a sample test that will prove that everything works as intended. Be sure to create the tables first. If you are using pytest you can use a fixture. @@ -109,9 +126,13 @@ def test_all_endpoints(): assert len(items) == 0 ``` +!!!tip + If you want to see more test cases and how to test ormar/fastapi see [tests][tests] directory in the github repo + !!!info You can read more on testing fastapi in [fastapi][fastapi] docs. [fastapi]: https://fastapi.tiangolo.com/ [models]: ./models.md -[database initialization]: ../models/#database-initialization-migrations \ No newline at end of file +[database initialization]: ../models/#database-initialization-migrations +[tests]: https://github.com/collerek/ormar/tree/master/tests \ No newline at end of file diff --git a/docs_src/fastapi/docs001.py b/docs_src/fastapi/docs001.py index 30ca75f..475756a 100644 --- a/docs_src/fastapi/docs001.py +++ b/docs_src/fastapi/docs001.py @@ -72,6 +72,8 @@ async def get_item(item_id: int, item: Item): @app.delete("/items/{item_id}") -async def delete_item(item_id: int, item: Item): +async def delete_item(item_id: int, item: Item = None): + if item: + return {"deleted_rows": await item.delete()} item_db = await Item.objects.get(pk=item_id) return {"deleted_rows": await item_db.delete()} diff --git a/mkdocs.yml b/mkdocs.yml index a7b99e3..234f18d 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -12,9 +12,9 @@ nav: - Release Notes: releases.md repo_name: collerek/ormar repo_url: https://github.com/collerek/ormar -google_analytics: - - UA-72514911-3 - - auto +#google_analytics: +# - UA-72514911-3 +# - auto theme: name: material highlightjs: true diff --git a/ormar/__init__.py b/ormar/__init__.py index 159fda5..4aefddc 100644 --- a/ormar/__init__.py +++ b/ormar/__init__.py @@ -28,7 +28,7 @@ class UndefinedType: # pragma no cover Undefined = UndefinedType() -__version__ = "0.3.8" +__version__ = "0.3.9" __all__ = [ "Integer", "BigInteger",