当前位置: 首页>>代码示例>>Python>>正文


Python factories.SpatialUnitFactory类代码示例

本文整理汇总了Python中spatial.tests.factories.SpatialUnitFactory的典型用法代码示例。如果您正苦于以下问题:Python SpatialUnitFactory类的具体用法?Python SpatialUnitFactory怎么用?Python SpatialUnitFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SpatialUnitFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_do_not_send_questionnaire_when_project_has_data

    def test_do_not_send_questionnaire_when_project_has_data(self):
        project = ProjectFactory.create()
        questionnaire = QuestionnaireFactory.create(
            project=project,
            xls_form=self._get_form('xls-form'))

        SpatialUnitFactory.create(project=project)

        data = {
            'name': 'New name',
            'access': project.access,
            'contacts-TOTAL_FORMS': 1,
            'contacts-INITIAL_FORMS': 0,
            'contacts-0-name': '',
            'contacts-0-email': '',
            'contacts-0-tel': ''
        }

        form = forms.ProjectEditDetails(
            instance=project,
            data=data,
            initial={'questionnaire': questionnaire.xls_form.url})

        assert form.is_valid() is True
        form.save()
        project.refresh_from_db()
        assert project.name == data['name']
        assert project.current_questionnaire == questionnaire.id
开发者ID:mikael19,项目名称:cadasta-platform,代码行数:28,代码来源:test_forms.py

示例2: test_has_records

    def test_has_records(self):
        project = ProjectFactory.create()
        assert project.has_records is False

        project = ProjectFactory.create()
        SpatialUnitFactory.create(project=project)
        assert project.has_records is True
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:7,代码来源:test_models.py

示例3: test_replace_questionnaire_when_project_has_data

    def test_replace_questionnaire_when_project_has_data(self):
        project = ProjectFactory.create()
        questionnaire = QuestionnaireFactory.create(
            project=project,
            xls_form=self._get_form('xls-form'))

        SpatialUnitFactory.create(project=project)

        data = {
            'name': 'New name',
            'questionnaire': self._get_form('xls-form-copy'),
            'access': project.access,
            'contacts-TOTAL_FORMS': 1,
            'contacts-INITIAL_FORMS': 0,
            'contacts-0-name': '',
            'contacts-0-email': '',
            'contacts-0-tel': ''
        }

        form = forms.ProjectEditDetails(
            instance=project,
            data=data,
            initial={'questionnaire': questionnaire.xls_form.url})

        assert form.is_valid() is False
        assert ("Data has already been contributed to this project. To "
                "ensure data integrity, uploading a new questionnaire is "
                "disabled for this project." in
                form.errors.get('questionnaire'))
开发者ID:mikael19,项目名称:cadasta-platform,代码行数:29,代码来源:test_forms.py

示例4: test_create_with_blocked_questionnaire_upload

    def test_create_with_blocked_questionnaire_upload(self):
        data = {'xls_form': self.get_form('xls-form')}
        SpatialUnitFactory.create(project=self.prj)
        response = self.request(method='PUT', user=self.user, post_data=data)

        assert response.status_code == 400
        assert ("Data has already been contributed to this "
                "project. To ensure data integrity, uploading a "
                "new questionnaire is disabled for this project." in
                response.content.get('xls_form'))
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:10,代码来源:test_views_api.py

示例5: setup_models

    def setup_models(self):
        self.user = UserFactory.create()
        assign_policies(self.user)

        self.prj = ProjectFactory.create(slug='test-project', access='public')
        self.party = PartyFactory.create(project=self.prj)
        self.spatial_unit = SpatialUnitFactory.create(project=self.prj)
        self.rel = TenureRelationshipFactory.create(
            project=self.prj, party=self.party, spatial_unit=self.spatial_unit)
        self.party2 = PartyFactory.create(project=self.prj)
        self.spatial_unit2 = SpatialUnitFactory.create(project=self.prj)
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:11,代码来源:test_views_api_tenure_relationships.py

示例6: test_get_xls_download

 def test_get_xls_download(self):
     ensure_dirs()
     data = {"type": "xls"}
     user = UserFactory.create()
     project = ProjectFactory.create()
     geometry = "SRID=4326;POINT (30 10)"
     SpatialUnitFactory.create(project=project, geometry=geometry)
     form = forms.DownloadForm(project, user, data=data)
     assert form.is_valid() is True
     path, mime = form.get_file()
     assert "{}-{}".format(project.id, user.id) in path
     assert mime == "application/vnd.openxmlformats-officedocument." "spreadsheetml.sheet"
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:12,代码来源:test_forms.py

