diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2020-06-29 15:37:18 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-02-28 12:15:20 +0100 |
commit | a8578dcee5b4cad64ec6e10b1dc5cbfad815b4c8 (patch) | |
tree | d915605d6207355788d69ad9a8e2a3a35d94507d /archaeological_warehouse/tests.py | |
parent | 1d6484bfe6bbdf763f6a9c583115c1c6b3914037 (diff) | |
download | Ishtar-a8578dcee5b4cad64ec6e10b1dc5cbfad815b4c8.tar.bz2 Ishtar-a8578dcee5b4cad64ec6e10b1dc5cbfad815b4c8.zip |
Container - bulk update: remove parent when changing warehouse (refs #4959)
Diffstat (limited to 'archaeological_warehouse/tests.py')
-rw-r--r-- | archaeological_warehouse/tests.py | 104 |
1 files changed, 103 insertions, 1 deletions
diff --git a/archaeological_warehouse/tests.py b/archaeological_warehouse/tests.py index 81b8b3df5..126cc0420 100644 --- a/archaeological_warehouse/tests.py +++ b/archaeological_warehouse/tests.py @@ -19,10 +19,15 @@ import json +from django.contrib.auth.models import Permission +from django.core.urlresolvers import reverse +from django.test.client import Client + from archaeological_finds.tests import FindInit from ishtar_common.tests import WizardTest, WizardTestFormData as FormData, \ - TestCase, WAREHOUSE_FIXTURES, GenericSerializationTest, COMMON_FIXTURES + TestCase, WAREHOUSE_FIXTURES, GenericSerializationTest, COMMON_FIXTURES, \ + create_user from ishtar_common.models import IshtarSiteProfile, SpatialReferenceSystem from archaeological_operations.models import Operation @@ -832,5 +837,102 @@ class ContainerTest(FindInit, TestCase): self.assertEqual(bottom.parent, middle) self.assertEqual(bottom.location, self.main_warehouse) + def test_bulk_update(self): + username, password, user = create_user() + user.user_permissions.add(Permission.objects.get( + codename='change_container')) + client = Client() + + ct = models.ContainerType.objects.all()[0] + ct2 = models.ContainerType.objects.all()[1] + container_parent = models.Container.objects.create( + reference="Parent container", + location=self.main_warehouse, + container_type=ct) + container_parent2 = models.Container.objects.create( + reference="Parent container 2", + location=self.alt_warehouse, + container_type=ct) + + container = models.Container.objects.create( + reference="Test", + location=self.main_warehouse, + parent=container_parent, + container_type=ct2) + + # base modification + url = reverse('container-qa-bulk-update', args=[container.pk]) + data = { + "qacontainer_type": ct.pk, + "qalocation": '', + "qaparent": '' + } + response = client.post(url, data) + self.assertRedirects(response, '/') + client.login(username=username, password=password) + response = client.post(url, data) + self.assertEqual(response.status_code, 200) + confirm_url = reverse( + 'container-qa-bulk-update-confirm', args=[container.pk]) + response = client.post(confirm_url, data) + self.assertRedirects(response, '/success/') + + container = models.Container.objects.get(pk=container.pk) + self.assertEqual(container.container_type_id, ct.pk) + + container.container_type = ct2 + container.save() + + data = { + "qacontainer_type": '', + "qalocation": self.alt_warehouse.pk, + "qaparent": container_parent2.pk + } + response = client.post(confirm_url, data) + self.assertRedirects(response, '/success/') + + container = models.Container.objects.get(pk=container.pk) + self.assertEqual(container.location, self.alt_warehouse) + self.assertEqual(container.parent, container_parent2) + + container.location = self.main_warehouse + container.parent = container_parent + container.save() + + # change location of children + + data = { + "qacontainer_type": '', + "qalocation": self.alt_warehouse.pk, + "qaparent": '' + } + confirm_parent_url = reverse( + 'container-qa-bulk-update-confirm', args=[container_parent.pk]) + response = client.post(confirm_parent_url, data) + self.assertRedirects(response, '/success/') + + container_parent = models.Container.objects.get(pk=container_parent.pk) + self.assertEqual(container_parent.location, self.alt_warehouse) + container = models.Container.objects.get(pk=container.pk) + self.assertEqual(container.location, self.alt_warehouse) + + container_parent.location = self.main_warehouse + container_parent.save() + container.location = self.main_warehouse + container.parent = container_parent + container.save() + + # reinit parent when not provided and location changed + + data = { + "qacontainer_type": '', + "qalocation": self.alt_warehouse.pk, + "qaparent": '' + } + response = client.post(confirm_url, data) + self.assertRedirects(response, '/success/') + container = models.Container.objects.get(pk=container.pk) + self.assertEqual(container.location, self.alt_warehouse) + self.assertEqual(container.parent, None) |