diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-03-02 11:23:23 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-03-02 12:44:59 +0100 |
commit | c3ac6de46a5ab6e35c0103456c47accc0f3cb3f9 (patch) | |
tree | 98dcb4e9c96101b01b4fd17bcddbd12a1c127377 /archaeological_operations | |
parent | 6676d09fbd11b26d014b46585db7e6997f4d2abc (diff) | |
download | Ishtar-c3ac6de46a5ab6e35c0103456c47accc0f3cb3f9.tar.bz2 Ishtar-c3ac6de46a5ab6e35c0103456c47accc0f3cb3f9.zip |
Fix custom form -> use profile instead of person types
Diffstat (limited to 'archaeological_operations')
-rw-r--r-- | archaeological_operations/tests.py | 101 |
1 files changed, 71 insertions, 30 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 650a839aa..3eefe5d61 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -1834,56 +1834,97 @@ class CustomFormTest(TestCase, OperationInitTest): '{}{}-current_step'.format(cls_wiz.url_name, cls_wiz.wizard_name): [step], } + + MSG_FOUND = " - '{}' field found on the modification "\ + "wizard. It should have been filtered." + MSG_NOT_FOUND = " - '{}' field not found on the modification "\ + "wizard. It shouldn't have been filtered." + key_in_charge = "in_charge" response = c.post(url, data) - self.assertIn( - key_in_charge, response.content.decode(), - msg="filter all - 'in charge' field not found on the modification " - "wizard") + content = response.content.decode() + res = key_in_charge in content + self.assertTrue(res, + msg="filter all" + MSG_NOT_FOUND.format(key_in_charge)) f = CustomForm.objects.create( name="Test - all", form="operation-010-general", available=True, apply_to_all=True) ExcludedField.objects.create(custom_form=f, field="in_charge") response = c.post(url, data) - self.assertNotIn( - key_in_charge, response.content.decode(), - msg="filter all - 'in charge' field found on the modification " - "wizard. It should have been filtered.") + content = response.content.decode() + res = key_in_charge not in content + self.assertTrue(res, + msg="filter all" + MSG_FOUND.format(key_in_charge)) # user type form prevail on "all" f_scientist = CustomForm.objects.create( - name="Test - user", form="operation-010-general", + name="Test - user type", form="operation-010-general", available=True) tpe = PersonType.objects.get(txt_idx='head_scientist') key_address = "address" f_scientist.user_types.add(tpe) self.user.ishtaruser.person.person_types.add(tpe) - ExcludedField.objects.create(custom_form=f_scientist, field="address") + ExcludedField.objects.create(custom_form=f_scientist, field=key_address) + response = c.post(url, data) - self.assertIn( - key_in_charge, response.content.decode(), - msg="filter user type - 'in charge' field not found on the " - "modification wizard. It should not have been filtered.") - self.assertNotIn( - key_address, response.content.decode(), - msg="filter user type - 'address' field found on the " - "modification wizard. It should have been filtered.") - - # user prevail on "all" and "user_types" + content = response.content.decode() + res = key_in_charge in content + self.assertTrue( + res, + msg="filter profile type" + MSG_NOT_FOUND.format(key_in_charge) + ) + res = key_address not in content + self.assertTrue( + res, + msg="filter profile type" + MSG_FOUND.format(key_address)) + + # profile type form prevail on "all" and "user types" + f_scientist2 = CustomForm.objects.create( + name="Test - profile type", form="operation-010-general", + available=True) + key_scientific = "scientific_documentation_comment" + ExcludedField.objects.create(custom_form=f_scientist2, + field=key_scientific) + + collaborator = ProfileType.objects.get(txt_idx='collaborator') + UserProfile.objects.create( + profile_type=collaborator, + person=self.user.ishtaruser.person, + current=True) + f_scientist2.profile_types.add(collaborator) + + response = c.post(url, data) + content = response.content.decode() + res = key_in_charge in content + self.assertTrue( + res, + msg="filter profile type" + MSG_NOT_FOUND.format(key_in_charge)) + res = key_address in content + self.assertTrue( + res, + msg="filter profile type" + MSG_NOT_FOUND.format(key_address)) + res = key_scientific not in content + self.assertTrue( + res, + msg="filter profile type" + MSG_FOUND.format(key_scientific)) + + # user prevail on "all", "profile_type" and "user_types" f_user = CustomForm.objects.create( - name="Test", form="operation-010-general", available=True) + name="Test - user", form="operation-010-general", available=True) f_user.users.add(self.user.ishtaruser) - self.user.ishtaruser.person.person_types.add(tpe) + response = c.post(url, data) - self.assertIn( - key_in_charge, response.content.decode(), - msg="filter user - 'in charge' field not found on the modification " - "wizard. It should not have been filtered.") - self.assertIn( - key_address, response.content.decode(), - msg="filter user - 'address' field not found on the modification " - "wizard. It should not have been filtered.") + content = response.content.decode() + res = key_in_charge in content + self.assertTrue(res, + msg="filter user" + MSG_NOT_FOUND.format(key_in_charge)) + res = key_scientific in content + self.assertTrue(res, + msg="filter user" + MSG_NOT_FOUND.format(key_scientific)) + res = key_address in content + self.assertTrue(res, + msg="filter user" + MSG_FOUND.format(key_address)) def test_enabled(self): c = Client() |