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.py85
1 files changed, 80 insertions, 5 deletions
diff --git a/archaeological_warehouse/tests.py b/archaeological_warehouse/tests.py
index 73cc166ac..3f4df9fad 100644
--- a/archaeological_warehouse/tests.py
+++ b/archaeological_warehouse/tests.py
@@ -17,14 +17,13 @@
# See the file COPYING for details.
-from django.conf import settings
-
from archaeological_finds.tests import FindInit
from ishtar_common.tests import WizardTest, WizardTestFormData as FormData, \
TestCase
from archaeological_finds.tests import WAREHOUSE_FIXTURES
+from ishtar_common.models import IshtarSiteProfile, SpatialReferenceSystem
from archaeological_warehouse import models, views, forms
@@ -189,7 +188,7 @@ class WarehouseTest(TestCase):
class ContainerTest(FindInit, TestCase):
fixtures = WAREHOUSE_FIXTURES
- def testFormCreation(self):
+ def test_form_creation(self):
main_warehouse = models.Warehouse.objects.create(
name="Main",
warehouse_type=models.WarehouseType.objects.all()[0]
@@ -208,7 +207,7 @@ class ContainerTest(FindInit, TestCase):
self.assertEqual(models.Container.objects.count(),
self.container_number + 1)
- def testChangeLocation(self):
+ def test_change_location(self):
main_warehouse = models.Warehouse.objects.create(
name="Main",
warehouse_type=models.WarehouseType.objects.all()[0]
@@ -222,13 +221,17 @@ class ContainerTest(FindInit, TestCase):
location=main_warehouse,
container_type=models.ContainerType.objects.all()[0]
)
+ container.save()
+ container = models.Container.objects.get(pk=container.pk)
+ self.assertIn(main_warehouse.name, container.cached_location)
+
models.ContainerLocalisation.objects.create(
container=container, division=div_link,
)
self.assertTrue(models.ContainerLocalisation.objects.filter(
division__warehouse=main_warehouse).count())
- # changing location remove unrelevent localisation
+ # changing location remove irrelevant localisation
other_warehouse = models.Warehouse.objects.create(
name="Other",
warehouse_type=models.WarehouseType.objects.all()[0]
@@ -238,3 +241,75 @@ class ContainerTest(FindInit, TestCase):
self.assertFalse(models.ContainerLocalisation.objects.filter(
division__warehouse=main_warehouse).count())
+ def test_update_containers_on_warehouse_update(self):
+ main_warehouse = models.Warehouse.objects.create(
+ name="Main",
+ warehouse_type=models.WarehouseType.objects.all()[0]
+ )
+ container = models.Container.objects.create(
+ reference="Test", responsible=main_warehouse,
+ location=main_warehouse,
+ container_type=models.ContainerType.objects.all()[0]
+ )
+ container.save()
+ container = models.Container.objects.get(pk=container.pk)
+ self.assertIn(main_warehouse.name, container.cached_location)
+ main_warehouse.name = "New name"
+ main_warehouse.save()
+ self.assertEqual(
+ models.Container.objects.filter(
+ need_update=True
+ ).count(), 1)
+ self.assertEqual(
+ models.Container.objects.filter(
+ pk=container.pk,
+ need_update=True
+ ).count(), 1)
+ container = models.Container.objects.get(pk=container.pk)
+ # process pending update
+ container.skip_history_when_saving = True
+ container._no_move = True
+ container.save()
+ container = models.Container.objects.get(pk=container.pk)
+ self.assertIn("New name", container.cached_location)
+
+ def test_update_container_localisation_on_warehouse_update(self):
+ profile, created = IshtarSiteProfile.objects.get_or_create(
+ slug='default', active=True)
+ profile.mapping = True
+ profile.locate_warehouses = True
+ profile.save()
+ wgs84 = SpatialReferenceSystem.objects.get(srid=4326)
+ main_warehouse = models.Warehouse.objects.create(
+ name="Main",
+ warehouse_type=models.WarehouseType.objects.all()[0],
+ )
+ container = models.Container.objects.create(
+ reference="Test", responsible=main_warehouse,
+ location=main_warehouse,
+ container_type=models.ContainerType.objects.all()[0]
+ )
+ container.save()
+ self.assertEqual(container.x, None)
+
+ main_warehouse = models.Warehouse.objects.get(pk=main_warehouse.pk)
+ main_warehouse.x, main_warehouse.y = 33, 42
+ main_warehouse.spatial_reference_system = wgs84
+ main_warehouse.save()
+ # an update is pending
+ self.assertEqual(
+ models.Container.objects.filter(
+ pk=container.pk,
+ need_update=True
+ ).count(), 1)
+
+ # process pending update
+ container = models.Container.objects.get(pk=container.pk)
+ self.assertEqual(container.x, None) # update has to be done
+ container.skip_history_when_saving = True
+ container._no_move = True
+ container.save()
+
+ container = models.Container.objects.get(pk=container.pk)
+ self.assertEqual(container.x, 33)
+