update readme and tests
This commit is contained in:
@ -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 :)
|
||||
|
||||
**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
|
||||
|
||||
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).
|
||||
|
||||
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>
|
||||
|
||||
|
||||
@ -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 :)
|
||||
|
||||
**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
|
||||
|
||||
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).
|
||||
|
||||
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>
|
||||
|
||||
|
||||
@ -69,29 +69,67 @@ async def test_exclude_default():
|
||||
@pytest.mark.asyncio
|
||||
async def test_exclude_none():
|
||||
async with database:
|
||||
category = Category(name=None)
|
||||
category = Category(id=2, name=None)
|
||||
assert category.dict() == {
|
||||
"id": None,
|
||||
"id": 2,
|
||||
"items": [],
|
||||
"name": None,
|
||||
"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()
|
||||
category2 = await Category.objects.get()
|
||||
assert category2.dict() == {
|
||||
"id": 1,
|
||||
"id": 2,
|
||||
"items": [],
|
||||
"name": None,
|
||||
"visibility": True,
|
||||
}
|
||||
assert category2.dict(exclude_none=True) == {
|
||||
"id": 1,
|
||||
"id": 2,
|
||||
"items": [],
|
||||
"visibility": True,
|
||||
}
|
||||
assert (
|
||||
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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user