diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-11-29 16:45:39 +0100 |
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-11-29 16:45:39 +0100 |
| commit | 47ae57c37abfed75f93594255b6c617afa011bf5 (patch) | |
| tree | c9172a07ceb24b67854009b0c3cad9e365affe7b /archaeological_context_records/tests.py | |
| parent | 713a5fd98aef4432977461dbf0b24790b9539053 (diff) | |
| download | Ishtar-47ae57c37abfed75f93594255b6c617afa011bf5.tar.bz2 Ishtar-47ae57c37abfed75f93594255b6c617afa011bf5.zip | |
🐛 fix deletion of items with associated datations - better performance for deletion - delete directly associéted geovectordata
Diffstat (limited to 'archaeological_context_records/tests.py')
| -rw-r--r-- | archaeological_context_records/tests.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py index 942ad83f1..0338a2f20 100644 --- a/archaeological_context_records/tests.py +++ b/archaeological_context_records/tests.py @@ -24,6 +24,7 @@ import locale from django.apps import apps from django.conf import settings from django.contrib.auth.models import Permission, Group +from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ValidationError from django.core.files.uploadedfile import SimpleUploadedFile from django.template.defaultfilters import slugify @@ -600,6 +601,35 @@ class ContextRecordTest(ContextRecordInit, TestCase): # same unit and other operation -> 1 self.assertEqual(cr3.custom_index, 1) + def test_cascade_delete(self): + cr1 = self.context_records[0] + # add a geo_vector associated to the town + source_content_type_pk = ContentType.objects.get( + app_label="ishtar_common", + model="town" + ).pk + geo_vector = models.GeoVectorData.objects.create( + source_content_type_id=source_content_type_pk, + source_id=cr1.town_id, + name="geo", + comment="This is a comment." + ) + cr1.geodata.add(geo_vector) + BaseFind = apps.get_model("archaeological_finds", "BaseFind") + bf = BaseFind.objects.create(context_record=cr1) + bf.geodata.add(geo_vector) + Find = apps.get_model("archaeological_finds", "Find") + find = Find.objects.create() + bf.find.add(find) + dating = models.ContextRecordDating.objects.create(context_record=cr1) + cr1.operation.delete() + self.assertEqual(models.ContextRecord.objects.filter(id=cr1.id).count(), 0) + self.assertEqual(Find.objects.filter(id=find.id).count(), 0) + self.assertEqual(BaseFind.objects.filter(id=bf.id).count(), 0) + self.assertEqual(models.ContextRecordDating.objects.filter(id=dating.id).count(), + 0) + self.assertEqual(models.GeoVectorData.objects.filter(id=geo_vector.id).count(), 1) + class ContextRecordQATest(ContextRecordInit, TestCase): fixtures = CONTEXT_RECORD_TOWNS_FIXTURES |
