Merge branch 'master' of https://github.com/collerek/ormar into check_timezones_filters
This commit is contained in:
@ -5,7 +5,10 @@ import pytest
|
||||
import sqlalchemy
|
||||
|
||||
import ormar
|
||||
from ormar.exceptions import ModelPersistenceError, QueryDefinitionError
|
||||
from ormar.exceptions import (
|
||||
ModelPersistenceError, QueryDefinitionError,
|
||||
ModelListEmptyError
|
||||
)
|
||||
from tests.settings import DATABASE_URL
|
||||
|
||||
database = databases.Database(DATABASE_URL, force_rollback=True)
|
||||
@ -309,3 +312,6 @@ async def test_bulk_update_not_saved_objts():
|
||||
Note(text="Call Mum.", category=category),
|
||||
]
|
||||
)
|
||||
|
||||
with pytest.raises(ModelListEmptyError):
|
||||
await Note.objects.bulk_update([])
|
||||
|
||||
@ -6,7 +6,11 @@ import pytest
|
||||
import sqlalchemy
|
||||
|
||||
import ormar
|
||||
from ormar import post_delete, post_save, post_update, pre_delete, pre_save, pre_update
|
||||
from ormar import (
|
||||
post_bulk_update, post_delete, post_save, post_update,
|
||||
pre_delete, pre_save, pre_update
|
||||
)
|
||||
from ormar.signals import SignalEmitter
|
||||
from ormar.exceptions import SignalDefinitionError
|
||||
from tests.settings import DATABASE_URL
|
||||
|
||||
@ -77,6 +81,12 @@ def test_passing_callable_without_kwargs():
|
||||
pass
|
||||
|
||||
|
||||
def test_invalid_signal():
|
||||
emitter = SignalEmitter()
|
||||
with pytest.raises(SignalDefinitionError):
|
||||
emitter.save = 1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_signal_functions(cleanup):
|
||||
async with database:
|
||||
@ -124,6 +134,14 @@ async def test_signal_functions(cleanup):
|
||||
event_log=instance.json(),
|
||||
).save()
|
||||
|
||||
@post_bulk_update(Album)
|
||||
async def after_bulk_update(sender, instances, **kwargs):
|
||||
for it in instances:
|
||||
await AuditLog(
|
||||
event_type=f"BULK_POST_UPDATE_{sender.get_name()}",
|
||||
event_log=it.json(),
|
||||
).save()
|
||||
|
||||
album = await Album.objects.create(name="Venice")
|
||||
|
||||
audits = await AuditLog.objects.all()
|
||||
@ -176,6 +194,19 @@ async def test_signal_functions(cleanup):
|
||||
album.signals.pre_save.disconnect(before_save)
|
||||
album.signals.post_save.disconnect(after_save)
|
||||
|
||||
albums = await Album.objects.all()
|
||||
assert len(albums)
|
||||
|
||||
for album in albums:
|
||||
album.play_count = 1
|
||||
|
||||
await Album.objects.bulk_update(albums)
|
||||
|
||||
cnt = await AuditLog.objects.filter(event_type__contains="BULK_POST").count()
|
||||
assert cnt == len(albums)
|
||||
|
||||
album.signals.bulk_post_update.disconnect(after_bulk_update)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_multiple_signals(cleanup):
|
||||
|
||||
Reference in New Issue
Block a user