summaryrefslogtreecommitdiff
path: root/archaeological_finds/tests.py
diff options
context:
space:
mode:
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
commite9f6af279c98260e2bd81d1a4b34f000e9469636 (patch)
treec2d3b328e45b85a4440c7ad4cc8cd6e781c18a2f /archaeological_finds/tests.py
parenta87eb643c09fb8af86c0b7198cccd097eef1aac6 (diff)
downloadIshtar-e9f6af279c98260e2bd81d1a4b34f000e9469636.tar.bz2
Ishtar-e9f6af279c98260e2bd81d1a4b34f000e9469636.zip
Tests: M2M history on finds - save and display
Diffstat (limited to 'archaeological_finds/tests.py')
-rw-r--r--archaeological_finds/tests.py85
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