示例7: test_get_shape_download

    def test_get_shape_download(self):
        ensure_dirs()
        data = {'type': 'shp'}
        user = UserFactory.create()
        project = ProjectFactory.create()
        content_type = ContentType.objects.get(app_label='spatial',
                                               model='spatialunit')
        schema = Schema.objects.create(
            content_type=content_type,
            selectors=(project.organization.id, project.id))
        attr_type = AttributeType.objects.get(name='text')
        Attribute.objects.create(
            schema=schema,
            name='key', long_name='Test field',
            attr_type=attr_type, index=0,
            required=False, omit=False
        )

        su1 = SpatialUnitFactory.create(
            project=project,
            geometry='POINT (1 1)',
            attributes={'key': 'value 1'})
        SpatialUnitFactory.create(
            project=project,
            geometry='SRID=4326;'
                     'MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)),'
                     '((15 5, 40 10, 10 20, 5 10, 15 5)))',
            attributes={'key': 'value 2'})
        party = PartyFactory.create(project=project)
        TenureRelationshipFactory.create(
            spatial_unit=su1, party=party, project=project)

        form = forms.DownloadForm(project, user, data=data)
        assert form.is_valid() is True
        path, mime = form.get_file()
        assert '{}-{}'.format(project.id, user.id) in path
        assert (mime == 'application/zip')

        with ZipFile(path, 'r') as testzip:
            assert len(testzip.namelist()) == 12
            assert 'point.dbf' in testzip.namelist()
            assert 'point.prj' in testzip.namelist()
            assert 'point.shp' in testzip.namelist()
            assert 'point.shx' in testzip.namelist()
            assert 'multipolygon.dbf' in testzip.namelist()
            assert 'multipolygon.prj' in testzip.namelist()
            assert 'multipolygon.shp' in testzip.namelist()
            assert 'multipolygon.shx' in testzip.namelist()
            assert 'relationships.csv' in testzip.namelist()
            assert 'parties.csv' in testzip.namelist()
            assert 'locations.csv' in testzip.namelist()
            assert 'README.txt' in testzip.namelist()
开发者ID:mikael19,项目名称:cadasta-platform,代码行数:52,代码来源:test_forms.py

示例8: test_repr

 def test_repr(self):
     project = ProjectFactory.build(slug='prj')
     su1 = SpatialUnitFactory.build(type='PA', id='abc123', project=project)
     su2 = SpatialUnitFactory.build(type='PA', id='def456', project=project)
     relationship = SpatialRelationshipFactory.build(
         id='abc123',
         project=project,
         su1=su1,
         su2=su2,
         type='C')
     assert repr(relationship) == ('<SpatialRelationship id=abc123'
                                   ' project=prj su1=abc123 su2=def456'
                                   ' type=C>')
开发者ID:mikael19,项目名称:cadasta-platform,代码行数:13,代码来源:test_models.py

示例9: test_omit_attribute

 def test_omit_attribute(self):
     project = ProjectFactory.create(name='TestProject')
     QuestionnaireFactory.create(project=project)
     content_type = ContentType.objects.get(
         app_label='spatial', model='spatialunit')
     create_attrs_schema(
         project=project, dict=location_xform_group,
         content_type=content_type, errors=[])
     with pytest.raises(KeyError):
         SpatialUnitFactory.create(
             project=project,
             attributes={
                 'notes': 'Some textual content',
             }
         )
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:15,代码来源:test_attr_schemas.py

示例10: test_serialize

    def test_serialize(self):
        location = SpatialUnitFactory.build(id='abc123')
        serializer = serializers.SpatialUnitGeoJsonSerializer(location)

        assert 'type' in serializer.data['properties']
        assert 'url' in serializer.data['properties']
        assert 'geometry' in serializer.data
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:7,代码来源:test_serializers.py

示例11: setup_models

    def setup_models(self):
        self.project = ProjectFactory.create()
        self.org_slug = self.project.organization.slug
        self.resource = ResourceFactory.create(project=self.project)
        self.location = SpatialUnitFactory.create(project=self.project)
        self.party = PartyFactory.create(project=self.project)
        self.tenurerel = TenureRelationshipFactory.create(project=self.project)
        self.project_attachment = ContentObject.objects.create(
            resource_id=self.resource.id,
            content_object=self.project,
        )
        self.location_attachment = ContentObject.objects.create(
            resource_id=self.resource.id,
            content_object=self.location,
        )
        self.party_attachment = ContentObject.objects.create(
            resource_id=self.resource.id,
            content_object=self.party,
        )
        self.tenurerel_attachment = ContentObject.objects.create(
            resource_id=self.resource.id,
            content_object=self.tenurerel,
        )

        self.user = UserFactory.create()
        assign_permissions(self.user)
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:26,代码来源:test_views_default.py

