本文整理汇总了Python中party.tests.factories.TenureRelationshipFactory类的典型用法代码示例。如果您正苦于以下问题:Python TenureRelationshipFactory类的具体用法?Python TenureRelationshipFactory怎么用?Python TenureRelationshipFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TenureRelationshipFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_project_relationship_invalid
def test_project_relationship_invalid(self):
with pytest.raises(exceptions.ProjectRelationshipError):
project = ProjectFactory()
TenureRelationshipFactory.create(
party__project=project,
spatial_unit__project=project
)
示例2: test_get_with_questionnaire
def test_get_with_questionnaire(self):
questionnaire = q_factories.QuestionnaireFactory.create()
self.project.current_questionnaire = questionnaire.id
self.project.save()
location_type_question = q_factories.QuestionFactory.create(
questionnaire=questionnaire,
name='location_type',
label={'en': 'Location type', 'de': 'Parzelle Typ'},
type='S1')
q_factories.QuestionOptionFactory.create(
question=location_type_question,
name=self.location.type,
label={'en': 'House', 'de': 'Haus'})
tenure_type_question = q_factories.QuestionFactory.create(
questionnaire=questionnaire,
name='tenure_type',
label={'en': 'Location type', 'de': 'Parzelle Typ'},
type='S1')
q_factories.QuestionOptionFactory.create(
question=tenure_type_question,
name='LH',
label={'en': 'Leasehold', 'de': 'Miete'})
q_factories.QuestionOptionFactory.create(
question=tenure_type_question,
name='WR',
label={'en': 'Water rights', 'de': 'Wasserecht'})
lh_ten = TenureRelationshipFactory.create(
tenure_type=TenureRelationshipType.objects.get(id='LH'),
spatial_unit=self.location,
project=self.project)
lh_ten.type_labels = ('data-label-de="Miete" '
'data-label-en="Leasehold"')
wr_ten = TenureRelationshipFactory.create(
tenure_type=TenureRelationshipType.objects.get(id='WR'),
spatial_unit=self.location,
project=self.project)
wr_ten.type_labels = ('data-label-de="Wasserecht" '
'data-label-en="Water rights"')
user = UserFactory.create()
assign_policies(user)
response = self.request(user=user)
assert response.status_code == 200
assert response.content == self.render_content(
type_labels=('data-label-de="Parzelle Typ" '
'data-label-en="Location type"'),
type_choice_labels=('data-label-de="Haus" data-label-en="House"'),
relationships=[wr_ten, lh_ten],
form_lang_default='en',
form_langs=[('en', 'English'), ('de', 'German')]
)
示例3: 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()
示例4: test_get_values
def test_get_values(self):
project = ProjectFactory.create(current_questionnaire="123abc")
exporter = Exporter(project)
content_type = ContentType.objects.get(app_label="party", model="tenurerelationship")
schema = Schema.objects.create(
content_type=content_type, selectors=(project.organization.id, project.id, "123abc")
)
text_type = AttributeType.objects.get(name="text")
select_m_type = AttributeType.objects.get(name="select_multiple")
attr = Attribute.objects.create(
schema=schema, name="key", long_name="Test field", attr_type=text_type, index=0, required=False, omit=False
)
attr2 = Attribute.objects.create(
schema=schema,
name="key_2",
long_name="Test select multiple field",
attr_type=select_m_type,
index=1,
choices=["choice_1", "choice_2", "choice_3"],
choice_labels=["Choice 1", "Choice 2", "Choice 3"],
required=False,
omit=False,
)
ttype = TenureRelationshipType.objects.get(id="LH")
item = TenureRelationshipFactory.create(
project=project, tenure_type=ttype, attributes={"key": "text", "key_2": ["choice_1", "choice_2"]}
)
model_attrs = ("id", "party_id", "spatial_unit_id", "tenure_type.label")
schema_attrs = [attr, attr2]
values = exporter.get_values(item, model_attrs, schema_attrs)
assert values == [item.id, item.party_id, item.spatial_unit_id, "Leasehold", "text", "choice_1, choice_2"]
示例5: test_ui_detail_url
def test_ui_detail_url(self):
tenurerel = TenureRelationshipFactory.create()
assert tenurerel.ui_detail_url == (
'/organizations/{org}/projects/{prj}/relationships/{id}/'.format(
org=tenurerel.project.organization.slug,
prj=tenurerel.project.slug,
id=tenurerel.id))
示例6: 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)
示例7: test_tenure_relationship_invalid_attribute
def test_tenure_relationship_invalid_attribute(self):
project = ProjectFactory.create(name='TestProject')
QuestionnaireFactory.create(project=project)
content_type = ContentType.objects.get(
app_label='party', model='tenurerelationship')
create_attrs_schema(
project=project, dict=tenure_relationship_xform_group,
content_type=content_type, errors=[])
assert 1 == Schema.objects.all().count()
with pytest.raises(KeyError):
TenureRelationshipFactory.create(
project=project,
attributes={
'invalid_attribute': 'yes',
}
)
示例8: setup_models
def setup_models(self):
self.prj = ProjectFactory.create()
self.tenure = TenureRelationshipFactory.create(
project=self.prj)
self.resource = ResourceFactory.create(content_object=self.tenure,
project=self.prj)
self.user = UserFactory.create()
assign_policies(self.user)
示例9: 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)
示例10: test_set_attributes
def test_set_attributes(self):
tenure_relationship = TenureRelationshipFactory.create()
attributes = {
'description':
'Additional attribute data'
}
tenure_relationship.attributes = attributes
tenure_relationship.save()
assert attributes[
'description'] == tenure_relationship.attributes['description']
示例11: test_str
def test_str(self):
project = ProjectFactory.build(name='TestProject')
tenure_type = TenureRelationshipType(id='LS', label="Leasehold")
relationship = TenureRelationshipFactory.build(
project=project,
party__project=project,
party__name='Family',
spatial_unit__project=project,
spatial_unit__type='PA',
tenure_type=tenure_type)
assert str(relationship) == (
"<TenureRelationship: <Family> Leasehold <Parcel>>")
示例12: test_repr
def test_repr(self):
project = ProjectFactory.build(slug='prj')
party = PartyFactory.build(id='abc123', project=project)
su = SpatialUnitFactory.build(id='def456', project=project)
relationship = TenureRelationshipFactory.build(
id='abc123',
project=project,
party=party,
spatial_unit=su,
tenure_type=TenureRelationshipType(id='CR'))
assert repr(relationship) == ('<TenureRelationship id=abc123'
' party=abc123 spatial_unit=def456'
' project=prj tenure_type=CR>')
示例13: test_detach_tenure_relationship_resources
def test_detach_tenure_relationship_resources(self):
project = ProjectFactory.create()
tenure = TenureRelationshipFactory.create(project=project)
resource = ResourceFactory.create(project=project)
resource.content_objects.create(
content_object=tenure)
assert ContentObject.objects.filter(
object_id=tenure.id,
resource=resource,).exists()
assert resource in tenure.resources
tenure.delete()
assert not ContentObject.objects.filter(
object_id=tenure.id, resource=resource).exists()
示例14: setUp
def setUp(self):
super().setUp()
self.project = ProjectFactory.create(current_questionnaire="123abc")
self.content_type = ContentType.objects.get(app_label="spatial", model="spatialunit")
schema = Schema.objects.create(
content_type=self.content_type, selectors=(self.project.organization.id, self.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
)
self.spatialunit_1 = SpatialUnitFactory.create(
project=self.project, geometry="POINT (1 1)", attributes={"key": "value 1"}
)
self.spatialunit_2 = SpatialUnitFactory.create(
project=self.project, geometry="POINT (2 2)", attributes={"key": "value 2"}
)
self.spatialunits = [self.spatialunit_1, self.spatialunit_2]
self.attrs = ["id", "geometry.ewkt"]
self.parties = PartyFactory.create_batch(project=self.project, size=2)
TenureRelationshipFactory.create(project=self.project, party=self.parties[0], spatial_unit=self.spatialunit_1)
示例15: test_reverse_ordering
def test_reverse_ordering(self):
tenure = TenureRelationshipFactory.create(
project=self.prj)
ResourceFactory.create_from_kwargs([
{'content_object': tenure, 'project': self.prj, 'name': 'A'},
{'content_object': tenure, 'project': self.prj, 'name': 'B'},
{'content_object': tenure, 'project': self.prj, 'name': 'C'},
])
response = self.request(
user=self.user,
url_kwargs={'tenure_rel_id': tenure.id},
get_data={'ordering': '-name'})
assert response.status_code == 200
assert len(response.content) == 3
names = [resource['name'] for resource in response.content]
assert(names == sorted(names, reverse=True))