diff options
Diffstat (limited to 'archaeological_finds/tests.py')
-rw-r--r-- | archaeological_finds/tests.py | 76 |
1 files changed, 69 insertions, 7 deletions
diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py index 1268b4f03..3d33cf693 100644 --- a/archaeological_finds/tests.py +++ b/archaeological_finds/tests.py @@ -28,7 +28,7 @@ from django.test.client import Client from ishtar_common.models import ImporterType, IshtarUser, ImporterColumn,\ FormaterType, ImportTarget -from ishtar_common.models import Person +from ishtar_common.models import Person, get_current_profile from archaeological_context_records.models import Period, Dating from archaeological_finds import models, views from archaeological_warehouse.models import Warehouse, WarehouseType @@ -91,7 +91,7 @@ class FindInit(ContextRecordInit): self.base_find = [] -class AFindWizardCreationTest(WizardTest, FindInit, TestCase): +class FindWizardCreationTest(WizardTest, FindInit, TestCase): # TODO: first to be run because of strange init things... fixtures = [settings.ROOT_PATH + '../fixtures/initial_data.json', @@ -134,12 +134,13 @@ class AFindWizardCreationTest(WizardTest, FindInit, TestCase): cr = self.create_context_record( data={'parcel': self.create_parcel()[-1]}, force=True)[-1] - self.form_datas[0].form_datas['selecrecord-find_creation']['pk'] = cr.pk + self.form_datas[0].form_datas['selecrecord-find_creation']['pk'] = \ + cr.pk self.form_datas[0].form_datas['dating-find_creation'][0]['period'] = \ Period.objects.all()[0].pk self.find_number = models.Find.objects.count() self.basefind_number = models.BaseFind.objects.count() - super(AFindWizardCreationTest, self).pre_wizard() + super(FindWizardCreationTest, self).pre_wizard() def post_wizard(self): self.assertEqual(models.BaseFind.objects.count(), @@ -148,8 +149,7 @@ class AFindWizardCreationTest(WizardTest, FindInit, TestCase): self.find_number + 1) -class ATreatmentWizardCreationTest(WizardTest, FindInit, TestCase): - # TODO: first to be run because of strange init things... +class TreatmentWizardCreationTest(WizardTest, FindInit, TestCase): fixtures = [settings.ROOT_PATH + '../fixtures/initial_data.json', settings.ROOT_PATH + @@ -206,7 +206,7 @@ class ATreatmentWizardCreationTest(WizardTest, FindInit, TestCase): self.form_datas[0].form_datas['selecfind-treatment_creation'][ 'resulting_pk'] = self.find.pk self.treatment_number = models.Treatment.objects.count() - super(ATreatmentWizardCreationTest, self).pre_wizard() + super(TreatmentWizardCreationTest, self).pre_wizard() def post_wizard(self): self.assertEqual(models.Treatment.objects.count(), @@ -312,6 +312,68 @@ class FindTest(FindInit, TestCase): base_find.context_record.external_id, base_find.label)) + def testIndex(self): + profile = get_current_profile() + profile.find_index = u"O" + profile.save() + profile = get_current_profile(force=True) + + op1 = self.create_operation()[-1] + op2 = self.create_operation()[-1] + op1_cr1 = self.create_context_record(data={'label': "CR1", + 'operation': op1})[-1] + op1_cr2 = self.create_context_record(data={'label': "CR2", + 'operation': op1})[-1] + op2_cr1 = self.create_context_record(data={'label': "CR3", + 'operation': op2})[-1] + self.create_finds(data_base={'context_record': op1_cr1}) + find_1 = self.finds[-1] + bf_1 = models.BaseFind.objects.get(pk=self.base_finds[-1].pk) + self.assertEqual(find_1.index, 1) + self.assertEqual(bf_1.index, 1) + + # index is based on operations + self.create_finds(data_base={'context_record': op1_cr2}) + find_2 = self.finds[-1] + bf_2 = models.BaseFind.objects.get(pk=self.base_finds[-1].pk) + self.assertEqual(find_2.index, 2) + self.assertEqual(bf_2.index, 2) + + self.create_finds(data_base={'context_record': op2_cr1}) + find_3 = self.finds[-1] + bf_3 = models.BaseFind.objects.get(pk=self.base_finds[-1].pk) + self.assertEqual(find_3.index, 1) + self.assertEqual(bf_3.index, 1) + + profile = get_current_profile(force=True) + profile.find_index = u"CR" + profile.save() + profile = get_current_profile(force=True) + + op3 = self.create_operation()[-1] + op3_cr1 = self.create_context_record(data={'label': "CR1", + 'operation': op3})[-1] + op3_cr2 = self.create_context_record(data={'label': "CR2", + 'operation': op3})[-1] + self.create_finds(data_base={'context_record': op3_cr1}) + find_1b = self.finds[-1] + bf_1b = models.BaseFind.objects.get(pk=self.base_finds[-1].pk) + self.assertEqual(find_1b.index, 1) + self.assertEqual(bf_1b.index, 1) + + # index now based on context records + self.create_finds(data_base={'context_record': op3_cr2}) + find_2b = self.finds[-1] + bf_2b = models.BaseFind.objects.get(pk=self.base_finds[-1].pk) + self.assertEqual(find_2b.index, 1) + self.assertEqual(bf_2b.index, 1) + + self.create_finds(data_base={'context_record': op3_cr2}) + find_3b = self.finds[-1] + bf_3b = models.BaseFind.objects.get(pk=self.base_finds[-1].pk) + self.assertEqual(find_3b.index, 2) + self.assertEqual(bf_3b.index, 2) + def testShowFind(self): find = self.finds[0] response = self.client.get(reverse('display-find', args=[find.pk])) |