update readme and tests

This commit is contained in:
collerek
2021-05-11 17:53:34 +02:00
parent bd2a67af84
commit 61a5199986
3 changed files with 54 additions and 8 deletions

View File

@ -35,6 +35,10 @@ Ormar - apart form obvious ORM in name - get it's name from ormar in swedish whi
And what's a better name for python ORM than snakes cabinet :) And what's a better name for python ORM than snakes cabinet :)
**If you like ormar remember to star the repository in [github](https://github.com/collerek/ormar)!**
The bigger community we build, the easier it will be to catch bugs and attract contributors ;)
### Documentation ### Documentation
Check out the [documentation][documentation] for details. Check out the [documentation][documentation] for details.
@ -73,7 +77,7 @@ Ormar is built with:
`ormar` is built as an open-sorce software and remain completely free (MIT license). `ormar` is built as an open-sorce software and remain completely free (MIT license).
As I write open-source code to solve everyday problems in my work or to promote and build strong python As I write open-source code to solve everyday problems in my work or to promote and build strong python
community you can say thank you and buy me a coffee or sponsor me with a monthly amount to help me ensure my work remains free and maintained. community you can say thank you and buy me a coffee or sponsor me with a monthly amount to help ensure my work remains free and maintained.
<iframe src="https://github.com/sponsors/collerek/button" title="Sponsor collerek" height="35" width="116" style="border: 0;"></iframe> <iframe src="https://github.com/sponsors/collerek/button" title="Sponsor collerek" height="35" width="116" style="border: 0;"></iframe>

View File

@ -35,6 +35,10 @@ Ormar - apart form obvious ORM in name - get it's name from ormar in swedish whi
And what's a better name for python ORM than snakes cabinet :) And what's a better name for python ORM than snakes cabinet :)
**If you like ormar remember to star the repository in [github](https://github.com/collerek/ormar)!**
The bigger community we build, the easier it will be to catch bugs and attract contributors ;)
### Documentation ### Documentation
Check out the [documentation][documentation] for details. Check out the [documentation][documentation] for details.
@ -73,7 +77,7 @@ Ormar is built with:
`ormar` is built as an open-sorce software and remain completely free (MIT license). `ormar` is built as an open-sorce software and remain completely free (MIT license).
As I write open-source code to solve everyday problems in my work or to promote and build strong python As I write open-source code to solve everyday problems in my work or to promote and build strong python
community you can say thank you and buy me a coffee or sponsor me with a monthly amount to help me ensure my work remains free and maintained. community you can say thank you and buy me a coffee or sponsor me with a monthly amount to help ensure my work remains free and maintained.
<iframe src="https://github.com/sponsors/collerek/button" title="Sponsor collerek" height="35" width="116" style="border: 0;"></iframe> <iframe src="https://github.com/sponsors/collerek/button" title="Sponsor collerek" height="35" width="116" style="border: 0;"></iframe>

View File

@ -69,29 +69,67 @@ async def test_exclude_default():
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_exclude_none(): async def test_exclude_none():
async with database: async with database:
category = Category(name=None) category = Category(id=2, name=None)
assert category.dict() == { assert category.dict() == {
"id": None, "id": 2,
"items": [], "items": [],
"name": None, "name": None,
"visibility": True, "visibility": True,
} }
assert category.dict(exclude_none=True) == {"items": [], "visibility": True} assert category.dict(exclude_none=True) == {
"id": 2,
"items": [],
"visibility": True,
}
await category.save() await category.save()
category2 = await Category.objects.get() category2 = await Category.objects.get()
assert category2.dict() == { assert category2.dict() == {
"id": 1, "id": 2,
"items": [], "items": [],
"name": None, "name": None,
"visibility": True, "visibility": True,
} }
assert category2.dict(exclude_none=True) == { assert category2.dict(exclude_none=True) == {
"id": 1, "id": 2,
"items": [], "items": [],
"visibility": True, "visibility": True,
} }
assert ( assert (
category2.json(exclude_none=True) category2.json(exclude_none=True)
== '{"id": 1, "visibility": true, "items": []}' == '{"id": 2, "visibility": true, "items": []}'
) )
@pytest.mark.asyncio
async def test_exclude_unset():
async with database:
category = Category(id=3, name="Test 2")
assert category.dict() == {
"id": 3,
"items": [],
"name": "Test 2",
"visibility": True,
}
assert category.dict(exclude_unset=True) == {
"id": 3,
"items": [],
"name": "Test 2",
}
await category.save()
category2 = await Category.objects.get()
assert category2.dict() == {
"id": 3,
"items": [],
"name": "Test 2",
"visibility": True,
}
# NOTE how after loading from db all fields are set explicitly
# as this is what happens when you populate a model from db
assert category2.dict(exclude_unset=True) == {
"id": 3,
"items": [],
"name": "Test 2",
"visibility": True,
}