summaryrefslogtreecommitdiff
path: root/archaeological_finds/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_finds/tests.py')
-rw-r--r--archaeological_finds/tests.py220
1 files changed, 172 insertions, 48 deletions
diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py
index a0a9f0a8a..ac87abc48 100644
--- a/archaeological_finds/tests.py
+++ b/archaeological_finds/tests.py
@@ -17,18 +17,187 @@
# See the file COPYING for details.
+import datetime
+
from django.conf import settings
from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import TestCase
from ishtar_common.models import ImporterType, IshtarUser, ImporterColumn,\
FormaterType, ImportTarget
-from archaeological_finds import models
+from ishtar_common.models import Person
+from archaeological_context_records.models import ContextRecord
+from archaeological_finds import models, views
+from archaeological_warehouse.models import Warehouse, WarehouseType
from archaeological_context_records.tests import ImportContextRecordTest, \
ContextRecordInit
from ishtar_common import forms_common
+from ishtar_common.tests import WizardTest, WizardTestFormData as FormData
+
+
+class FindInit(ContextRecordInit):
+ test_context_records = False
+
+ def create_finds(self, user=None, data_base={}, data={}, force=False):
+ if not getattr(self, 'finds', None):
+ self.finds = []
+ if not getattr(self, 'base_finds', None):
+ self.base_finds = []
+
+ default = {'label': "Base find"}
+ if not data_base.get('history_modifier'):
+ data_base['history_modifier'] = self.get_default_user()
+ if force or not data_base.get('context_record'):
+ data_base['context_record'] = self.get_default_context_record(
+ force=force)
+ default.update(data_base)
+ base_find = models.BaseFind.objects.create(**default)
+ self.base_finds.append(base_find)
+
+ data["history_modifier"] = data_base["history_modifier"]
+ find = models.Find.objects.create(**data)
+ find.base_finds.add(base_find)
+ self.finds.append(find)
+ return self.finds, self.base_finds
+
+ def get_default_find(self, force=False):
+ finds, base_finds = self.create_finds(force=force)
+ if force:
+ return finds[-1], base_finds[-1]
+ return finds[0], base_finds[0]
+
+ def tearDown(self):
+ super(FindInit, self).tearDown()
+ if hasattr(self, 'finds'):
+ for f in self.finds:
+ try:
+ f.delete()
+ except:
+ pass
+ self.finds = []
+ if hasattr(self, 'base_finds'):
+ for f in self.base_finds:
+ try:
+ f.delete()
+ except:
+ pass
+ self.base_find = []
+
+
+class AFindWizardCreationTest(WizardTest, FindInit, TestCase):
+ # TODO: first to be run because of strange init things...
+ fixtures = [settings.ROOT_PATH +
+ '../fixtures/initial_data.json',
+ settings.ROOT_PATH +
+ '../ishtar_common/fixtures/initial_data.json',
+ settings.ROOT_PATH +
+ '../archaeological_files/fixtures/initial_data.json',
+ settings.ROOT_PATH +
+ '../archaeological_operations/fixtures/initial_data-fr.json',
+ settings.ROOT_PATH +
+ '../archaeological_finds/fixtures/initial_data-fr.json',
+ settings.ROOT_PATH +
+ '../archaeological_warehouse/fixtures/initial_data-fr.json',
+ ]
+ url_name = 'find_creation'
+ wizard_name = 'find_wizard'
+ steps = views.find_creation_steps
+ form_datas = [
+ FormData(
+ 'Find creation',
+ form_datas={
+ 'selecrecord-find_creation': {'pk': 1},
+ 'find-find_creation': {
+ 'label': 'hop',
+ 'checked': 'NC',
+ 'check_date': '2016-01-01'
+ },
+ 'dating-find_creation': []
+ },
+ )
+ ]
+
+ def pre_wizard(self):
+ 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.find_number = models.Find.objects.count()
+ self.basefind_number = models.BaseFind.objects.count()
+ super(AFindWizardCreationTest, self).pre_wizard()
+
+ def post_wizard(self):
+ self.assertEqual(models.BaseFind.objects.count(),
+ self.basefind_number + 1)
+ self.assertEqual(models.Find.objects.count(),
+ self.find_number + 1)
+
+
+class ATreatmentWizardCreationTest(WizardTest, FindInit, TestCase):
+ # TODO: first to be run because of strange init things...
+ fixtures = [settings.ROOT_PATH +
+ '../fixtures/initial_data.json',
+ settings.ROOT_PATH +
+ '../ishtar_common/fixtures/initial_data.json',
+ settings.ROOT_PATH +
+ '../archaeological_files/fixtures/initial_data.json',
+ settings.ROOT_PATH +
+ '../archaeological_operations/fixtures/initial_data-fr.json',
+ settings.ROOT_PATH +
+ '../archaeological_finds/fixtures/initial_data-fr.json',
+ settings.ROOT_PATH +
+ '../archaeological_warehouse/fixtures/initial_data-fr.json',
+ ]
+ url_name = 'treatment_creation'
+ wizard_name = 'treatment_wizard'
+ steps = views.treatment_wizard_steps
+ form_datas = [
+ FormData(
+ 'Move treament',
+ form_datas={
+ 'file-treatment_creation': {},
+ 'basetreatment-treatment_creation': {
+ 'treatment_type': 4, # move
+ 'person': 1, # doer
+ 'location': 1, # associated warehouse
+ 'year': 2016,
+ 'target_is_basket': False
+ },
+ 'selecfind-treatment_creation': {
+ 'pk': 1,
+ 'resulting_pk': 1
+ }
+ },
+ ignored=('resultfind-treatment_creation',
+ 'selecbasket-treatment_creation',
+ 'resultfinds-treatment_creation'))
+ ]
+
+ def pre_wizard(self):
+ q = Warehouse.objects.filter(pk=1)
+ if not q.count():
+ warehouse = Warehouse.objects.create(
+ name="default", warehouse_type=WarehouseType.objects.all()[0])
+ warehouse.id = 1
+ warehouse.save()
+ q = Person.objects.filter(pk=1)
+ if not q.count():
+ person = Person.objects.create(name="default")
+ person.id = 1
+ person.save()
+ find, base_find = self.get_default_find(force=True)
+ self.form_datas[0].form_datas['selecfind-treatment_creation'][
+ 'pk'] = find.pk
+ self.form_datas[0].form_datas['selecfind-treatment_creation'][
+ 'resulting_pk'] = find.pk
+ self.treatment_number = models.Treatment.objects.count()
+ super(ATreatmentWizardCreationTest, self).pre_wizard()
+
+ def post_wizard(self):
+ self.assertEqual(models.Treatment.objects.count(),
+ self.treatment_number + 1)
class ImportFindTest(ImportContextRecordTest):
@@ -94,52 +263,6 @@ class ImportFindTest(ImportContextRecordTest):
self.assertEqual(len(images), 1)
-class FindInit(ContextRecordInit):
- test_context_records = False
-
- def create_finds(self, user=None, data_base={}, data={}, force=False):
- if not getattr(self, 'finds', None):
- self.finds = []
- if not getattr(self, 'base_finds', None):
- self.base_finds = []
-
- default = {'label': "Base find"}
- if not data_base.get('history_modifier'):
- data_base['history_modifier'] = self.get_default_user()
- if force or not data_base.get('context_record'):
- data_base['context_record'] = self.get_default_context_record(
- force=force)
- default.update(data_base)
- base_find = models.BaseFind.objects.create(**default)
- self.base_finds.append(base_find)
-
- data["history_modifier"] = data_base["history_modifier"]
- find = models.Find.objects.create(**data)
- find.base_finds.add(base_find)
- self.finds.append(find)
- return self.finds, self.base_finds
-
- def get_default_find(self):
- return self.create_finds()[0]
-
- def tearDown(self):
- super(FindInit, self).tearDown()
- if hasattr(self, 'finds'):
- for f in self.finds:
- try:
- f.delete()
- except:
- pass
- self.finds = []
- if hasattr(self, 'base_finds'):
- for f in self.base_finds:
- try:
- f.delete()
- except:
- pass
- self.base_find = []
-
-
class FindTest(FindInit, TestCase):
fixtures = [settings.ROOT_PATH +
'../fixtures/initial_data.json',
@@ -201,12 +324,13 @@ class PackagingTest(FindInit, TestCase):
def testPackaging(self):
treatment_type = models.TreatmentType.objects.get(txt_idx='packaging')
- treatment = models.Treatment(treatment_type=treatment_type)
+ treatment = models.Treatment()
items_nb = models.Find.objects.count()
treatment.save(user=self.get_default_user(), items=self.basket)
self.assertEqual(items_nb + self.basket.items.count(),
models.Find.objects.count(),
msg="Packaging doesn't generate enough new finds")
+ treatment.treatment_types.add(treatment_type)
# new version of the find is in the basket
for item in self.basket.items.all():
self.assertNotIn(