def setUp(self):
        super().setUp()
        self.project = ProjectFactory.create()
        QuestionnaireFactory.create(project=self.project)
        ATTR_TYPE_IDS = get_attr_type_ids()

        content_type = ContentType.objects.get(app_label='spatial',
                                               model='spatialunit')
        create_attrs_schema(
            project=self.project,
            question_group_dict=attr_schemas.location_xform_group,
            content_type=content_type,
            attr_type_ids=ATTR_TYPE_IDS,
        )
        content_type = ContentType.objects.get(app_label='party',
                                               model='party')
        create_attrs_schema(
            project=self.project,
            question_group_dict=attr_schemas.default_party_xform_group,
            content_type=content_type,
            attr_type_ids=ATTR_TYPE_IDS,
        )
        create_attrs_schema(
            project=self.project,
            question_group_dict=attr_schemas.individual_party_xform_group,
            content_type=content_type,
            attr_type_ids=ATTR_TYPE_IDS,
        )
        create_attrs_schema(
            project=self.project,
            question_group_dict=attr_schemas.group_party_attributes,
            content_type=content_type,
            attr_type_ids=ATTR_TYPE_IDS,
        )
        content_type = ContentType.objects.get(app_label='party',
                                               model='tenurerelationship')
        create_attrs_schema(
            project=self.project,
            question_group_dict=attr_schemas.tenure_relationship_xform_group,
            content_type=content_type,
            attr_type_ids=ATTR_TYPE_IDS,
        )
Esempio n. 2
0
    def setup_models(self):
        self.user = UserFactory.create()
        assign_policies(self.user)
        self.project = ProjectFactory.create(slug='test-project')

        QuestionnaireFactory.create(project=self.project)
        content_type = ContentType.objects.get(app_label='party',
                                               model='party')
        create_attrs_schema(project=self.project,
                            dict=individual_party_xform_group,
                            content_type=content_type,
                            errors=[])
        create_attrs_schema(project=self.project,
                            dict=default_party_xform_group,
                            content_type=content_type,
                            errors=[])

        content_type = ContentType.objects.get(app_label='party',
                                               model='tenurerelationship')
        create_attrs_schema(project=self.project,
                            dict=tenure_relationship_xform_group,
                            content_type=content_type,
                            errors=[])

        self.su = SpatialUnitFactory.create(project=self.project, type='CB')
        self.party = PartyFactory.create(project=self.project,
                                         type='IN',
                                         attributes={
                                             'gender': 'm',
                                             'homeowner': 'yes',
                                             'dob': '1951-05-05'
                                         })
        self.tenure_rel = TenureRelationshipFactory.create(
            spatial_unit=self.su,
            party=self.party,
            project=self.project,
            attributes={'notes': 'PBS is the best.'})
        self.resource = ResourceFactory.create(project=self.project)

        self.results = get_fake_es_api_results(self.project, self.su,
                                               self.party, self.tenure_rel,
                                               self.resource)
        self.proj_result = self.results['hits']['hits'][0]
        self.su_result = self.results['hits']['hits'][1]
        self.party_result = self.results['hits']['hits'][2]
        self.tenure_rel_result = self.results['hits']['hits'][3]
        self.resource_result = self.results['hits']['hits'][4]

        self.query = 'searching'
        self.query_body = {
            'query': {
                'simple_query_string': {
                    'default_operator': 'and',
                    'query': self.query,
                }
            }
        }
        self.es_endpoint = '{}/project-{}/_search'.format(
            api_url, self.project.id)
        self.es_body = json.dumps(self.query_body, sort_keys=True)
    def setup_models(self):
        self.user = UserFactory.create()
        assign_policies(self.user)
        self.project = ProjectFactory.create(slug='test-project')

        QuestionnaireFactory.create(project=self.project)
        content_type = ContentType.objects.get(
            app_label='party', model='party')
        create_attrs_schema(
            project=self.project, dict=individual_party_xform_group,
            content_type=content_type, errors=[])
        create_attrs_schema(
            project=self.project, dict=default_party_xform_group,
            content_type=content_type, errors=[])

        content_type = ContentType.objects.get(
            app_label='party', model='tenurerelationship')
        create_attrs_schema(
            project=self.project, dict=tenure_relationship_xform_group,
            content_type=content_type, errors=[])

        self.su = SpatialUnitFactory.create(project=self.project, type='CB')
        self.party = PartyFactory.create(
            project=self.project,
            type='IN',
            attributes={
                'gender': 'm',
                'homeowner': 'yes',
                'dob': '1951-05-05'
            })
        self.tenure_rel = TenureRelationshipFactory.create(
            spatial_unit=self.su, party=self.party, project=self.project,
            attributes={'notes': 'PBS is the best.'})
        self.resource = ResourceFactory.create(project=self.project)

        self.results = get_fake_es_api_results(
            self.project, self.su, self.party, self.tenure_rel, self.resource)
        self.proj_result = self.results['hits']['hits'][0]
        self.su_result = self.results['hits']['hits'][1]
        self.party_result = self.results['hits']['hits'][2]
        self.tenure_rel_result = self.results['hits']['hits'][3]
        self.resource_result = self.results['hits']['hits'][4]

        self.query = 'searching'
        self.query_body = {
            'query': {
                'simple_query_string': {
                    'default_operator': 'and',
                    'query': self.query,
                }
            },
            'from': 10,
            'size': 20,
            'sort': {'_score': {'order': 'desc'}},
        }
        self.es_endpoint = '{}/project-{}/_search/'.format(api_url,
                                                           self.project.id)
        self.es_body = json.dumps(self.query_body, sort_keys=True)
 def _create_attrs_schema(self, prj):
     create_attrs_schema(
         project=prj, dict=default_party_xform_group,
         content_type=ContentType.objects.get(
             app_label='party', model='party'), errors=[])
     create_attrs_schema(
         project=prj, dict=individual_party_xform_group,
         content_type=ContentType.objects.get(
             app_label='party', model='party'), errors=[])
     create_attrs_schema(
         project=prj, dict=location_xform_group,
         content_type=ContentType.objects.get(
             app_label='spatial', model='spatialunit'), errors=[])
     create_attrs_schema(
         project=prj, dict=tenure_relationship_xform_group,
         content_type=ContentType.objects.get(
             app_label='party', model='tenurerelationship'), errors=[])
