diff options
Diffstat (limited to 'archaeological_operations/tests.py')
| -rw-r--r-- | archaeological_operations/tests.py | 105 | 
1 files changed, 104 insertions, 1 deletions
| diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index ec7ae44c5..af6199774 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,109 @@ 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.") + +    def test_enabled(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 = 'collaborators-operation_modification' +        data = { +            '{}{}-current_step'.format(cls_wiz.url_name, +                                       cls_wiz.wizard_name): [step], +        } +        response = c.post(url, data) +        self.assertNotEqual(response.status_code, 404) +        CustomForm.objects.create( +            name="Test2", form="operation-collaborators", available=True, +            apply_to_all=True, enabled=False) +        response = c.post(url, data) +        self.assertEqual(response.status_code, 404) + +  class OperationSearchTest(TestCase, OperationInitTest):      fixtures = FILE_FIXTURES | 