示例12: test_spatial_unit_invalid_attribute

 def test_spatial_unit_invalid_attribute(self):
     project = ProjectFactory.create(name='TestProject')
     QuestionnaireFactory.create(project=project)
     content_type = ContentType.objects.get(
         app_label='spatial', model='spatialunit')
     create_attrs_schema(
         project=project, dict=location_xform_group,
         content_type=content_type, errors=[])
     assert 1 == Schema.objects.all().count()
     with pytest.raises(KeyError):
         SpatialUnitFactory.create(
             project=project,
             attributes={
                 'invalid_attribute': 'yes',
             }
         )
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:16,代码来源:test_attr_schemas.py

示例13: test_spatial_unit_attribute_schema

 def test_spatial_unit_attribute_schema(self):
     project = ProjectFactory.create(name='TestProject')
     QuestionnaireFactory.create(project=project)
     content_type = ContentType.objects.get(
         app_label='spatial', model='spatialunit')
     create_attrs_schema(
         project=project, dict=location_xform_group,
         content_type=content_type, errors=[])
     spatial_unit = SpatialUnitFactory.create(
         project=project,
         attributes={
             'quality': 'polygon_high',
             'infrastructure': ['water', 'food']
         }
     )
     assert 1 == Schema.objects.all().count()
     schema = Schema.objects.get(content_type=content_type)
     assert schema is not None
     assert schema.selectors == [
         project.organization.pk, project.pk, project.current_questionnaire]
     assert 'quality' in spatial_unit.attributes.attributes
     assert 'polygon_high' == spatial_unit.attributes['quality']
     assert 'infrastructure' in spatial_unit.attributes.attributes
     assert 'water' in spatial_unit.attributes['infrastructure']
     # notes field is omitted in xform
     assert 'notes' not in spatial_unit.attributes.attributes
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:26,代码来源:test_attr_schemas.py

示例14: test_get_absolute_url

 def test_get_absolute_url(self):
     su = SpatialUnitFactory.create()
     assert su.get_absolute_url() == (
         '/organizations/{org}/projects/{prj}/'
         'records/locations/{id}/'.format(
             org=su.project.organization.slug,
             prj=su.project.slug,
             id=su.id))
开发者ID:mikael19,项目名称:cadasta-platform,代码行数:8,代码来源:test_models.py

示例15: test_make_download

    def test_make_download(self):
        ensure_dirs()
        project = ProjectFactory.create(current_questionnaire='123abc')
        exporter = ShapeExporter(project)

        content_type = ContentType.objects.get(app_label='spatial',
                                               model='spatialunit')
        schema = Schema.objects.create(
            content_type=content_type,
            selectors=(project.organization.id, project.id, '123abc', ))
        attr_type = AttributeType.objects.get(name='text')
        Attribute.objects.create(
            schema=schema,
            name='key', long_name='Test field',
            attr_type=attr_type, index=0,
            required=False, omit=False
        )

        SpatialUnitFactory.create(
            project=project,
            geometry='POINT (1 1)',
            attributes={'key': 'value 1'})
        SpatialUnitFactory.create(
            project=project,
            geometry='SRID=4326;'
                     'MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)),'
                     '((15 5, 40 10, 10 20, 5 10, 15 5)))',
            attributes={'key': 'value 2'})

        path, mime = exporter.make_download('file5')

        assert path == os.path.join(settings.MEDIA_ROOT, 'temp/file5.zip')
        assert mime == 'application/zip'

        with ZipFile(path, 'r') as testzip:
            assert len(testzip.namelist()) == 10
            assert 'point.dbf' in testzip.namelist()
            assert 'point.prj' in testzip.namelist()
            assert 'point.shp' in testzip.namelist()
            assert 'point.shx' in testzip.namelist()
            assert 'multipolygon.dbf' in testzip.namelist()
            assert 'multipolygon.prj' in testzip.namelist()
            assert 'multipolygon.shp' in testzip.namelist()
            assert 'multipolygon.shx' in testzip.namelist()
            assert 'locations.csv' in testzip.namelist()
            assert 'README.txt' in testzip.namelist()
开发者ID:mikael19,项目名称:cadasta-platform,代码行数:46,代码来源:test_downloads.py


注:本文中的spatial.tests.factories.SpatialUnitFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。