update docs and bump version

This commit is contained in:
collerek
2020-10-27 18:18:09 +01:00
parent 82e3eb94ae
commit 8b37a14131
4 changed files with 30 additions and 7 deletions

View File

@ -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 <filename_without_extension>: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
[tests]: https://github.com/collerek/ormar/tree/master/tests

View File

@ -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()}

View File

@ -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

View File

@ -28,7 +28,7 @@ class UndefinedType: # pragma no cover
Undefined = UndefinedType()
__version__ = "0.3.8"
__version__ = "0.3.9"
__all__ = [
"Integer",
"BigInteger",