本文整理匯總了Python中party.tests.factories.PartyFactory.create方法的典型用法代碼示例。如果您正苦於以下問題:Python PartyFactory.create方法的具體用法?Python PartyFactory.create怎麽用?Python PartyFactory.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類party.tests.factories.PartyFactory
的用法示例。
在下文中一共展示了PartyFactory.create方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setup_models
# 需要導入模塊: from party.tests.factories import PartyFactory [as 別名]
# 或者: from party.tests.factories.PartyFactory import create [as 別名]
def setup_models(self):
self.user = UserFactory.create()
assign_policies(self.user)
self.org = OrganizationFactory.create(slug="namati")
self.prj = ProjectFactory.create(slug="test-project", organization=self.org, access="public")
self.party1 = PartyFactory.create(project=self.prj, name="Landowner")
self.party2 = PartyFactory.create(project=self.prj, name="Leaser")
示例2: setup_models
# 需要導入模塊: from party.tests.factories import PartyFactory [as 別名]
# 或者: from party.tests.factories.PartyFactory import create [as 別名]
def setup_models(self):
self.user = UserFactory.create()
assign_policies(self.user)
self.org = OrganizationFactory.create(slug='namati')
self.prj = ProjectFactory.create(
slug='test-project', organization=self.org, access='public')
self.party1 = PartyFactory.create(project=self.prj, name='Landowner')
self.party2 = PartyFactory.create(project=self.prj, name='Leaser')
示例3: setup_models
# 需要導入模塊: from party.tests.factories import PartyFactory [as 別名]
# 或者: from party.tests.factories.PartyFactory 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)
示例4: test_render
# 需要導入模塊: from party.tests.factories import PartyFactory [as 別名]
# 或者: from party.tests.factories.PartyFactory import create [as 別名]
def test_render(self):
project = ProjectFactory.create()
party_1 = PartyFactory.create(project=project)
party_2 = PartyFactory.create(project=project)
widget = SelectPartyWidget(project=project)
rendered = widget.render(name='name', value='value')
assert ('<select id="party-select" name="name" class="form-control" '
' data-parsley-required="true">' in rendered)
assert ('<option value="' + party_1.id + '" data-type="'
'' + party_1.get_type_display() + '">' + party_1.name + ''
'</option>' in rendered)
assert ('<option value="' + party_2.id + '" data-type="'
'' + party_2.get_type_display() + '">' + party_2.name + ''
'</option>' in rendered)
示例5: setup_models
# 需要導入模塊: from party.tests.factories import PartyFactory [as 別名]
# 或者: from party.tests.factories.PartyFactory 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_add_attribute_fields
# 需要導入模塊: from party.tests.factories import PartyFactory [as 別名]
# 或者: from party.tests.factories.PartyFactory import create [as 別名]
def test_add_attribute_fields(self):
party = PartyFactory.create()
form = MockAttributeModelForm(self.project, instance=party)
assert len(form.fields) == 6
attr = form.fields.get('party::gr::homeowner')
assert attr is not None
assert attr.label == 'Homeowner'
示例7: test_format_create_resource
# 需要導入模塊: from party.tests.factories import PartyFactory [as 別名]
# 或者: from party.tests.factories.PartyFactory import create [as 別名]
def test_format_create_resource(self):
party = PartyFactory.create(project=self.project)
file_name = 'test_image_two.png'
file = open(
path + '/xforms/tests/files/test_image_two.png', 'rb'
).read()
file_data = InMemoryUploadedFile(
file=io.BytesIO(file),
field_name='test_image_two',
name=file_name,
content_type='image/png',
size=len(file),
charset='utf-8',
)
files = {file_name: file_data}
data = {
'parties': [{'id': party.id, 'resources': [file_name]}],
'locations': [{'id': '1234', 'resources': ['not_created.png']}]
}
mh()._format_create_resource(data, self.user, self.project,
files, file_name,
'parties', Party)
assert Resource.objects.all().count() == 1
resource = Resource.objects.get(name='test_image_two.png')
assert resource in party.resources.all()
示例8: test_party_attribute_schema
# 需要導入模塊: from party.tests.factories import PartyFactory [as 別名]
# 或者: from party.tests.factories.PartyFactory import create [as 別名]
def test_party_attribute_schema(self):
project = ProjectFactory.create(name='TestProject')
QuestionnaireFactory.create(project=project)
content_type = ContentType.objects.get(
app_label='party', model='party')
create_attrs_schema(
project=project, dict=individual_party_xform_group,
content_type=content_type, errors=[])
party = PartyFactory.create(
name='TestParty', project=project,
type='IN',
attributes={
'homeowner': 'yes',
'dob': '1980-01-01'
}
)
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, party.type]
assert 'homeowner' in party.attributes.attributes
assert 'dob' in party.attributes.attributes
assert 'gender' in party.attributes.attributes
assert 3 == Attribute.objects.filter(schema=schema).count()
assert party.attributes['homeowner'] == 'yes'
assert party.attributes['dob'] == '1980-01-01'
示例9: test_post_with_authorized_invalid_existing_party_data
# 需要導入模塊: from party.tests.factories import PartyFactory [as 別名]
# 或者: from party.tests.factories.PartyFactory import create [as 別名]
def test_post_with_authorized_invalid_existing_party_data(self):
user = UserFactory.create()
assign_policies(user)
party = PartyFactory.create(project=self.project)
response = self.request(method='POST',
user=user,
post_data={'new_entity': ''})
data = self.post_data.copy()
data['new_entity'] = ''
form = forms.TenureRelationshipForm(
project=self.project,
spatial_unit=self.spatial_unit,
data=data,
schema_selectors=(
{'name': 'organization',
'value': self.project.organization,
'selector': self.project.organization.id},
{'name': 'project',
'value': self.project,
'selector': self.project.id},
{'name': 'questionnaire',
'value': self.project.current_questionnaire,
'selector': self.project.current_questionnaire}
)
)
assert response.status_code == 200
expected = self.render_content(form=form)
assert response.content == expected
assert TenureRelationship.objects.count() == 0
assert Party.objects.count() == 1
assert Party.objects.first().name == party.name
示例10: test_ui_detail_url
# 需要導入模塊: from party.tests.factories import PartyFactory [as 別名]
# 或者: from party.tests.factories.PartyFactory import create [as 別名]
def test_ui_detail_url(self):
party = PartyFactory.create()
assert party.ui_detail_url == (
'/organizations/{org}/projects/{prj}/records/parties/{id}/'.format(
org=party.project.organization.slug,
prj=party.project.slug,
id=party.id))
示例11: test_update_invalid_record_with_different_project
# 需要導入模塊: from party.tests.factories import PartyFactory [as 別名]
# 或者: from party.tests.factories.PartyFactory import create [as 別名]
def test_update_invalid_record_with_different_project(self):
other_party = PartyFactory.create(name="Other")
response = self.request(user=self.user, method="PATCH", post_data={"party2": other_party.id})
assert response.status_code == 400
err_msg = "'party1' project ({}) should be equal to 'party2' project ({})"
assert response.content["non_field_errors"][0] == (
err_msg.format(self.party1.project.slug, other_party.project.slug)
)
示例12: test_party_invalid_attribute
# 需要導入模塊: from party.tests.factories import PartyFactory [as 別名]
# 或者: from party.tests.factories.PartyFactory import create [as 別名]
def test_party_invalid_attribute(self):
project = ProjectFactory.create(name='TestProject')
QuestionnaireFactory.create(project=project)
content_type = ContentType.objects.get(
app_label='party', model='party')
create_attrs_schema(
project=project, dict=individual_party_xform_group,
content_type=content_type, errors=[])
assert 1 == Schema.objects.all().count()
with pytest.raises(KeyError):
PartyFactory.create(
name='TestParty', project=project,
attributes={
'invalid_attribute': 'yes',
'dob': '1980-01-01'
}
)
示例13: setup_models
# 需要導入模塊: from party.tests.factories import PartyFactory [as 別名]
# 或者: from party.tests.factories.PartyFactory 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)
示例14: test_create_invalid_record_with_different_project
# 需要導入模塊: from party.tests.factories import PartyFactory [as 別名]
# 或者: from party.tests.factories.PartyFactory import create [as 別名]
def test_create_invalid_record_with_different_project(self):
other_party = PartyFactory.create(name="Other")
invalid_data = {"party1": self.party1.id, "party2": other_party.id, "type": "C"}
response = self.request(user=self.user, method="POST", post_data=invalid_data)
assert response.status_code == 400
assert PartyRelationship.objects.count() == 0
err_msg = "'party1' project ({}) should be equal to 'party2' " "project ({})"
assert response.content["non_field_errors"][0] == (err_msg.format(self.prj.slug, other_party.project.slug))
示例15: test_get_shape_download
# 需要導入模塊: from party.tests.factories import PartyFactory [as 別名]
# 或者: from party.tests.factories.PartyFactory 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()