diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-07-18 12:42:01 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-07-18 12:59:02 +0200 |
commit | 0ba146309a273d49bba4fd4c10939c79dd920ca6 (patch) | |
tree | 19f13dd8275b304f211223de3743a88f888dd544 /archaeological_operations | |
parent | f835d181d61fd6987319ac532a20154719b14771 (diff) | |
download | Ishtar-0ba146309a273d49bba4fd4c10939c79dd920ca6.tar.bz2 Ishtar-0ba146309a273d49bba4fd4c10939c79dd920ca6.zip |
✅ add relations forms tests
Diffstat (limited to 'archaeological_operations')
-rw-r--r-- | archaeological_operations/tests.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 4ce1a4cc2..770b57d86 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -2613,6 +2613,56 @@ class OperationTest(TestCase, OperationInitTest): return data + def test_operation_relations_formset(self): + self.create_operation() + self.create_operation() + ope1, ope2, ope3 = self.operations[-3:] + rt = models.RelationType.objects.all()[0] + self.assertTrue(rt.symmetrical or rt.inverse_relation) + ope1.right_relations.add() + r = models.RecordRelations.objects.create( + left_record=ope1, right_record=ope2, relation_type=rt + ) + r.save() + c = Client() + + c.login(username=self.alt_username, password=self.alt_password) + url = reverse("operation-relation-modify", kwargs={"pk": ope1.pk}) + response = c.get(url) + self.assertRedirects(response, "/") # permission failed, redirect to index + + c.login(username=self.username, password=self.password) + response = c.get(url) + self.assertEqual(response.status_code, 200) + self.assertContains(response, str(ope2)) + + # add an ope + data = self.formset_init_data(models.RecordRelations) + nb_relation_initial = models.RecordRelations.objects.count() + data["form-0-relation_type"] = rt.pk + data["form-0-right_record"] = ope2.pk + data["form-1-relation_type"] = rt.pk + data["form-1-right_record"] = ope3.pk + post_response = c.post(url, data) + self.assertEqual(post_response.status_code, 302) + # relation is symetrical -> 2 new relations + self.assertEqual(models.RecordRelations.objects.count(), nb_relation_initial + 2) + lst = [rel.right_record_id for rel in ope1.right_relations.all()] + self.assertIn(ope2.pk, lst) + self.assertIn(ope3.pk, lst) + + # delete first + data["form-0-pk"] = models.RecordRelations.objects.get( + left_record=ope1, right_record=ope2, relation_type=rt + ).pk + data["form-0-DELETE"] = 1 + post_response = c.post(url, data) + self.assertEqual(post_response.status_code, 302) + self.assertEqual(models.RecordRelations.objects.count(), nb_relation_initial) + lst = [rel.right_record_id for rel in ope1.right_relations.all()] + self.assertNotIn(ope2.pk, lst) + self.assertIn(ope3.pk, lst) + def test_operation_site_formset(self): ope1, ope2 = self.create_operation()[:2] site1 = models.ArchaeologicalSite.objects.create(reference="ref-site") |