Update get_or_create method

This commit is contained in:
Mojix Coder
2022-02-01 09:44:07 +03:30
parent 4ed267e5c3
commit fc32001fe7
9 changed files with 92 additions and 33 deletions

View File

@ -157,15 +157,17 @@ async def test_bulk_operations_and_fields():
async def test_working_with_aliases_get_or_create():
async with database:
async with database.transaction(force_rollback=True):
artist = await Artist.objects.get_or_create(
artist, created = await Artist.objects.get_or_create(
first_name="Teddy", last_name="Bear", born_year=2020
)
assert artist.pk is not None
assert created is True
artist2 = await Artist.objects.get_or_create(
artist2, created = await Artist.objects.get_or_create(
first_name="Teddy", last_name="Bear", born_year=2020
)
assert artist == artist2
assert created is False
art3 = artist2.dict()
art3["born_year"] = 2019

View File

@ -195,12 +195,14 @@ async def test_queryset_methods():
comps = await Company.objects.all()
assert [comp.saved for comp in comps]
comp2 = await Company.objects.get_or_create(name="Banzai_new", founded=2001)
comp2, created = await Company.objects.get_or_create(name="Banzai_new", founded=2001)
assert comp2.saved
assert created is True
comp3 = await Company.objects.get_or_create(name="Banzai", founded=1988)
comp3, created = await Company.objects.get_or_create(name="Banzai", founded=1988)
assert comp3.saved
assert comp3.pk == comp.pk
assert created is False
update_dict = comp.dict()
update_dict["founded"] = 2010