本文整理汇总了Python中party.tests.factories.PartyFactory类的典型用法代码示例。如果您正苦于以下问题:Python PartyFactory类的具体用法?Python PartyFactory怎么用?Python PartyFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PartyFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_models
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
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
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_repr
def test_repr(self):
project = ProjectFactory.build(slug='prj')
party1 = PartyFactory.build(id='abc123', project=project)
party2 = PartyFactory.build(id='def456', project=project)
relationship = PartyRelationshipFactory.build(
id='abc123',
project=project,
party1=party1,
party2=party2,
type='C')
assert repr(relationship) == ('<PartyRelationship id=abc123'
' party1=abc123 party2=def456'
' project=prj type=C>')
示例5: test_render
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)
示例6: test_post_with_authorized_invalid_existing_party_data
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
示例7: test_ui_detail_url
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))
示例8: test_add_attribute_fields
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'
示例9: 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)
示例10: test_party_attribute_schema
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'
示例11: test_format_create_resource
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()
示例12: test_update_invalid_record_with_different_project
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)
)
示例13: test_party_invalid_attribute
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'
}
)
示例14: 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)
示例15: test_create_invalid_record_with_different_project
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))