summaryrefslogtreecommitdiff
path: root/archaeological_operations/tests.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2017-01-23 13:30:02 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2017-01-23 13:30:02 +0100
commitba337429e0f062195c23cf12950826ddf8eaf18a (patch)
treed9670b2cfda751566edb6cde81aedf81eb9fa6e8 /archaeological_operations/tests.py
parentf02eaa8d0ab5a381b64b7108dc9f4a7c3ffdbcef (diff)
downloadIshtar-ba337429e0f062195c23cf12950826ddf8eaf18a.tar.bz2
Ishtar-ba337429e0f062195c23cf12950826ddf8eaf18a.zip
Parcels: on associated operation or file detachment remove the parcel
Diffstat (limited to 'archaeological_operations/tests.py')
-rw-r--r--archaeological_operations/tests.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index 86eb2dfe7..33199dd04 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -35,7 +35,7 @@ import models
from archaeological_operations import views
from ishtar_common.models import OrganizationType, Organization, \
- ImporterType, IshtarUser, TargetKey, IshtarSiteProfile
+ ImporterType, IshtarUser, TargetKey, IshtarSiteProfile, Town
from ishtar_common import forms_common
from ishtar_common.tests import WizardTest, WizardTestFormData as FormData, \
@@ -603,10 +603,28 @@ class OperationTest(TestCase, OperationInitTest):
response = c.get(reverse('get-operation'), search)
self.assertTrue(json.loads(response.content)['total'] == 2)
- def testRelations(self):
+ def testPostDeleteRelations(self):
self.create_relations()
self.operations[0].delete()
+ def testPostDeleteParcels(self):
+ ope = self.operations[0]
+ town = Town.objects.create(name='plouf', numero_insee='20000')
+ parcel = models.Parcel.objects.create(town=town)
+ parcel_nb = models.Parcel.objects.count()
+ ope.parcels.add(parcel)
+ ope.delete()
+ # our parcel has no operation attached and should be deleted
+ self.assertEqual(parcel_nb - 1, models.Parcel.objects.count())
+ ope = self.operations[1]
+ parcel = models.Parcel.objects.create(town=town)
+ parcel_nb = models.Parcel.objects.count()
+ ope.parcels.add(parcel)
+ ope.parcels.clear() # no signal raised... should resave
+ models.Parcel.objects.filter(pk=parcel.pk).all()[0].save()
+ # our parcel has no operation attached and should be deleted
+ self.assertEqual(parcel_nb - 1, models.Parcel.objects.count())
+
def testOwnSearch(self):
c = Client()
response = c.get(reverse('get-operation'), {'year': '2010'})
@@ -726,6 +744,8 @@ class OperationWizardDeleteTest(OperationWizardCreationTest):
def pre_wizard(self):
self.ope = self.get_default_operation(force=True)
+ self.ope.parcels.add(self.create_parcel()[0])
+ self.parcel_nb = models.Parcel.objects.count()
self.form_datas[0].form_datas['selec-operation_deletion']['pk'] = \
self.ope.pk
self.operation_number = models.Operation.objects.count()
@@ -734,6 +754,8 @@ class OperationWizardDeleteTest(OperationWizardCreationTest):
def post_wizard(self):
self.assertEqual(self.operation_number - 1,
models.Operation.objects.count())
+ # associated parcel removed
+ self.assertEqual(self.parcel_nb - 1, models.Parcel.objects.count())
class OperationWizardClosingTest(OperationWizardCreationTest):