diff options
Diffstat (limited to 'archaeological_operations/tests.py')
-rw-r--r-- | archaeological_operations/tests.py | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index d8399eedb..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, \ @@ -578,8 +578,7 @@ class OperationTest(TestCase, OperationInitTest): {'operator': self.orgas[0].pk}) self.assertTrue(json.loads(response.content)['total'] == 2) - def testRelatedSearch(self): - c = Client() + def create_relations(self): rel1 = models.RelationType.objects.create( symmetrical=True, label='Include', txt_idx='include') rel2 = models.RelationType.objects.create( @@ -589,6 +588,11 @@ class OperationTest(TestCase, OperationInitTest): left_record=self.operations[0], right_record=self.operations[1], relation_type=rel1) + return rel1, rel2 + + def testRelatedSearch(self): + c = Client() + rel1, rel2 = self.create_relations() self.operations[1].year = 2011 self.operations[1].save() search = {'year': '2010', 'relation_types_0': rel2.pk} @@ -599,6 +603,28 @@ class OperationTest(TestCase, OperationInitTest): response = c.get(reverse('get-operation'), search) self.assertTrue(json.loads(response.content)['total'] == 2) + 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'}) @@ -718,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() @@ -726,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): |