本文整理汇总了Python中spatial.tests.factories.SpatialUnitFactory类的典型用法代码示例。如果您正苦于以下问题:Python SpatialUnitFactory类的具体用法?Python SpatialUnitFactory怎么用?Python SpatialUnitFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SpatialUnitFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: setup_models
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,代码行数:58,代码来源:test_views_async.py
示例17: test_geometry
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,代码行数:9,代码来源:test_models.py
示例18: test_write_features
def test_write_features(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
)
su1 = SpatialUnitFactory.create(project=project, geometry="POINT (1 1)", attributes={"key": "value 1"})
su2 = SpatialUnitFactory.create(project=project, geometry="POINT (2 2)", attributes={"key": "value 2"})
dst_dir = os.path.join(settings.MEDIA_ROOT, "temp/file4")
ds = exporter.create_datasource(dst_dir, "file4")
layers = exporter.create_shp_layers(ds, "file4")
csvfile = os.path.join(dst_dir, "locations.csv")
exporter.write_features(layers, csvfile)
assert len(layers[0]) == 2
f = layers[0].GetNextFeature()
while f:
geom = f.geometry()
assert geom.ExportToWkt() in ["POINT (1 1)", "POINT (2 2)"]
assert f.GetFieldAsString("id") in [su1.id, su2.id]
f = layers[0].GetNextFeature()
ds.Destroy()
with open(csvfile) as csvfile:
csvreader = csv.reader(csvfile)
for i, row in enumerate(csvreader):
if i == 0:
assert row == ["id", "type", "key"]
elif row[0] == su1.id:
assert row == [su1.id, su1.type, "value 1"]
elif row[1] == su2.id:
assert row == [su2.id, su2.type, "value 2"]
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:44,代码来源:test_downloads.py
示例19: test_get_values_null_geom
def test_get_values_null_geom(self):
project = ProjectFactory.create(current_questionnaire='123abc')
exporter = Exporter(project)
item = SpatialUnitFactory.create(
project=project,
geometry=None)
content_type = ContentType.objects.get(app_label='spatial',
model='spatialunit')
model_attrs = ('id', 'geometry.wkt')
schema_attrs = exporter.get_schema_attrs(content_type)
values = exporter.get_values(item, model_attrs, schema_attrs)
assert values == {'id': item.id, 'geometry.wkt': None}
开发者ID:mikael19,项目名称:cadasta-platform,代码行数:12,代码来源:test_downloads.py
示例20: test_reassign_extent
def test_reassign_extent(self):
spatial_unit = SpatialUnitFactory.create(
geometry='SRID=4326;POLYGON(('
'211.36667 47.25000, '
'211.41667 47.25000, '
'211.41667 47.28333, '
'211.36667 47.28333, '
'211.36667 47.25000))'
)
assert spatial_unit.geometry.boundary.coords == (
(-148.63333, 47.25), (-148.58333, 47.25), (-148.58333, 47.28333),
(-148.63333, 47.28333), (-148.63333, 47.25))
开发者ID:mikael19,项目名称:cadasta-platform,代码行数:12,代码来源:test_models.py
注:本文中的spatial.tests.factories.SpatialUnitFactory类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论