Add test for an Album with tracks.

This commit is contained in:
EspenAlbert
2020-11-24 08:56:57 +00:00
parent 3eccd05ece
commit a668b20f1a

View File

@ -379,7 +379,7 @@ async def test_wrong_model_passed_as_fk():
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_bulk_update_model_with_children(): async def test_bulk_update_model_with_no_children():
async with database: async with database:
async with database.transaction(force_rollback=True): async with database.transaction(force_rollback=True):
album = await Album.objects.create(name="Test") album = await Album.objects.create(name="Test")
@ -389,3 +389,19 @@ async def test_bulk_update_model_with_children():
updated_album = await Album.objects.get(id=album.id) updated_album = await Album.objects.get(id=album.id)
assert updated_album.name == "Test2" assert updated_album.name == "Test2"
@pytest.mark.asyncio
async def test_bulk_update_model_with_children():
async with database:
async with database.transaction(force_rollback=True):
album = await Album.objects.create(name="Test")
track = await Track.objects.create(album=album, title="Test1", position=1)
album_with_tracks = await Album.objects.select_related("tracks").get(
name="Test"
)
album_with_tracks.name = "Test2"
await Album.objects.bulk_update([album_with_tracks], columns=["name"])
updated_album = await Album.objects.get(id=album.id)
assert updated_album.name == "Test2"