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


Python SpatialUnitFactory.create方法代码示例

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


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

示例1: test_has_records

# 需要导入模块: from spatial.tests.factories import SpatialUnitFactory [as 别名]
# 或者: from spatial.tests.factories.SpatialUnitFactory import create [as 别名]
    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,代码行数:9,代码来源:test_models.py

示例2: test_replace_questionnaire_when_project_has_data

# 需要导入模块: from spatial.tests.factories import SpatialUnitFactory [as 别名]
# 或者: from spatial.tests.factories.SpatialUnitFactory import create [as 别名]
    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,代码行数:31,代码来源:test_forms.py

示例3: test_do_not_send_questionnaire_when_project_has_data

# 需要导入模块: from spatial.tests.factories import SpatialUnitFactory [as 别名]
# 或者: from spatial.tests.factories.SpatialUnitFactory import create [as 别名]
    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,代码行数:30,代码来源:test_forms.py

示例4: test_create_with_blocked_questionnaire_upload

# 需要导入模块: from spatial.tests.factories import SpatialUnitFactory [as 别名]
# 或者: from spatial.tests.factories.SpatialUnitFactory import create [as 别名]
    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,代码行数:12,代码来源:test_views_api.py

示例5: setup_models

# 需要导入模块: from spatial.tests.factories import SpatialUnitFactory [as 别名]
# 或者: from spatial.tests.factories.SpatialUnitFactory import create [as 别名]
    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,代码行数:13,代码来源:test_views_api_tenure_relationships.py

示例6: test_get_xls_download

# 需要导入模块: from spatial.tests.factories import SpatialUnitFactory [as 别名]
# 或者: from spatial.tests.factories.SpatialUnitFactory import create [as 别名]
 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,代码行数:14,代码来源:test_forms.py

示例7: test_get_shape_download

# 需要导入模块: from spatial.tests.factories import SpatialUnitFactory [as 别名]
# 或者: from spatial.tests.factories.SpatialUnitFactory import create [as 别名]
    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,代码行数:54,代码来源:test_forms.py

示例8: test_omit_attribute

# 需要导入模块: from spatial.tests.factories import SpatialUnitFactory [as 别名]
# 或者: from spatial.tests.factories.SpatialUnitFactory import create [as 别名]
 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,代码行数:17,代码来源:test_attr_schemas.py

示例9: test_spatial_unit_attribute_schema

# 需要导入模块: from spatial.tests.factories import SpatialUnitFactory [as 别名]
# 或者: from spatial.tests.factories.SpatialUnitFactory import create [as 别名]
 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,代码行数:28,代码来源:test_attr_schemas.py

示例10: test_spatial_unit_invalid_attribute

# 需要导入模块: from spatial.tests.factories import SpatialUnitFactory [as 别名]
# 或者: from spatial.tests.factories.SpatialUnitFactory import create [as 别名]
 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,代码行数:18,代码来源:test_attr_schemas.py

示例11: setup_models

# 需要导入模块: from spatial.tests.factories import SpatialUnitFactory [as 别名]
# 或者: from spatial.tests.factories.SpatialUnitFactory import create [as 别名]
    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,代码行数:28,代码来源:test_views_default.py

示例12: test_make_download

# 需要导入模块: from spatial.tests.factories import SpatialUnitFactory [as 别名]
# 或者: from spatial.tests.factories.SpatialUnitFactory import create [as 别名]
    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,代码行数:48,代码来源:test_downloads.py

示例13: test_get_absolute_url

# 需要导入模块: from spatial.tests.factories import SpatialUnitFactory [as 别名]
# 或者: from spatial.tests.factories.SpatialUnitFactory import create [as 别名]
 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,代码行数:10,代码来源:test_models.py

示例14: setup_models

# 需要导入模块: from spatial.tests.factories import SpatialUnitFactory [as 别名]
# 或者: from spatial.tests.factories.SpatialUnitFactory import create [as 别名]
    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)
开发者ID:mikael19,项目名称:cadasta-platform,代码行数:60,代码来源:test_views_async.py

示例15: test_geometry

# 需要导入模块: from spatial.tests.factories import SpatialUnitFactory [as 别名]
# 或者: from spatial.tests.factories.SpatialUnitFactory import create [as 别名]
 def test_geometry(self):
     spatial_unit = SpatialUnitFactory.create(
         geometry='SRID=4326;POLYGON(('
         '11.36667 47.25000, '
         '11.41667 47.25000, '
         '11.41667 47.28333, '
         '11.36667 47.28333, '
         '11.36667 47.25000))')
     assert spatial_unit.geometry is not None
开发者ID:mikael19,项目名称:cadasta-platform,代码行数:11,代码来源:test_models.py


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