diff options
Diffstat (limited to 'archaeological_context_records/tests.py')
-rw-r--r-- | archaeological_context_records/tests.py | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py index b613b837e..b64754ad6 100644 --- a/archaeological_context_records/tests.py +++ b/archaeological_context_records/tests.py @@ -352,6 +352,21 @@ 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 @@ -558,22 +573,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 +614,14 @@ class ContextRecordWizardCreationTest(WizardTest, ContextRecordInit, TestCase): label="Test").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 +630,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) |