diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-01-10 15:51:32 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-01-11 17:30:46 +0100 |
commit | ca1bdab53b4f8a688f2eaee73ee54e44489563f1 (patch) | |
tree | cdb95e6403d2c729a30aac692321dfa5fb0a0a22 /archaeological_finds/tests.py | |
parent | 9d718981e677bfa60cb4597dcf5af3376622d1df (diff) | |
download | Ishtar-ca1bdab53b4f8a688f2eaee73ee54e44489563f1.tar.bz2 Ishtar-ca1bdab53b4f8a688f2eaee73ee54e44489563f1.zip |
Fix datings M2M history
Diffstat (limited to 'archaeological_finds/tests.py')
-rw-r--r-- | archaeological_finds/tests.py | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py index ba53719bd..cefeb1649 100644 --- a/archaeological_finds/tests.py +++ b/archaeological_finds/tests.py @@ -827,16 +827,7 @@ class FindHistoryTest(FindInit, TestCase): self.client = Client() self.client.login(username=self.username, password=self.password) - def test_m2m_history_save(self): - find = self.finds[0] - user = self.get_default_user() - nb_hist = find.history.count() - - ceram = models.MaterialType.objects.get(txt_idx='ceramic').pk - glass = models.MaterialType.objects.get(txt_idx='glass').pk - find.material_types.add(ceram) - find.material_types.add(glass) - + def _add_datings(self, find): d1_attrs = { "period": Period.objects.get(txt_idx='neolithic'), "start_date": 5000, @@ -865,6 +856,18 @@ class FindHistoryTest(FindInit, TestCase): d2 = Dating.objects.create(**d2_attrs) find.datings.add(d1) find.datings.add(d2) + return d1_txt, d2_txt + + def test_m2m_history_save(self): + find = self.finds[0] + user = self.get_default_user() + nb_hist = find.history.count() + + ceram = models.MaterialType.objects.get(txt_idx='ceramic').pk + glass = models.MaterialType.objects.get(txt_idx='glass').pk + find.material_types.add(ceram) + find.material_types.add(glass) + d1_txt, d2_txt = self._add_datings(find) find = models.Find.objects.get(pk=find.pk) self.assertIn( @@ -884,6 +887,7 @@ class FindHistoryTest(FindInit, TestCase): find = models.Find.objects.get(pk=find.pk) find.material_types.remove(ceram) + find.datings.clear() find.label = "hop hop hop2" find.history_modifier = user if hasattr(find, 'skip_history_when_saving'): @@ -893,6 +897,7 @@ class FindHistoryTest(FindInit, TestCase): find = models.Find.objects.get(pk=find.pk) self.assertEqual(find.historical_material_types, 'glass') + self.assertEqual(find.historical_datings, "") self.assertEqual(find.history.count(), nb_hist + 2) self.assertEqual(find.history.all()[1].historical_material_types, historical_material_types) @@ -909,6 +914,7 @@ class FindHistoryTest(FindInit, TestCase): glass = models.MaterialType.objects.get(txt_idx='glass').pk find.material_types.add(ceram) find.material_types.add(glass) + self._add_datings(find) find.history_modifier = user find.label = "hop hop hop1" find._force_history = True @@ -920,6 +926,7 @@ class FindHistoryTest(FindInit, TestCase): find.material_types.remove(ceram) find.history_modifier = user find.label = "hop hop hop2" + find.datings.clear() find._force_history = True if hasattr(find, 'skip_history_when_saving'): delattr(find, 'skip_history_when_saving') @@ -930,22 +937,29 @@ class FindHistoryTest(FindInit, TestCase): '%Y-%m-%dT%H:%M:%S.%f') c.login(username=self.username, password=self.password) - response = c.get(reverse('show-historized-find', + response = c.get(reverse('show-find', kwargs={'pk': find.pk})) self.assertEqual(response.status_code, 200) self.assertIn('class="card sheet"', response.content) + content = response.content.decode('utf-8') self.assertNotIn( models.MaterialType.objects.get(txt_idx='ceramic').label, - response.content.decode('utf-8')) + content) + self.assertNotIn( + Period.objects.get(txt_idx='neolithic').label, content) + self.assertNotIn("5001", content) response = c.get(reverse('show-historized-find', kwargs={'pk': find.pk, 'date': history_date})) self.assertEqual(response.status_code, 200) self.assertIn('class="card sheet"', response.content) + content = response.content.decode('utf-8') self.assertIn( - models.MaterialType.objects.get(txt_idx='ceramic').label, - response.content.decode('utf-8')) + models.MaterialType.objects.get(txt_idx='ceramic').label, content) + self.assertIn("5001", content) + self.assertIn( + Period.objects.get(txt_idx='neolithic').label, content) def test_m2m_history_restore(self): pass |