Esempio n. 5
0
 def _create_attrs_schema(self, prj):
     create_attrs_schema(
         project=prj, dict=default_party_xform_group,
         content_type=ContentType.objects.get(
             app_label='party', model='party'), errors=[])
     create_attrs_schema(
         project=prj, dict=individual_party_xform_group,
         content_type=ContentType.objects.get(
             app_label='party', model='party'), errors=[])
     create_attrs_schema(
         project=prj, dict=location_xform_group,
         content_type=ContentType.objects.get(
             app_label='spatial', model='spatialunit'), errors=[])
     create_attrs_schema(
         project=prj, dict=tenure_relationship_xform_group,
         content_type=ContentType.objects.get(
             app_label='party', model='tenurerelationship'), errors=[])
Esempio n. 6
0
    def setup_models(self):
        self.user = UserFactory.create()
        assign_policies(self.user)
        self.project = ProjectFactory.create(slug='test-project')
        QuestionnaireFactory.create(project=self.project)

        content_type = ContentType.objects.get(app_label='party',
                                               model='party')
        create_attrs_schema(
            project=self.project,
            dict=attr_schemas.individual_party_xform_group,
            content_type=content_type,
        )
        create_attrs_schema(
            project=self.project,
            dict=attr_schemas.default_party_xform_group,
            content_type=content_type,
        )
        content_type = ContentType.objects.get(app_label='party',
                                               model='tenurerelationship')
        create_attrs_schema(
            project=self.project,
            dict=attr_schemas.tenure_relationship_xform_group,
            content_type=content_type,
        )

        self.su = SpatialUnitFactory.create(project=self.project, type='CB')
        self.party = PartyFactory.create(project=self.project,
                                         type='IN',
                                         attributes={
                                             'gender': 'm',
                                             'homeowner': 'yes',
                                             'dob': '1951-05-05'
                                         })
        self.tenure_rel = TenureRelationshipFactory.create(
            spatial_unit=self.su,
            party=self.party,
            project=self.project,
            attributes={'notes': 'PBS is the best.'})
        self.resource = ResourceFactory.create(project=self.project)

        self.results = get_fake_es_api_results(self.project, self.su,
                                               self.party, self.tenure_rel,
                                               self.resource)
        self.proj_result = self.results['hits']['hits'][0]
        self.su_result = self.results['hits']['hits'][1]
        self.party_result = self.results['hits']['hits'][2]
        self.tenure_rel_result = self.results['hits']['hits'][3]
        self.resource_result = self.results['hits']['hits'][4]

        self.query = 'searching'
        self.query_body = {
            'query': parse_query(self.query),
            'from': 10,
            'size': 20,
            'sort': {
                '_score': {
                    'order': 'desc'
                }
            },
        }
        url = '{}/project-{}/spatial,party,resource/_search/'
        self.es_endpoint = url.format(api_url, self.project.id)
        self.es_body = json.dumps(self.query_body, sort_keys=True)
