diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-11-20 15:17:42 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-11-20 15:17:42 +0100 |
commit | e0a1e5b8cc4e85895176d42bc0da0422eeabf70a (patch) | |
tree | 59e72e3bc35787dd2e822cbfd6896e4f8da30cd3 /archaeological_operations/tests.py | |
parent | 828fc2faebf1b7fd86d9aaaedf1bd3bbd0d3c6dc (diff) | |
download | Ishtar-e0a1e5b8cc4e85895176d42bc0da0422eeabf70a.tar.bz2 Ishtar-e0a1e5b8cc4e85895176d42bc0da0422eeabf70a.zip |
Custom forms: filter by user and by groups - tests
Diffstat (limited to 'archaeological_operations/tests.py')
-rw-r--r-- | archaeological_operations/tests.py | 82 |
1 files changed, 81 insertions, 1 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index ec7ae44c5..9f07aff45 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -40,7 +40,7 @@ from ishtar_common.models import OrganizationType, Organization, ItemKey, \ ImporterType, IshtarUser, TargetKey, ImporterModel, IshtarSiteProfile, \ Town, ImporterColumn, Person, Author, SourceType, AuthorType, \ DocumentTemplate, PersonType, TargetKeyGroup, JsonDataField, \ - JsonDataSection, ImportTarget, FormaterType + JsonDataSection, ImportTarget, FormaterType, CustomForm, ExcludedField from archaeological_files.models import File, FileType from archaeological_context_records.models import Unit @@ -1142,6 +1142,86 @@ class OperationTest(TestCase, OperationInitTest): self.assertNotIn(u"Marmotte".encode('utf-8'), response.content) +class CustomFormTest(TestCase, OperationInitTest): + fixtures = FILE_FIXTURES + + def setUp(self): + IshtarSiteProfile.objects.get_or_create( + slug='default', active=True) + self.username, self.password, self.user = create_superuser() + self.alt_username, self.alt_password, self.alt_user = create_user() + self.alt_user.user_permissions.add(Permission.objects.get( + codename='view_own_operation')) + self.orgas = self.create_orgas(self.user) + self.operations = self.create_operation(self.user, self.orgas[0]) + self.operations += self.create_operation(self.alt_user, self.orgas[0]) + self.item = self.operations[0] + + def test_filters(self): + c = Client() + c.login(username=self.username, password=self.password) + + cls_wiz = OperationWizardModifTest + url = reverse(cls_wiz.url_name) + # first wizard step + step = 'selec-operation_modification' + cls_wiz.wizard_post(c, url, step, {'pk': self.operations[0].pk}) + + step = 'general-operation_modification' + data = { + '{}{}-current_step'.format(cls_wiz.url_name, + cls_wiz.wizard_name): [step], + } + key_in_charge = "in_charge" + response = c.post(url, data) + self.assertIn( + key_in_charge, response.content, + msg="filter all - 'in charge' field not found on the modification " + "wizard") + f = CustomForm.objects.create(name="Test", form="operation-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, + msg="filter all - 'in charge' field found on the modification " + "wizard. It should have been filtered.") + + # user type form prevail on "all" + f_scientist = CustomForm.objects.create( + name="Test", form="operation-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") + response = c.post(url, data) + self.assertIn( + key_in_charge, response.content, + 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, + msg="filter user type - 'address' field found on the " + "modification wizard. It should have been filtered.") + + # user prevail on "all" and "user_types" + f_user = CustomForm.objects.create( + name="Test", form="operation-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, + msg="filter user - 'in charge' field not found on the modification " + "wizard. It should not have been filtered.") + self.assertIn( + key_address, response.content, + msg="filter user - 'address' field not found on the modification " + "wizard. It should not have been filtered.") + + class OperationSearchTest(TestCase, OperationInitTest): fixtures = FILE_FIXTURES |