summaryrefslogtreecommitdiff
path: root/archaeological_finds/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_finds/tests.py')
-rw-r--r--archaeological_finds/tests.py69
1 files changed, 27 insertions, 42 deletions
diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py
index 23c6e9fa2..b7c2dd636 100644
--- a/archaeological_finds/tests.py
+++ b/archaeological_finds/tests.py
@@ -63,7 +63,6 @@ from ishtar_common.models import (
from archaeological_operations.models import AdministrativeAct
from archaeological_context_records.models import (
Period,
- Dating,
ContextRecord,
DatingType,
DatingQuality,
@@ -331,9 +330,6 @@ class FindWizardCreationTest(WizardTest, FindInit, TestCase):
def post_wizard(self):
self.assertEqual(models.BaseFind.objects.count(), self.basefind_number + 1)
self.assertEqual(models.Find.objects.count(), self.find_number + 1)
- # identical datings, only one should be finaly save
- f = models.Find.objects.order_by("-pk").all()[0]
- self.assertEqual(f.datings.count(), 1)
class FindWizardModificationTest(WizardTest, FindInit, TestCase):
@@ -356,13 +352,6 @@ class FindWizardModificationTest(WizardTest, FindInit, TestCase):
"checked": "NC",
"check_date": "2016-01-01",
},
- "dating-find_modification": [
- {
- "period": None,
- "start_date": "",
- "end_date": "",
- },
- ],
},
ignored=[
"preservation-find_modification",
@@ -393,12 +382,6 @@ class FindWizardModificationTest(WizardTest, FindInit, TestCase):
self.period = Period.objects.all()[0]
self.period2 = Period.objects.all()[1]
- find.datings.add(
- Dating.objects.create(period=self.period, start_date="0", end_date="200")
- )
- find.datings.add(Dating.objects.create(period=self.period2))
-
- data["dating-find_modification"][0]["period"] = self.period.pk
self.find_number = models.Find.objects.count()
self.basefind_number = models.BaseFind.objects.count()
super(FindWizardModificationTest, self).pre_wizard()
@@ -407,12 +390,7 @@ class FindWizardModificationTest(WizardTest, FindInit, TestCase):
# no creation
self.assertEqual(models.BaseFind.objects.count(), self.basefind_number)
self.assertEqual(models.Find.objects.count(), self.find_number)
- f = models.Find.objects.get(pk=self.find.pk)
- self.assertEqual(f.datings.count(), 1)
- dating = f.datings.all()[0]
- self.assertEqual(dating.period, self.period)
- self.assertEqual(dating.end_date, None)
- self.assertEqual(dating.start_date, None)
+ models.Find.objects.get(pk=self.find.pk)
class FindWizardDeletionWithWarehouseModTest(WizardTest, FindInit, TestCase):
@@ -1536,12 +1514,11 @@ class FindSearchTest(FindInit, TestCase, SearchText):
neo = Period.objects.get(txt_idx="neolithic")
final_neo = Period.objects.get(txt_idx="final-neolithic")
recent_neo = Period.objects.get(txt_idx="recent-neolithic")
- dating = Dating.objects.create(period=final_neo)
- find.datings.add(dating)
find = models.Find.objects.get(pk=find.pk)
+ find.periods.add(final_neo)
find.save()
- search = {"datings__period": final_neo.pk}
+ search = {"periods": final_neo.pk}
# no result when no authentication
response = c.get(reverse("get-find"), search)
@@ -1556,19 +1533,19 @@ class FindSearchTest(FindInit, TestCase, SearchText):
self.assertEqual(res["rows"][0]["cached_periods"], str(final_neo))
# no result for the brother
- search = {"datings__period": recent_neo.pk}
+ search = {"periods": recent_neo.pk}
response = c.get(reverse("get-find"), search)
self.assertEqual(response.status_code, 200)
self.assertEqual(json.loads(response.content.decode())["recordsTotal"], 0)
# one result for the father
- search = {"datings__period": neo.pk}
+ search = {"periods": neo.pk}
response = c.get(reverse("get-find"), search)
self.assertEqual(response.status_code, 200)
self.assertEqual(json.loads(response.content.decode())["recordsTotal"], 1)
# test on text search
- period_key = str(pgettext_lazy("key for text search", "datings-period"))
+ period_key = str(pgettext_lazy("key for text search", "period"))
result = [
('{}="{}"'.format(period_key, str(final_neo)), 1),
('{}="{}"'.format(period_key, str(recent_neo)), 0),
@@ -1788,8 +1765,7 @@ class FindSearchTest(FindInit, TestCase, SearchText):
find = self.finds[0]
find2 = self.finds[1]
- dating = Dating.objects.create(period=final_neo)
- find.datings.add(dating)
+ models.FindDating.objects.create(period=final_neo, find=find)
find.material_types.add(iron_metal)
find2.material_types.add(iron_metal)
find = models.Find.objects.get(pk=find.pk)
@@ -2353,8 +2329,8 @@ class FindQATest(FindInit, TestCase):
)
if response.status_code != 200:
self.assertRedirects(response, "/success/")
- self.assertIn(period, [dating.period.pk for dating in find_0.datings.all()])
- self.assertIn(period, [dating.period.pk for dating in find_1.datings.all()])
+ self.assertIn(period, [period.pk for period in find_0.periods.all()])
+ self.assertIn(period, [period.pk for period in find_1.periods.all()])
self.assertEqual(
models.Find.objects.get(pk=find_0.pk).description,
base_desc_0 + "\n" + extra_desc,
@@ -2600,6 +2576,9 @@ class FindHistoryTest(FindInit, TestCase):
self.client.login(username=self.username, password=self.password)
def _add_datings(self, find):
+ find.periods.add(Period.objects.get(txt_idx="neolithic"))
+ find.periods.add(Period.objects.get(txt_idx="paleolithic"))
+ find.save()
d1_attrs = {
"period": Period.objects.get(txt_idx="neolithic"),
"start_date": 5000,
@@ -2607,15 +2586,17 @@ class FindHistoryTest(FindInit, TestCase):
"dating_type": DatingType.objects.get(txt_idx="from_absolute_dating"),
"quality": DatingQuality.objects.get(txt_idx="sure"),
"precise_dating": "Blah !!!",
+ "find": find
}
- d1 = Dating.objects.create(**d1_attrs)
+ models.FindDating.objects.create(**d1_attrs)
d2_attrs = {
"period": Period.objects.get(txt_idx="paleolithic"),
+ "find": find
}
- d2 = Dating.objects.create(**d2_attrs)
+ models.FindDating.objects.create(**d2_attrs)
d1_dct, d2_dct = {}, {}
- for k in Dating.HISTORY_ATTR:
+ for k in models.FindDating.HISTORY_ATTR:
for dct, attr in ((d1_dct, d1_attrs), (d2_dct, d2_attrs)):
if k in attr:
if hasattr(attr[k], "txt_idx"):
@@ -2625,8 +2606,6 @@ class FindHistoryTest(FindInit, TestCase):
else:
dct[k] = ""
- find.datings.add(d1)
- find.datings.add(d2)
return d1_dct, d2_dct
def test_m2m_history_save(self):
@@ -2704,7 +2683,7 @@ class FindHistoryTest(FindInit, TestCase):
if hasattr(find, "skip_history_when_saving"):
delattr(find, "skip_history_when_saving")
find.save()
- find.datings.clear()
+ models.FindDating.objects.filter(pk__isnull=False).delete()
find.material_types.remove(ceram)
def test_m2m_history_display(self):
@@ -2714,6 +2693,9 @@ class FindHistoryTest(FindInit, TestCase):
self._init_m2m(find, user)
find = models.Find.objects.get(pk=find.pk)
+ neo = Period.objects.get(txt_idx="neolithic")
+ find.periods.remove(neo)
+ find.save()
history_date = (
find.history.order_by("-history_date")
.all()[1]
@@ -2725,7 +2707,7 @@ class FindHistoryTest(FindInit, TestCase):
self.assertEqual(response.status_code, 200)
self.assertIn('class="card sheet"', response.content.decode("utf-8"))
content = response.content.decode("utf-8")
- self.assertNotIn(Period.objects.get(txt_idx="neolithic").label, content)
+ self.assertNotIn(neo.label, content)
self.assertNotIn("5001", content)
response = c.get(
@@ -2741,8 +2723,11 @@ class FindHistoryTest(FindInit, TestCase):
content,
msg="ceramic not found in historical sheet",
)
- self.assertIn("5\xa0001", content, msg="5 001 not found in historical sheet")
- self.assertIn(Period.objects.get(txt_idx="neolithic").label, content)
+ # self.assertIn("5\xa0001", content, msg="5 001 not found in historical sheet")
+ self.assertIn(
+ Period.objects.get(txt_idx="neolithic").label,
+ content,
+ msg="Neolithic not found in historical sheet")
def test_m2m_history_restore(self):
user = self.get_default_user()