diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-07-26 14:39:13 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-07-26 14:39:13 +0200 |
commit | 943a35dacc9fdd0e86cf4713c441124d99fafa14 (patch) | |
tree | 8b9cef16c3dc1077b81465029b102391fa6106fa /archaeological_context_records/tests.py | |
parent | 9a7c3c036e1ae743c7ccc00cdc4c9e8499b8578e (diff) | |
parent | 32d85d8604fbdf67644a406e265372e3bb4c8657 (diff) | |
download | Ishtar-943a35dacc9fdd0e86cf4713c441124d99fafa14.tar.bz2 Ishtar-943a35dacc9fdd0e86cf4713c441124d99fafa14.zip |
Merge branch 'master' into develop
Diffstat (limited to 'archaeological_context_records/tests.py')
-rw-r--r-- | archaeological_context_records/tests.py | 64 |
1 files changed, 49 insertions, 15 deletions
diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py index 60fbaa65e..0de30ef31 100644 --- a/archaeological_context_records/tests.py +++ b/archaeological_context_records/tests.py @@ -29,7 +29,7 @@ from django.test.client import Client from ishtar_common.models import IshtarSiteProfile, ImporterModel from archaeological_operations.tests import OperationInitTest, \ - ImportTest, ImportOperationTest + ImportTest, FILE_TOWNS_FIXTURES, FILE_FIXTURES, OPERATION_TOWNS_FIXTURES from archaeological_operations import models as models_ope from archaeological_context_records import models @@ -38,12 +38,19 @@ from ishtar_common.tests import WizardTest, WizardTestFormData as FormData, \ from archaeological_context_records import views -class ImportContextRecordTest(ImportTest, TestCase): +CONTEXT_RECORD_FIXTURES = FILE_FIXTURES + [ + settings.ROOT_PATH + + '../archaeological_context_records/fixtures/initial_data-fr.json', +] - fixtures = ImportOperationTest.fixtures + [ - settings.ROOT_PATH + - '../archaeological_context_records/fixtures/initial_data-fr.json', - ] +CONTEXT_RECORD_TOWNS_FIXTURES = FILE_TOWNS_FIXTURES + [ + settings.ROOT_PATH + + '../archaeological_context_records/fixtures/initial_data-fr.json', +] + + +class ImportContextRecordTest(ImportTest, TestCase): + fixtures = CONTEXT_RECORD_TOWNS_FIXTURES def test_mcc_import_contextrecords(self): old_nb = models.ContextRecord.objects.count() @@ -193,7 +200,7 @@ class ContextRecordInit(OperationInitTest): class ExportTest(ContextRecordInit, TestCase): - fixtures = ImportContextRecordTest.fixtures + fixtures = CONTEXT_RECORD_TOWNS_FIXTURES def setUp(self): self.username, self.password, self.user = create_superuser() @@ -222,7 +229,7 @@ class ExportTest(ContextRecordInit, TestCase): class ContextRecordTest(ContextRecordInit, TestCase): - fixtures = ImportContextRecordTest.fixtures + fixtures = CONTEXT_RECORD_TOWNS_FIXTURES def setUp(self): IshtarSiteProfile.objects.create() @@ -352,9 +359,24 @@ class ContextRecordTest(ContextRecordInit, TestCase): self.assertEqual(response.status_code, 200) self.assertIn('class="sheet"', response.content) + def test_redundant_dating_clean(self): + obj = self.context_records[0] + values = {'period': models.Period.objects.all()[0]} + values_2 = {'period': models.Period.objects.all()[0], + 'quality': models.DatingQuality.objects.all()[0]} + + obj.datings.add(models.Dating.objects.create(**values)) + obj.datings.add(models.Dating.objects.create(**values)) + obj.datings.add(models.Dating.objects.create(**values_2)) + obj.datings.add(models.Dating.objects.create(**values_2)) + self.assertEqual(obj.datings.count(), 4) + obj.fix() + self.assertEqual(obj.datings.count(), 2) + + class ContextRecordSearchTest(ContextRecordInit, TestCase): - fixtures = ImportContextRecordTest.fixtures + fixtures = CONTEXT_RECORD_TOWNS_FIXTURES def setUp(self): IshtarSiteProfile.objects.create() @@ -496,7 +518,7 @@ class ContextRecordSearchTest(ContextRecordInit, TestCase): class RecordRelationsTest(ContextRecordInit, TestCase): - fixtures = ImportOperationTest.fixtures + fixtures = OPERATION_TOWNS_FIXTURES model = models.ContextRecord def setUp(self): @@ -546,7 +568,7 @@ class RecordRelationsTest(ContextRecordInit, TestCase): class ContextRecordWizardCreationTest(WizardTest, ContextRecordInit, TestCase): - fixtures = ImportOperationTest.fixtures + fixtures = OPERATION_TOWNS_FIXTURES url_name = 'record_creation' wizard_name = 'record_wizard' steps = views.record_creation_steps @@ -558,22 +580,23 @@ class ContextRecordWizardCreationTest(WizardTest, ContextRecordInit, TestCase): 'general': { 'label': "First" }, - 'relations': [] + 'relations': [], }, ignored=('datings', 'interpretation', ) ), FormData( - "Create a context record with a relation", + "Create a context record with a relation and datings", form_datas={ 'selec': {}, 'general': { 'label': "Second" }, - 'relations': [] + 'relations': [], + 'datings': [] }, - ignored=('datings', 'interpretation',) + ignored=('interpretation',) ), ] @@ -598,6 +621,14 @@ class ContextRecordWizardCreationTest(WizardTest, ContextRecordInit, TestCase): label="Test", symmetrical=False).pk} ) + period = models.Period.objects.all()[0].pk + self.form_datas[1].append( + 'datings', {'period': period} + ) + self.form_datas[1].append( + 'datings', {'period': period} + ) + self.cr_nb = models.ContextRecord.objects.count() super(ContextRecordWizardCreationTest, self).pre_wizard() @@ -606,3 +637,6 @@ class ContextRecordWizardCreationTest(WizardTest, ContextRecordInit, TestCase): self.cr_nb + 2) self.assertEqual(self.related_cr.left_relations.count(), 1) + # identical datings, only one should be finaly save + cr = models.ContextRecord.objects.order_by('-pk')[0] + self.assertEqual(cr.datings.count(), 1) |