本文整理汇总了Python中party.tests.factories.TenureRelationshipFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Python TenureRelationshipFactory.create方法的具体用法?Python TenureRelationshipFactory.create怎么用?Python TenureRelationshipFactory.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类party.tests.factories.TenureRelationshipFactory
的用法示例。
在下文中一共展示了TenureRelationshipFactory.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_project_relationship_invalid
# 需要导入模块: from party.tests.factories import TenureRelationshipFactory [as 别名]
# 或者: from party.tests.factories.TenureRelationshipFactory import create [as 别名]
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
# 需要导入模块: from party.tests.factories import TenureRelationshipFactory [as 别名]
# 或者: from party.tests.factories.TenureRelationshipFactory import create [as 别名]
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
# 需要导入模块: from party.tests.factories import TenureRelationshipFactory [as 别名]
# 或者: from party.tests.factories.TenureRelationshipFactory 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()
示例4: test_get_values
# 需要导入模块: from party.tests.factories import TenureRelationshipFactory [as 别名]
# 或者: from party.tests.factories.TenureRelationshipFactory import create [as 别名]
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: setup_models
# 需要导入模块: from party.tests.factories import TenureRelationshipFactory [as 别名]
# 或者: from party.tests.factories.TenureRelationshipFactory 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)
示例6: test_ui_detail_url
# 需要导入模块: from party.tests.factories import TenureRelationshipFactory [as 别名]
# 或者: from party.tests.factories.TenureRelationshipFactory import create [as 别名]
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))
示例7: test_tenure_relationship_invalid_attribute
# 需要导入模块: from party.tests.factories import TenureRelationshipFactory [as 别名]
# 或者: from party.tests.factories.TenureRelationshipFactory import create [as 别名]
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
# 需要导入模块: from party.tests.factories import TenureRelationshipFactory [as 别名]
# 或者: from party.tests.factories.TenureRelationshipFactory import create [as 别名]
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
# 需要导入模块: from party.tests.factories import TenureRelationshipFactory [as 别名]
# 或者: from party.tests.factories.TenureRelationshipFactory 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)
示例10: test_set_attributes
# 需要导入模块: from party.tests.factories import TenureRelationshipFactory [as 别名]
# 或者: from party.tests.factories.TenureRelationshipFactory import create [as 别名]
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_detach_tenure_relationship_resources
# 需要导入模块: from party.tests.factories import TenureRelationshipFactory [as 别名]
# 或者: from party.tests.factories.TenureRelationshipFactory import create [as 别名]
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()
示例12: setUp
# 需要导入模块: from party.tests.factories import TenureRelationshipFactory [as 别名]
# 或者: from party.tests.factories.TenureRelationshipFactory import create [as 别名]
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)
示例13: test_reverse_ordering
# 需要导入模块: from party.tests.factories import TenureRelationshipFactory [as 别名]
# 或者: from party.tests.factories.TenureRelationshipFactory import create [as 别名]
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))
示例14: test_tenure_relationship_schema
# 需要导入模块: from party.tests.factories import TenureRelationshipFactory [as 别名]
# 或者: from party.tests.factories.TenureRelationshipFactory import create [as 别名]
def test_tenure_relationship_schema(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=[])
tr = TenureRelationshipFactory.create(
project=project, attributes={
'notes': 'Some additional textual info'}
)
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 'notes' in tr.attributes.attributes
示例15: test_detach_deferred_tenure_relationship_resources
# 需要导入模块: from party.tests.factories import TenureRelationshipFactory [as 别名]
# 或者: from party.tests.factories.TenureRelationshipFactory import create [as 别名]
def test_detach_deferred_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()
tenure_deferred = TenureRelationship.objects.all(
).defer('attributes')[0]
assert resource in tenure_deferred.resources
tenure_deferred.delete()
assert not ContentObject.objects.filter(
object_id=tenure.id, resource=resource).exists()
assert TenureRelationship.objects.all().count() == 0