本文整理汇总了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
示例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
示例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'))
示例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'))
示例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)
示例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"
示例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()
示例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>')
示例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',
}
)
示例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
示例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)
示例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',
}
)
示例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
示例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))
示例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()