Esempio n. 7
0
    def setup_data(self):
        self.project = ProjectFactory.create()
        QuestionnaireFactory.create(project=self.project)

        content_type = ContentType.objects.get(app_label='spatial',
                                               model='spatialunit')
        create_attrs_schema(
            project=self.project,
            dict=attr_schemas.location_xform_group,
            content_type=content_type,
        )
        content_type = ContentType.objects.get(app_label='party',
                                               model='party')
        create_attrs_schema(
            project=self.project,
            dict=attr_schemas.default_party_xform_group,
            content_type=content_type,
        )
        create_attrs_schema(
            project=self.project,
            dict=attr_schemas.individual_party_xform_group,
            content_type=content_type,
        )
        content_type = ContentType.objects.get(app_label='party',
                                               model='tenurerelationship')
        create_attrs_schema(
            project=self.project,
            dict=attr_schemas.tenure_relationship_xform_group,
            content_type=content_type,
        )

        self.location = SpatialUnitFactory.create(
            project=self.project,
            geometry='SRID=4326;POINT(1 1)',
            attributes={
                'quality': 'point',
                'infrastructure': 'food',
            },
        )
        self.party = PartyFactory.create(
            project=self.project,
            type='IN',
            attributes={
                'gender': 'm',
                'homeowner': 'yes',
                'dob': '1951-05-05'
            },
        )
        self.tenure_rel = TenureRelationshipFactory.create(
            project=self.project,
            spatial_unit=self.location,
            party=self.party,
            attributes={'notes': 'The best relationship!'},
        )
        self.resource = ResourceFactory.create(project=self.project)

        self.location_raw_result = {
            'id': self.location.id,
            'type': self.location.type,
            'geometry': {
                'type': 'geometry',
                'value': '0101000020E6100000000000000000F03F000000000000F03F',
            },
            'attributes': {
                'type': 'jsonb',
                'value': '{"infrastructure": "food", "quality": "point"}',
            },
            '@timestamp': '2017-01-01T01:23:45.678Z',
        }
        self.party_raw_result = {
            'id': self.party.id,
            'name': self.party.name,
            'type': 'IN',
            'attributes': {
                'type':
                'jsonb',
                'value': ('{"dob": "1951-05-05",'
                          ' "gender": "m",'
                          ' "homeowner": "yes"}'),
            },
            'tenure_id': None,
            'tenure_attributes': None,
            'tenure_partyid': None,
            'spatial_unit_id': None,
            'tenure_type_id': None,
            '@timestamp': '2017-01-01T01:23:45.678Z',
        }
        self.tenure_rel_raw_result = {
            'id': self.party.id,
            'name': self.party.name,
            'type': 'IN',
            'attributes': {
                'type':
                'jsonb',
                'value': ('{"dob": "1951-05-05",'
                          ' "gender": "m",'
                          ' "homeowner": "yes"}'),
            },
            'tenure_id': self.tenure_rel.id,
            'tenure_attributes': {
                'type': 'jsonb',
                'value': '{"notes": "The best relationship!"}',
            },
            'tenure_partyid': self.party.id,
            'spatial_unit_id': self.location.id,
            'tenure_type_id': self.tenure_rel.tenure_type.id,
            '@timestamp': '2017-01-01T01:23:45.678Z',
        }
        self.resource_raw_result = {
            'id': self.resource.id,
            'name': self.resource.name,
            'description': self.resource.description,
            'file': 'http://*****:*****@timestamp': '2017-01-01T01:23:45.678Z',
        }
