diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-01-07 12:06:07 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-01-11 17:30:46 +0100 |
commit | d63d253ef98c19c10a83699e5d4345171c39f590 (patch) | |
tree | c2d3b328e45b85a4440c7ad4cc8cd6e781c18a2f /archaeological_finds/tests.py | |
parent | 5c110f503d9dc6ef956b1f12d2220be9cd528fb1 (diff) | |
download | Ishtar-d63d253ef98c19c10a83699e5d4345171c39f590.tar.bz2 Ishtar-d63d253ef98c19c10a83699e5d4345171c39f590.zip |
Tests: M2M history on finds - save and display
Diffstat (limited to 'archaeological_finds/tests.py')
-rw-r--r-- | archaeological_finds/tests.py | 85 |
1 files changed, 82 insertions, 3 deletions
diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py index 876bbecb2..107240389 100644 --- a/archaeological_finds/tests.py +++ b/archaeological_finds/tests.py @@ -35,6 +35,7 @@ from archaeological_finds import models, views from archaeological_warehouse.models import Warehouse, WarehouseType from ishtar_common import forms_common +from ishtar_common.utils import HISTORY_M2M_SPLIT from ishtar_common.tests import WizardTest, WizardTestFormData as FormData, \ TestCase, create_user, create_superuser @@ -821,16 +822,94 @@ class FindHistoryTest(FindInit, TestCase): def setUp(self): self.create_finds(data_base={"label": u"Find 1"}, force=True) - self.create_finds(data_base={"label": u"Find 2"}, force=True) self.username, self.password, self.user = create_superuser() self.client = Client() self.client.login(username=self.username, password=self.password) def test_m2m_history_save(self): - pass + 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) + find = models.Find.objects.get(pk=find.pk) + self.assertIn( + find.historical_material_types, + [HISTORY_M2M_SPLIT.join(['ceramic', 'glass']), # order do not + HISTORY_M2M_SPLIT.join(['glass', 'ceramic'])]) # matter + historical_material_types = find.historical_material_types + find.label = "hop hop hop1" + find.history_modifier = user + find._force_history = True + find.save() + + find = models.Find.objects.get(pk=find.pk) + find.material_types.remove(ceram) + find.label = "hop hop hop2" + find.history_modifier = user + if hasattr(find, 'skip_history_when_saving'): + delattr(find, 'skip_history_when_saving') + find._force_history = True + find.save() + + find = models.Find.objects.get(pk=find.pk) + self.assertEqual(find.historical_material_types, 'glass') + self.assertEqual(find.history.count(), nb_hist + 2) + self.assertEqual(find.history.all()[1].historical_material_types, + historical_material_types) + self.assertEqual(find.history.all()[0].historical_material_types, + "glass") def test_m2m_history_display(self): - pass + c = Client() + user = self.get_default_user() + find = self.finds[0] + + find = models.Find.objects.get(pk=find.pk) + 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) + find.history_modifier = user + find.label = "hop hop hop1" + find._force_history = True + if hasattr(find, 'skip_history_when_saving'): + delattr(find, 'skip_history_when_saving') + find.save() + + find = models.Find.objects.get(pk=find.pk) + find.material_types.remove(ceram) + find.history_modifier = user + find.label = "hop hop hop2" + find._force_history = True + if hasattr(find, 'skip_history_when_saving'): + delattr(find, 'skip_history_when_saving') + find.save() + + find = models.Find.objects.get(pk=find.pk) + history_date = find.history.all()[1].history_date.strftime( + '%Y-%m-%dT%H:%M:%S.%f') + + c.login(username=self.username, password=self.password) + response = c.get(reverse('show-historized-find', + kwargs={'pk': find.pk})) + self.assertEqual(response.status_code, 200) + self.assertIn('class="card sheet"', response.content) + self.assertNotIn( + models.MaterialType.objects.get(txt_idx='ceramic').label, + response.content.decode('utf-8')) + + 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) + self.assertIn( + models.MaterialType.objects.get(txt_idx='ceramic').label, + response.content.decode('utf-8')) def test_m2m_history_restore(self): pass |