Skip to content

Commit

Permalink
test: add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
mschoettle committed Sep 13, 2024
1 parent 94b2c57 commit d6d9b19
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest
from asgiref.sync import sync_to_async
from django.db import transaction
from django.contrib.contenttypes.models import ContentType
from django.core import management
from django.urls import reverse
Expand Down Expand Up @@ -189,6 +190,29 @@ def test_delete(self, model):
)
assert crud_event_qs.count() == 2

@pytest.mark.django_db(transaction=True)
def test_delete_transaction(self, model, settings):
settings.TEST = False

with transaction.atomic():
obj = model.objects.create()
model.objects.all().delete()

crud_event_qs = CRUDEvent.objects.filter(
object_id=obj.id,
content_type=ContentType.objects.get_for_model(obj),
event_type=CRUDEvent.CREATE,
)
assert crud_event_qs.count() == 1

# model.objects.all().delete()
crud_event_qs = CRUDEvent.objects.filter(
object_id=obj.id,
content_type=ContentType.objects.get_for_model(obj),
event_type=CRUDEvent.DELETE,
)
assert crud_event_qs.count() == 1

@pytest.mark.usefixtures("_audit_logger")
def test_propagate_exceptions(self, model, settings):
with pytest.raises(ValueError, match="Test exception"):
Expand Down

0 comments on commit d6d9b19

Please sign in to comment.