summaryrefslogtreecommitdiff
path: root/archaeological_warehouse/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_warehouse/tests.py')
-rw-r--r--archaeological_warehouse/tests.py70
1 files changed, 63 insertions, 7 deletions
diff --git a/archaeological_warehouse/tests.py b/archaeological_warehouse/tests.py
index 382efb769..bc31d0ba6 100644
--- a/archaeological_warehouse/tests.py
+++ b/archaeological_warehouse/tests.py
@@ -631,9 +631,12 @@ class ContainerQATest(FindInit, TestCase):
def test_move(self):
c = Client()
- find_0 = self.finds[0]
+ find_0 = Find.objects.get(pk=self.finds[0].pk)
find_0.container = self.container_3
+ find_0.container_ref = self.container_3
find_0.save()
+ find = Find.objects.get(pk=find_0.pk)
+ self.assertTrue(find.container_fisrt_full_location)
pks_1 = f"{self.container_3.pk}-{self.container_4.pk}"
pks_2 = str(self.container_1.pk)
@@ -656,18 +659,33 @@ class ContainerQATest(FindInit, TestCase):
packaging = TreatmentType.objects.get(txt_idx="packaging")
- def check_location_of_children():
+ def check_location_of_children(idx):
# check change location of children
container3 = models.Container.objects.get(pk=self.container_3.pk)
self.assertEqual(container3.location, self.alt_warehouse)
container4 = models.Container.objects.get(pk=self.container_4.pk)
self.assertEqual(container4.location, self.alt_warehouse)
- def check_reinit_parent():
+ def check_reinit_parent(idx):
# reinit parent when not provided and location changed
container = models.Container.objects.get(pk=self.container_3.pk)
self.assertEqual(container.parent, None)
+ def init_treatment(find_0):
+ # create a first packaging treatment
+ treat_status = TreatmentStatus.get_completed_state()
+ t = Treatment.objects.create(
+ container=self.container_3,
+ year=2024,
+ start_date=datetime.date(2024, 2, 29),
+ location=self.main_warehouse,
+ treatment_status=treat_status
+ )
+ treat_type = TreatmentType.objects.get(txt_idx="packaging")
+ t.treatment_types.add(treat_type)
+ t.save()
+ t.finds.add(find_0)
+ t.save() # force find container history
data_check_lst = [
(
@@ -677,6 +695,7 @@ class ContainerQATest(FindInit, TestCase):
{"parent": self.container_2},
0,
pks_1,
+ None,
None
),
(
@@ -686,6 +705,7 @@ class ContainerQATest(FindInit, TestCase):
{"location": self.alt_warehouse},
0,
pks_1,
+ None,
None
),
(
@@ -698,10 +718,24 @@ class ContainerQATest(FindInit, TestCase):
{"parent": self.container_2},
2,
pks_1,
+ None,
None
),
(
{
+ "qa-move-qaparent": self.container_2.pk,
+ "qa-move-create_treatment": True,
+ "qa-move-year": 2019,
+ "qa-move-treatment_type": packaging.pk,
+ },
+ {"parent": self.container_2},
+ 2,
+ pks_1,
+ None,
+ init_treatment
+ ),
+ (
+ {
"qa-move-qalocation": self.alt_warehouse.pk,
"qa-move-create_treatment": True,
"qa-move-year": 2019,
@@ -710,6 +744,7 @@ class ContainerQATest(FindInit, TestCase):
{"location": self.alt_warehouse},
2,
pks_1,
+ None,
None
),
(
@@ -719,7 +754,8 @@ class ContainerQATest(FindInit, TestCase):
{"location": self.alt_warehouse},
0,
pks_2,
- check_location_of_children
+ check_location_of_children,
+ None
),
(
{
@@ -728,12 +764,13 @@ class ContainerQATest(FindInit, TestCase):
{"location": self.alt_warehouse},
0,
pks_1,
- check_reinit_parent
+ check_reinit_parent,
+ None
),
]
for idx, lst in enumerate(data_check_lst):
- data, check, nb_treat, pks, extra_check = lst
+ data, check, nb_treat, pks, extra_check, pre_init = lst
# reinit
self.container_1.location = self.main_warehouse
self.container_1.parent = None
@@ -744,6 +781,12 @@ class ContainerQATest(FindInit, TestCase):
self.container_4.location = self.main_warehouse
self.container_4.parent = self.container_1
self.container_4.save()
+ find_0.save()
+ FindTreatment.objects.exclude(id__isnull=True).delete()
+ Treatment.objects.exclude(id__isnull=True).delete()
+
+ if pre_init:
+ pre_init(find_0)
init_nb_treat = Treatment.objects.count()
@@ -758,7 +801,7 @@ class ContainerQATest(FindInit, TestCase):
self.assertEqual(init_nb_treat + nb_treat, final_nb_treat)
if extra_check:
- extra_check()
+ extra_check(idx)
if not final_nb_treat:
self.assertEqual(FindTreatment.objects.filter(find=find_0).count(), 0)
@@ -774,6 +817,19 @@ class ContainerQATest(FindInit, TestCase):
self.assertTrue(ft.full_location)
self.assertTrue(ft.location_type)
+ find = Find.objects.get(pk=find_0.pk)
+ if pre_init:
+ # pre init add a packaging -> first full location is not changed
+ self.assertNotEqual(
+ find.container_fisrt_full_location,
+ find.container.generate_full_location()
+ )
+ else:
+ self.assertEqual(
+ find.container_fisrt_full_location,
+ find.container.generate_full_location()
+ )
+
class ContainerTest(FindInit, TestCase):
fixtures = WAREHOUSE_FIXTURES