コード例 #1
0
    def test_invalid_submission_upload(self):
        questionnaire = self._create_questionnaire('t_questionnaire', 0)
        QuestionFactory.create(name='party_name',
                               questionnaire=questionnaire,
                               type='TX')
        # testing submitting with a missing xml_submission_file
        data = self._invalid_submission(form='This is not an xml form!')
        response = self.request(method='POST', user=self.user, post_data=data,
                                content_type='multipart/form-data')
        assert response.status_code == 400
        msg = self._getResponseMessage(response)
        assert msg == "XML submission not found"

        data = self._submission(form='submission_bad_location')
        response = self.request(method='POST', user=self.user, post_data=data,
                                content_type='multipart/form-data')
        assert response.status_code == 400
        msg = self._getResponseMessage(response)
        assert msg == "Location error: 'location_type'"

        data = self._submission(form='submission_bad_party')
        response = self.request(method='POST', user=self.user, post_data=data,
                                content_type='multipart/form-data')
        assert response.status_code == 400
        msg = self._getResponseMessage(response)
        assert msg == "Party error: 'party_name'"

        data = self._submission(form='submission_bad_tenure')
        response = self.request(method='POST', user=self.user, post_data=data,
                                content_type='multipart/form-data')
        assert response.status_code == 400
        msg = self._getResponseMessage(response)
        assert msg == "Tenure relationship error: 'tenure_type'"

        data = self._submission(form='submission_not_sane')
        response = self.request(method='POST', user=self.user, post_data=data,
                                content_type='multipart/form-data')
        assert response.status_code == 400
        msg = self._getResponseMessage(response)
        assert msg == SANITIZE_ERROR

        file = self.get_file(
            '/xforms/tests/files/test_bad_resource.html', 'rb')
        bad_file = file.read().decode('utf-8')
        file.close()

        self._create_questionnaire('t_questionnaire_bad', 2, False)
        data = self._submission(form='submission_bad_resource',
                                image=['test_image_one'],
                                file=bad_file)
        response = self.request(method='POST', user=self.user, post_data=data,
                                content_type='multipart/form-data')
        assert response.status_code == 400
        msg = self._getResponseMessage(response)
        exp = "{'mime_type': ['Files of type text/html are not accepted.']}"
        assert msg == exp

        assert len(Party.objects.all()) == 0
        assert len(SpatialUnit.objects.all()) == 0
        assert len(Resource.objects.all()) == 0
コード例 #2
0
    def setUp(self):
        super().setUp()
        PolicyFactory.load_policies()
        create_attribute_types()

        loadattrtypes.Command().handle(force=True)
        load_tenure_relationship_types(force=True)

        self.user = UserFactory.create()
        self.project = ProjectFactory.create(current_questionnaire='a1')

        self.questionnaire = QuestionnaireFactory.create(id_string='a1',
                                                         version=0,
                                                         project=self.project,
                                                         id='a1')
        QuestionFactory.create(name='location_geometry',
                               label='Location of Parcel',
                               type='GS',
                               questionnaire=self.questionnaire)

        content_type_party = ContentType.objects.get(app_label='party',
                                                     model='party')
        content_type_spatial = ContentType.objects.get(app_label='spatial',
                                                       model='spatialunit')
        content_type_tenure = ContentType.objects.get(
            app_label='party', model='tenurerelationship')
        for content_type in [
                content_type_party, content_type_tenure, content_type_spatial
        ]:
            schema = Schema.objects.create(
                content_type=content_type,
                selectors=(self.project.organization.id, self.project.id,
                           'a1'))
            attr_type = AttributeType.objects.get(name='boolean')
            Attribute.objects.create(schema=schema,
                                     name='fname',
                                     long_name='True or False',
                                     attr_type=attr_type,
                                     index=0,
                                     required=False,
                                     omit=False)
            attr_type = AttributeType.objects.get(name='text')
            Attribute.objects.create(schema=schema,
                                     name='fname_two',
                                     long_name='Notes',
                                     attr_type=attr_type,
                                     index=1,
                                     required=False,
                                     omit=False)

        OrganizationRole.objects.create(user=self.user,
                                        organization=self.project.organization)
