summaryrefslogtreecommitdiff
path: root/archaeological_operations/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_operations/tests.py')
-rw-r--r--archaeological_operations/tests.py77
1 files changed, 72 insertions, 5 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index 5eeeb1808..a8d627dd5 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
+ ImporterType, IshtarUser, TargetKey, IshtarSiteProfile
from ishtar_common import forms_common
from ishtar_common.tests import WizardTest, create_superuser, create_user
@@ -467,11 +467,10 @@ class OperationInitTest(object):
return self.towns
def get_default_town(self):
- town = getattr(self, 'towns', None)
- if not town:
+ towns = getattr(self, 'towns', None)
+ if not towns:
self.create_towns()
- town = self.towns[0]
- return town
+ return self.towns[0]
def create_parcel(self, data={}):
default = {'town': self.get_default_town(),
@@ -498,6 +497,28 @@ class OperationInitTest(object):
def get_default_operation(self):
return self.create_operation()[0]
+ def tearDown(self):
+ # cleanup for further test
+ if hasattr(self, 'user'):
+ self.user.delete()
+ self.user = None
+ # all try/except is necessary for bad migrations on master...
+ # should be removed at the next big version
+ if hasattr(self, 'operations'):
+ for ope in self.operations:
+ try:
+ ope.delete()
+ except:
+ pass
+ self.operations = []
+ if hasattr(self, 'parcels'):
+ for p in self.parcels:
+ try:
+ p.delete()
+ except:
+ pass
+ self.parcels = []
+
class OperationTest(TestCase, OperationInitTest):
fixtures = [settings.ROOT_PATH +
@@ -510,6 +531,7 @@ class OperationTest(TestCase, OperationInitTest):
'../archaeological_operations/fixtures/initial_data-fr.json']
def setUp(self):
+ IshtarSiteProfile.objects.create()
self.username, self.password, self.user = create_superuser()
self.alt_username, self.alt_password, self.alt_user = create_user()
self.alt_user.user_permissions.add(Permission.objects.get(
@@ -519,6 +541,26 @@ class OperationTest(TestCase, OperationInitTest):
self.operations += self.create_operation(self.alt_user, self.orgas[0])
self.item = self.operations[0]
+ def testExternalID(self):
+ self.item.code_patriarche = '123456789'
+ self.item.save()
+ parcel = self.get_default_parcel()
+ parcel.operation = self.item
+ parcel.save()
+ correct_ext_id = u"{}-{}-{}{}".format(
+ self.item.code_patriarche, parcel.town.numero_insee,
+ parcel.section, parcel.parcel_number)
+ self.assertEqual(parcel.external_id, correct_ext_id)
+ # auto has been previously set
+ parcel.external_id = 'blabla'
+ parcel.save()
+ self.assertEqual(parcel.external_id, correct_ext_id)
+ # deactivate auto
+ parcel.auto_external_id = False
+ parcel.external_id = 'blabla'
+ parcel.save()
+ self.assertEqual(parcel.external_id, 'blabla')
+
def testSearch(self):
c = Client()
response = c.get(reverse('get-operation'), {'year': '2010'})
@@ -650,6 +692,31 @@ class OperationWizardCreationTest(WizardTest, OperationInitTest, TestCase):
self.operation_number + 1)
+class OperationWizardClosingTest(OperationWizardCreationTest):
+ fixtures = OperationWizardCreationTest.fixtures
+ url_name = 'operation_closing'
+ wizard_name = 'operation_closing_wizard'
+ steps = views.operation_closing_steps
+ form_datas = [[
+ {
+ 'selec-operation_closing': {'pk': None},
+ 'date-operation_closing': {'end_date': '2016-01-01'},
+ }, []]]
+
+ def pre_wizard(self):
+ self.ope = self.get_default_operation()
+ self.form_datas[0][0]['selec-operation_closing']['pk'] = self.ope.pk
+ self.assertTrue(self.ope.is_active())
+ super(OperationWizardClosingTest, self).pre_wizard()
+
+ def post_wizard(self):
+ ope = models.Operation.objects.get(pk=self.ope.pk)
+ self.assertFalse(ope.is_active())
+ self.assertEqual(
+ ope.closing()['date'].strftime('%Y-%d-%m'),
+ self.form_datas[0][0]['date-operation_closing']['end_date'])
+
+
class OperationAdminActWizardCreationTest(WizardTest, OperationInitTest,
TestCase):
fixtures = [settings.ROOT_PATH +