Esempio n. 8
0
    def test_form_resource_in_group(self):
        questionnaire = self._create_questionnaire(
            't_questionnaire_resource_in_group', 7, schema=False)

        attr_type_ids = get_attr_type_ids()
        create_attrs_schema(
            project=self.prj, question_group_dict={
                "label": "Default Party Attributes",
                "children": [
                    {
                        "label": "Notes",
                        "type": "text",
                        "name": "party_notes"
                    }
                ],
                "type": "group",
                "name": "party_attributes_default"
            },
            content_type=ContentType.objects.get(
                app_label='party', model='party'),
            errors=[], attr_type_ids=attr_type_ids)
        create_attrs_schema(
            project=self.prj, question_group_dict={
                "label": "Individual Party Attributes",
                "children": [
                    {
                        "label": "National Id Number",
                        "type": "text",
                        "name": "national_id",
                    },
                    {
                        "label": "Mobile Number",
                        "type": "text",
                        "name": "mobile_number",
                    },
                    {
                        "label": "Gender",
                        "default": "f",
                        "choices": [
                            {
                                "label": "Male",
                                "name": "m"
                            },
                            {
                                "label": "Female",
                                "name": "f"
                            }
                        ],
                        "type": "select one",
                        "name": "gender"
                    },
                    {
                        "label": "Date of Birth",
                        "type": "date",
                        "name": "dob",
                    },
                ],
                "name": "party_attributes_individual",
                "bind": {
                    "relevant": "${party_type}='IN'"
                },
                "type": "group"
            },
            content_type=ContentType.objects.get(
                app_label='party', model='party'),
            errors=[], attr_type_ids=attr_type_ids)
        create_attrs_schema(
            project=self.prj, question_group_dict={
                "type": "group",
                "name": "location_attributes",
                "label": "Location Attributes",
                "children": [
                    {
                        "label": "Name of Location",
                        "name": "location_name",
                        "type": "text",
                    },
                    {
                        "label": "Village name",
                        "name": "village_name",
                        "type": "text",
                    },
                    {
                        "label": "Please, select all problems that apply",
                        "name": "location_problems",
                        "type": "select all that apply",
                        "choices": [
                            {
                                "name": "eviction",
                                "label": "Risk of eviction",
                            },
                            {
                                "name": "conflict",
                                "label": "Conflicts",
                            },
                            {
                                "name": "lack_of_prop_docs",
                                "label": "Lack of property documents",
                            },
                            {
                                "name": "none",
                                "label": "None",
                            },
                        ]
                    },
                    {
                        "label": "Notes about the Location",
                        "name": "location_notes",
                        "type": "text",
                    },
                ]
            },
            content_type=ContentType.objects.get(
                app_label='spatial', model='spatialunit'),
            errors=[], attr_type_ids=attr_type_ids)
        create_attrs_schema(
            project=self.prj, question_group_dict={
                "name": "tenure_relationship_attributes",
                "children": [
                    {
                        "label": "Tenure Notes",
                        "name": "relationship_notes",
                        "type": "text",
                    }
                ],
                "label": "Tenure relationship attributes",
                "type": "group"
            },
            content_type=ContentType.objects.get(
                app_label='party', model='tenurerelationship'),
            errors=[], attr_type_ids=attr_type_ids)

        data = self._submission(form='submission_resource_in_group',
                                image=['test_image_one',
                                       'test_image_two',
                                       'test_image_three'],
                                audio=['test_audio_one'])

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

        assert response.status_code == 201
        assert Party.objects.all().count() == 1
        assert SpatialUnit.objects.all().count() == 1
        assert TenureRelationship.objects.all().count() == 1
        party = Party.objects.first()
        location = SpatialUnit.objects.first()
        tenure = TenureRelationship.objects.first()
        assert party.name == 'Bilbo Baggins'
        assert location.type == 'MI'
        assert tenure.tenure_type == 'LH'
        assert tenure.party == party
        assert tenure.spatial_unit == location

        self._test_resource('test_image_one', location)
        self._test_resource('test_image_two', party)
        self._test_resource('test_audio_one', party)
        self._test_resource('test_image_three', tenure)

        xfsubmission = XFormSubmission.objects.get(user=self.user)
        assert xfsubmission.questionnaire == questionnaire
Esempio n. 9
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=[])