本文整理匯總了Python中resources.tests.factories.ResourceFactory類的典型用法代碼示例。如果您正苦於以下問題:Python ResourceFactory類的具體用法?Python ResourceFactory怎麽用?Python ResourceFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ResourceFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setup_models
def setup_models(self):
self.project = ProjectFactory.create()
self.relationship = TenureRelationshipFactory.create(
project=self.project)
self.attached = ResourceFactory.create(
project=self.project, content_object=self.relationship)
self.unattached = ResourceFactory.create(project=self.project)
示例2: test_archived_resources_not_listed
def test_archived_resources_not_listed(self):
ResourceFactory.create(
project=self.prj, content_object=self.su, archived=True)
response = self.request(user=self.user)
assert response.status_code == 200
assert len(response.content) == 2
returned_ids = [r['id'] for r in response.content]
assert all(res.id in returned_ids for res in self.resources)
示例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.su = SpatialUnitFactory.create(project=self.prj)
self.resources = ResourceFactory.create_batch(
2, project=self.prj, content_object=self.su)
ResourceFactory.create(project=self.prj)
self.file = self.get_file('/resources/tests/files/image.jpg', 'rb')
self.file_name = self.storage.save('resources/image.jpg', self.file)
示例4: test_reverse_ordering
def test_reverse_ordering(self):
su = SpatialUnitFactory.create(project=self.prj)
ResourceFactory.create_from_kwargs([
{'content_object': su, 'project': self.prj, 'name': 'A'},
{'content_object': su, 'project': self.prj, 'name': 'B'},
{'content_object': su, 'project': self.prj, 'name': 'C'},
])
response = self.request(
user=self.user,
url_kwargs={'location': su.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))
示例5: test_add_existing_resource
def test_add_existing_resource(self):
new_resource = ResourceFactory.create()
data = {'id': new_resource.id}
response = self.request(method='POST', user=self.user, post_data=data)
assert response.status_code == 201
assert self.su.resources.count() == 3
assert new_resource in self.su.resources
示例6: setup_models
def setup_models(self):
self.prj = ProjectFactory.create()
self.party = PartyFactory.create(project=self.prj)
self.resource = ResourceFactory.create(content_object=self.party,
project=self.prj)
self.user = UserFactory.create()
assign_policies(self.user)
示例7: test_ordering
def test_ordering(self):
party = PartyFactory.create(project=self.prj)
ResourceFactory.create_from_kwargs([
{'content_object': party, 'project': self.prj, 'name': 'A'},
{'content_object': party, 'project': self.prj, 'name': 'B'},
{'content_object': party, 'project': self.prj, 'name': 'C'},
])
response = self.request(
user=self.user,
url_kwargs={'party': party.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))
示例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_delete_resource_with_invalid_resource
def test_delete_resource_with_invalid_resource(self):
new_resource = ResourceFactory.create(project=self.prj)
response = self.request(method='DELETE', user=self.user, url_kwargs={
'resource': new_resource.id
})
assert response.status_code == 404
assert response.content['detail'] == "Not found."
assert len(self.su.resources) == 1
assert Resource.objects.filter(
id=self.resource.id, project=self.prj).exists()
示例11: test_search_filter
def test_search_filter(self):
not_found = self.storage.save('resources/bild.jpg', self.file)
su = SpatialUnitFactory.create(project=self.prj)
ResourceFactory.create_from_kwargs([
{'content_object': su, 'project': self.prj,
'file': self.file_name},
{'content_object': su, 'project': self.prj,
'file': self.file_name},
{'content_object': su, 'project': self.prj,
'file': not_found}
])
response = self.request(
user=self.user,
url_kwargs={'organization': self.prj.organization.slug,
'project': self.prj.slug,
'location': su.id},
get_data={'search': 'image'})
assert response.status_code == 200
assert len(response.content) == 2
示例12: test_detach_party_resources
def test_detach_party_resources(self):
project = ProjectFactory.create()
party = PartyFactory.create(project=project)
resource = ResourceFactory.create(project=project)
resource.content_objects.create(
content_object=party)
assert ContentObject.objects.filter(
object_id=party.id, resource=resource).exists()
assert resource in party.resources
party.delete()
assert not ContentObject.objects.filter(
object_id=party.id, resource=resource).exists()
示例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: test_detach_spatial_unit_resources
def test_detach_spatial_unit_resources(self):
project = ProjectFactory.create()
su = SpatialUnitFactory.create(project=project)
resource = ResourceFactory.create(project=project)
resource.content_objects.create(
content_object=su)
assert ContentObject.objects.filter(
object_id=su.id,
resource=resource,).exists()
assert resource in su.resources
su.delete()
assert not ContentObject.objects.filter(
object_id=su.id, resource=resource).exists()
示例15: test_make_download
def test_make_download(self):
ensure_dirs()
project = ProjectFactory.create()
exporter = ResourceExporter(project)
res = ResourceFactory.create(project=project)
t = round(time.time() * 1000)
path, mime = exporter.make_download("res-test-" + str(t))
assert path == os.path.join(settings.MEDIA_ROOT, "temp/res-test-{}.zip".format(t))
assert mime == "application/zip"
with ZipFile(path, "r") as testzip:
assert len(testzip.namelist()) == 2
assert res.original_file in testzip.namelist()
assert "resources.xlsx" in testzip.namelist()