コード例 #3
0
    def setUp(self):
        super().setUp()
        PolicyFactory.load_policies()
        create_attribute_types()

        loadattrtypes.Command().handle(force=True)
        load_tenure_relationship_types(force=True)

        self.user = UserFactory.create()
        self.project = ProjectFactory.create(
            current_questionnaire='a1')

        self.questionnaire = QuestionnaireFactory.create(
            id_string='a1', version=0, project=self.project, id='a1')
        QuestionFactory.create(
            name='location_geometry',
            label='Location of Parcel',
            type='GS',
            questionnaire=self.questionnaire)

        content_type_party = ContentType.objects.get(
            app_label='party', model='party')
        content_type_spatial = ContentType.objects.get(
            app_label='spatial', model='spatialunit')
        content_type_tenure = ContentType.objects.get(
            app_label='party', model='tenurerelationship')
        for content_type in [content_type_party, content_type_tenure,
                             content_type_spatial]:
            schema = Schema.objects.create(
                content_type=content_type,
                selectors=(self.project.organization.id, self.project.id, 'a1')
            )
            attr_type = AttributeType.objects.get(name='boolean')
            Attribute.objects.create(
                schema=schema,
                name='fname', long_name='True or False',
                attr_type=attr_type, index=0,
                required=False, omit=False
            )
            attr_type = AttributeType.objects.get(name='text')
            Attribute.objects.create(
                schema=schema,
                name='fname_two', long_name='Notes',
                attr_type=attr_type, index=1,
                required=False, omit=False
            )

        OrganizationRole.objects.create(
            user=self.user, organization=self.project.organization)
コード例 #4
0
    def test_geoshape_as_location_geometry_upload(self):
        questionnaire = self._create_questionnaire(
            't_questionnaire_geotype_select', 1)
        QuestionFactory.create(
            name='location_geometry',
            label='Location of Parcel',
            type='GS',
            questionnaire=questionnaire)

        data = self._submission(form='submission_geotype_neither')
        response = self.request(method='POST', user=self.user, post_data=data,
                                content_type='multipart/form-data')

        geom = SpatialUnit.objects.get(attributes={'name': 'Geoshape'})
        assert response.status_code == 201
        assert geom.geometry.geom_type == 'Polygon'
コード例 #5
0
    def test_geoshape_as_location_geometry_upload(self):
        questionnaire = self._create_questionnaire(
            't_questionnaire_geotype_select', 1)
        QuestionFactory.create(
            name='location_geometry',
            label='Location of Parcel',
            type='GS',
            questionnaire=questionnaire)

        data = self._submission(form='submission_geotype_neither')
        response = self.request(method='POST', user=self.user, post_data=data,
                                content_type='multipart/form-data')

        geom = SpatialUnit.objects.get(attributes={'name': 'Geoshape'})
        assert response.status_code == 201
        assert geom.geometry.geom_type == 'Polygon'
コード例 #6
0
    def test_get_sanitizable_questions(self):
        QuestionFactory.create(name='text',
                               type='TX',
                               questionnaire=self.questionnaire)
        QuestionFactory.create(name='note',
                               type='NO',
                               questionnaire=self.questionnaire)
        QuestionFactory.create(name='integer',
                               type='IN',
                               questionnaire=self.questionnaire)
        QuestionFactory.create(name='select_one',
                               type='S1',
                               questionnaire=self.questionnaire)
        QuestionFactory.create(name='select_multiple',
                               type='SM',
                               questionnaire=self.questionnaire)
        QuestionFactory.create(name='geopoint',
                               type='GP',
                               questionnaire=self.questionnaire)
        QuestionFactory.create(name='geotrace',
                               type='GT',
                               questionnaire=self.questionnaire)
        QuestionFactory.create(name='geoshape',
                               type='GS',
                               questionnaire=self.questionnaire)
        QuestionFactory.create(name='date',
                               type='DA',
                               questionnaire=self.questionnaire)
        QuestionFactory.create(name='time',
                               type='TI',
                               questionnaire=self.questionnaire)
        QuestionFactory.create(name='datetime',
                               type='DT',
                               questionnaire=self.questionnaire)
        QuestionFactory.create(name='calculate',
                               type='CA',
                               questionnaire=self.questionnaire)
        QuestionFactory.create(name='acknowledge',
                               type='AC',
                               questionnaire=self.questionnaire)
        QuestionFactory.create(name='photo',
                               type='PH',
                               questionnaire=self.questionnaire)
        QuestionFactory.create(name='audio',
                               type='AU',
                               questionnaire=self.questionnaire)
        QuestionFactory.create(name='video',
                               type='VI',
                               questionnaire=self.questionnaire)
        QuestionFactory.create(name='barcode',
                               type='BC',
                               questionnaire=self.questionnaire)
        QuestionFactory.create(name='start',
                               type='ST',
                               questionnaire=self.questionnaire)
        QuestionFactory.create(name='end',
                               type='EN',
                               questionnaire=self.questionnaire)
        QuestionFactory.create(name='today',
                               type='TD',
                               questionnaire=self.questionnaire)
        QuestionFactory.create(name='deviceid',
                               type='DI',
                               questionnaire=self.questionnaire)
        QuestionFactory.create(name='subscriber_id',
                               type='SI',
                               questionnaire=self.questionnaire)
        QuestionFactory.create(name='simserial',
                               type='SS',
                               questionnaire=self.questionnaire)
        QuestionFactory.create(name='phonenumber',
                               type='PN',
                               questionnaire=self.questionnaire)

        sanitizeable_questions = mh.get_sanitizable_questions(
            mh(), self.questionnaire.id_string, self.questionnaire.version)
        assert len(sanitizeable_questions) == 2
        assert 'text' in sanitizeable_questions
        assert 'note' in sanitizeable_questions
        assert 'integer' not in sanitizeable_questions
        assert 'select_one' not in sanitizeable_questions
        assert 'select_multiple' not in sanitizeable_questions
        assert 'geopoint' not in sanitizeable_questions
        assert 'geotrace' not in sanitizeable_questions
        assert 'geoshape' not in sanitizeable_questions
        assert 'date' not in sanitizeable_questions
        assert 'time' not in sanitizeable_questions
        assert 'datetime' not in sanitizeable_questions
        assert 'calculate' not in sanitizeable_questions
        assert 'acknowledge' not in sanitizeable_questions
        assert 'photo' not in sanitizeable_questions
        assert 'audio' not in sanitizeable_questions
        assert 'video' not in sanitizeable_questions
        assert 'barcode' not in sanitizeable_questions
        assert 'start' not in sanitizeable_questions
        assert 'end' not in sanitizeable_questions
        assert 'today' not in sanitizeable_questions
        assert 'deviceid' not in sanitizeable_questions
        assert 'subscriber_id' not in sanitizeable_questions
        assert 'simserial' not in sanitizeable_questions
        assert 'phonenumber' not in sanitizeable_questions
コード例 #7
0
    def setup_models(self):
        self.user = UserFactory.create()
        self.org = OrganizationFactory.create()
        self.prj = ProjectFactory.create(organization=self.org)
        self.prj_2 = ProjectFactory.create(organization=self.org)
        self.prj_3 = ProjectFactory.create(organization=self.org)

        OrganizationRole.objects.create(
            organization=self.org, user=self.user, admin=True)

        QuestionnaireFactory.create(
            project=self.prj,
            xls_form=get_form('test_standard_questionnaire'),
            filename='test_standard_questionnaire',
            id_string='test_standard_questionnaire',
            version=20160727122110)

        questionnaire = QuestionnaireFactory.create(
            project=self.prj_2,
            xls_form=get_form('test_standard_questionnaire_2'),
            filename='test_standard_questionnaire_2',
            id_string='test_standard_questionnaire_2',
            version=20160727122111)

        QuestionFactory.create(
            name='location_geometry',
            label='Location of Parcel',
            type='GS',
            questionnaire=questionnaire)

        QuestionnaireFactory.create(
            project=self.prj_3,
            xls_form=get_form('test_standard_questionnaire_bad'),
            filename='test_standard_questionnaire_bad',
            id_string='test_standard_questionnaire_bad',
            version=20160727122112)

        # project 1
        create_attrs_schema(
            project=self.prj, dict=default_party_xform_group,
            content_type=ContentType.objects.get(
                app_label='party', model='party'), errors=[])
        create_attrs_schema(
            project=self.prj, dict=individual_party_xform_group,
            content_type=ContentType.objects.get(
                app_label='party', model='party'), errors=[])
        create_attrs_schema(
            project=self.prj, dict=location_xform_group,
            content_type=ContentType.objects.get(
                app_label='spatial', model='spatialunit'), errors=[])
        create_attrs_schema(
            project=self.prj, dict=tenure_relationship_xform_group,
            content_type=ContentType.objects.get(
                app_label='party', model='tenurerelationship'), errors=[])

        # project 2
        create_attrs_schema(
            project=self.prj_2, dict=default_party_xform_group,
            content_type=ContentType.objects.get(
                app_label='party', model='party'), errors=[])
        create_attrs_schema(
            project=self.prj_2, dict=individual_party_xform_group,
            content_type=ContentType.objects.get(
                app_label='party', model='party'), errors=[])
        create_attrs_schema(
            project=self.prj_2, dict=location_xform_group,
            content_type=ContentType.objects.get(
                app_label='spatial', model='spatialunit'), errors=[])
        create_attrs_schema(
            project=self.prj_2, dict=tenure_relationship_xform_group,
            content_type=ContentType.objects.get(
                app_label='party', model='tenurerelationship'), errors=[])