本文整理汇总了Python中tests.factories.PreprintFactory.reload方法的典型用法代码示例。如果您正苦于以下问题:Python PreprintFactory.reload方法的具体用法?Python PreprintFactory.reload怎么用?Python PreprintFactory.reload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.factories.PreprintFactory
的用法示例。
在下文中一共展示了PreprintFactory.reload方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestPreprintProviders
# 需要导入模块: from tests.factories import PreprintFactory [as 别名]
# 或者: from tests.factories.PreprintFactory import reload [as 别名]
class TestPreprintProviders(OsfTestCase):
def setUp(self):
super(TestPreprintProviders, self).setUp()
self.preprint = PreprintFactory(providers=[])
self.provider = PreprintProviderFactory(name='WWEArxiv')
def test_add_provider(self):
assert_not_equal(self.preprint.provider, self.provider)
self.preprint.provider = self.provider
self.preprint.save()
self.preprint.reload()
assert_equal(self.preprint.provider, self.provider)
def test_remove_provider(self):
self.preprint.provider = None
self.preprint.save()
self.preprint.reload()
assert_equal(self.preprint.provider, None)
示例2: TestPreprintServicePermissions
# 需要导入模块: from tests.factories import PreprintFactory [as 别名]
# 或者: from tests.factories.PreprintFactory import reload [as 别名]
class TestPreprintServicePermissions(OsfTestCase):
def setUp(self):
super(TestPreprintServicePermissions, self).setUp()
self.user = AuthUserFactory()
self.write_contrib = AuthUserFactory()
self.project = ProjectFactory(creator=self.user)
self.project.add_contributor(self.write_contrib, permissions=[permissions.WRITE])
self.preprint = PreprintFactory(project=self.project, is_published=False)
def test_nonadmin_cannot_set_subjects(self):
initial_subjects = self.preprint.subjects
with assert_raises(PermissionsError):
self.preprint.set_subjects([[SubjectFactory()._id]], auth=Auth(self.write_contrib), save=True)
self.preprint.reload()
assert_equal(initial_subjects, self.preprint.subjects)
def test_nonadmin_cannot_set_file(self):
initial_file = self.preprint.primary_file
file = OsfStorageFile.create(
is_file=True,
node=self.project,
path='/panda.txt',
name='panda.txt',
materialized_path='/panda.txt')
file.save()
with assert_raises(PermissionsError):
self.preprint.set_primary_file(file, auth=Auth(self.write_contrib), save=True)
self.preprint.reload()
self.preprint.node.reload()
assert_equal(initial_file._id, self.preprint.primary_file._id)
def test_nonadmin_cannot_publish(self):
assert_false(self.preprint.is_published)
with assert_raises(PermissionsError):
self.preprint.set_published(True, auth=Auth(self.write_contrib), save=True)
assert_false(self.preprint.is_published)
def test_admin_can_set_subjects(self):
initial_subjects = self.preprint.subjects
self.preprint.set_subjects([[SubjectFactory()._id]], auth=Auth(self.user), save=True)
self.preprint.reload()
assert_not_equal(initial_subjects, self.preprint.subjects)
def test_admin_can_set_file(self):
initial_file = self.preprint.primary_file
file = OsfStorageFile.create(
is_file=True,
node=self.project,
path='/panda.txt',
name='panda.txt',
materialized_path='/panda.txt')
file.save()
self.preprint.set_primary_file(file, auth=Auth(self.user), save=True)
self.preprint.reload()
self.preprint.node.reload()
assert_not_equal(initial_file._id, self.preprint.primary_file._id)
assert_equal(file._id, self.preprint.primary_file._id)
def test_admin_can_publish(self):
assert_false(self.preprint.is_published)
self.preprint.set_published(True, auth=Auth(self.user), save=True)
assert_true(self.preprint.is_published)
def test_admin_cannot_unpublish(self):
assert_false(self.preprint.is_published)
self.preprint.set_published(True, auth=Auth(self.user), save=True)
assert_true(self.preprint.is_published)
with assert_raises(ValueError) as e:
self.preprint.set_published(False, auth=Auth(self.user), save=True)
assert_in('Cannot unpublish', e.exception.message)
示例3: TestPreprintUpdate
# 需要导入模块: from tests.factories import PreprintFactory [as 别名]
# 或者: from tests.factories.PreprintFactory import reload [as 别名]
class TestPreprintUpdate(ApiTestCase):
def setUp(self):
super(TestPreprintUpdate, self).setUp()
self.user = AuthUserFactory()
self.preprint = PreprintFactory(creator=self.user)
self.url = '/{}preprints/{}/'.format(API_BASE, self.preprint._id)
self.subject = SubjectFactory()
def test_update_preprint_title(self):
update_title_payload = build_preprint_update_payload(self.preprint._id, attributes={'title': 'A new title'})
res = self.app.patch_json_api(self.url, update_title_payload, auth=self.user.auth)
assert_equal(res.status_code, 200)
self.preprint.reload()
assert_equal(self.preprint.title, 'A new title')
def test_update_preprint_tags(self):
update_tags_payload = build_preprint_update_payload(self.preprint._id, attributes={'tags': ['newtag', 'bluetag']})
res = self.app.patch_json_api(self.url, update_tags_payload, auth=self.user.auth)
assert_equal(res.status_code, 200)
self.preprint.reload()
assert_in('newtag', self.preprint.tags)
assert_in('bluetag', self.preprint.tags)
assert_in('tag_added', [l.action for l in self.preprint.logs])
def test_update_preprint_tags_not_list(self):
update_tags_payload = build_preprint_update_payload(self.preprint._id, attributes={'tags': 'newtag'})
res = self.app.patch_json_api(self.url, update_tags_payload, auth=self.user.auth, expect_errors=True)
assert_equal(res.status_code, 400)
def test_update_preprint_none_tags(self):
update_tags_payload = build_preprint_update_payload(self.preprint._id, attributes={'tags': [None]})
res = self.app.patch_json_api(self.url, update_tags_payload, auth=self.user.auth, expect_errors=True)
assert_equal(res.status_code, 400)
def test_update_preprint_subjects(self):
assert_not_equal(self.preprint.preprint_subjects[0], self.subject._id)
update_subjects_payload = build_preprint_update_payload(self.preprint._id, attributes={"subjects": [self.subject._id]})
res = self.app.patch_json_api(self.url, update_subjects_payload, auth=self.user.auth)
assert_equal(res.status_code, 200)
self.preprint.reload()
assert_equal(self.preprint.preprint_subjects[0], self.subject)
def test_update_invalid_subjects(self):
preprint_subjects = self.preprint.preprint_subjects
update_subjects_payload = build_preprint_update_payload(self.preprint._id, attributes={"subjects": ['wwe']})
res = self.app.patch_json_api(self.url, update_subjects_payload, auth=self.user.auth, expect_errors=True)
assert_equal(res.status_code, 400)
self.preprint.reload()
assert_equal(self.preprint.preprint_subjects, preprint_subjects)
def test_update_primary_file(self):
new_file = test_utils.create_test_file(self.preprint, 'openupthatwindow.pdf')
relationships = {
"primary_file": {
"data": {
"type": "file",
"id": new_file._id
}
}
}
assert_not_equal(self.preprint.preprint_file, new_file)
update_file_payload = build_preprint_update_payload(self.preprint._id, relationships=relationships)
res = self.app.patch_json_api(self.url, update_file_payload, auth=self.user.auth)
assert_equal(res.status_code, 200)
self.preprint.reload()
assert_equal(self.preprint.preprint_file, new_file)
def test_new_primary_not_in_node(self):
project = ProjectFactory()
file_for_project = test_utils.create_test_file(project, 'letoutthatantidote.pdf')
relationships = {
"primary_file": {
"data": {
"type": "file",
"id": file_for_project._id
}
}
}
update_file_payload = build_preprint_update_payload(self.preprint._id, relationships=relationships)
res = self.app.patch_json_api(self.url, update_file_payload, auth=self.user.auth, expect_errors=True)
assert_equal(res.status_code, 400)
self.preprint.reload()
#.........这里部分代码省略.........
示例4: TestPreprintUpdate
# 需要导入模块: from tests.factories import PreprintFactory [as 别名]
# 或者: from tests.factories.PreprintFactory import reload [as 别名]
class TestPreprintUpdate(ApiTestCase):
def setUp(self):
super(TestPreprintUpdate, self).setUp()
self.user = AuthUserFactory()
self.preprint = PreprintFactory(creator=self.user)
self.url = '/{}preprints/{}/'.format(API_BASE, self.preprint._id)
self.subject = SubjectFactory()
def test_update_preprint_permission_denied(self):
update_doi_payload = build_preprint_update_payload(self.preprint._id, attributes={'article_doi': '10.123/456/789'})
noncontrib = AuthUserFactory()
res = self.app.patch_json_api(self.url, update_doi_payload, auth=noncontrib.auth, expect_errors=True)
assert_equal(res.status_code, 403)
res = self.app.patch_json_api(self.url, update_doi_payload, expect_errors=True)
assert_equal(res.status_code, 401)
def test_update_subjects(self):
assert_not_equal(self.preprint.subjects[0], [self.subject._id])
update_subjects_payload = build_preprint_update_payload(self.preprint._id, attributes={"subjects": [[self.subject._id]]})
res = self.app.patch_json_api(self.url, update_subjects_payload, auth=self.user.auth)
assert_equal(res.status_code, 200)
self.preprint.reload()
assert_equal(self.preprint.subjects[0], [self.subject._id])
def test_update_invalid_subjects(self):
subjects = self.preprint.subjects
update_subjects_payload = build_preprint_update_payload(self.preprint._id, attributes={"subjects": [['wwe']]})
res = self.app.patch_json_api(self.url, update_subjects_payload, auth=self.user.auth, expect_errors=True)
assert_equal(res.status_code, 400)
self.preprint.reload()
assert_equal(self.preprint.subjects, subjects)
def test_update_primary_file(self):
new_file = test_utils.create_test_file(self.preprint.node, 'openupthatwindow.pdf')
relationships = {
"primary_file": {
"data": {
"type": "file",
"id": new_file._id
}
}
}
assert_not_equal(self.preprint.primary_file, new_file)
update_file_payload = build_preprint_update_payload(self.preprint._id, relationships=relationships)
res = self.app.patch_json_api(self.url, update_file_payload, auth=self.user.auth)
assert_equal(res.status_code, 200)
self.preprint.node.reload()
assert_equal(self.preprint.primary_file, new_file)
def test_new_primary_not_in_node(self):
project = ProjectFactory()
file_for_project = test_utils.create_test_file(project, 'letoutthatantidote.pdf')
relationships = {
"primary_file": {
"data": {
"type": "file",
"id": file_for_project._id
}
}
}
update_file_payload = build_preprint_update_payload(self.preprint._id, relationships=relationships)
res = self.app.patch_json_api(self.url, update_file_payload, auth=self.user.auth, expect_errors=True)
assert_equal(res.status_code, 400)
self.preprint.reload()
assert_not_equal(self.preprint.primary_file, file_for_project)
def test_update_doi(self):
new_doi = '10.1234/ASDFASDF'
assert_not_equal(self.preprint.article_doi, new_doi)
update_subjects_payload = build_preprint_update_payload(self.preprint._id, attributes={"doi": new_doi})
res = self.app.patch_json_api(self.url, update_subjects_payload, auth=self.user.auth)
assert_equal(res.status_code, 200)
self.preprint.node.reload()
assert_equal(self.preprint.article_doi, new_doi)
preprint_detail = self.app.get(self.url, auth=self.user.auth).json['data']
assert_equal(preprint_detail['links']['doi'], 'https://dx.doi.org/{}'.format(new_doi))
def test_write_contrib_cannot_set_primary_file(self):
user_two = AuthUserFactory()
self.preprint.node.add_contributor(user_two, permissions=['read', 'write'], auth=Auth(self.user), save=True)
new_file = test_utils.create_test_file(self.preprint.node, 'openupthatwindow.pdf')
#.........这里部分代码省略.........
示例5: TestPreprintUpdateLicense
# 需要导入模块: from tests.factories import PreprintFactory [as 别名]
# 或者: from tests.factories.PreprintFactory import reload [as 别名]
class TestPreprintUpdateLicense(ApiTestCase):
def setUp(self):
super(TestPreprintUpdateLicense, self).setUp()
ensure_licenses()
self.admin_contributor = AuthUserFactory()
self.rw_contributor = AuthUserFactory()
self.read_contributor = AuthUserFactory()
self.non_contributor = AuthUserFactory()
self.preprint_provider = PreprintProviderFactory()
self.preprint = PreprintFactory(creator=self.admin_contributor, provider=self.preprint_provider)
self.preprint.node.add_contributor(self.rw_contributor, auth=Auth(self.admin_contributor))
self.preprint.node.add_contributor(self.read_contributor, auth=Auth(self.admin_contributor), permissions=['read'])
self.preprint.node.save()
self.cc0_license = NodeLicense.find_one(Q('name', 'eq', 'CC0 1.0 Universal'))
self.mit_license = NodeLicense.find_one(Q('name', 'eq', 'MIT License'))
self.no_license = NodeLicense.find_one(Q('name', 'eq', 'No license'))
self.preprint_provider.licenses_acceptable = [self.cc0_license, self.no_license]
self.preprint_provider.save()
self.url = '/{}preprints/{}/'.format(API_BASE, self.preprint._id)
def make_payload(self, node_id, license_id=None, license_year=None, copyright_holders=None):
attributes = {}
if license_year and copyright_holders:
attributes = {
'license_record': {
'year': license_year,
'copyright_holders': copyright_holders
}
}
elif license_year:
attributes = {
'license_record': {
'year': license_year
}
}
elif copyright_holders:
attributes = {
'license_record': {
'copyright_holders': copyright_holders
}
}
return {
'data': {
'id': node_id,
'attributes': attributes,
'relationships': {
'license': {
'data': {
'type': 'licenses',
'id': license_id
}
}
}
}
} if license_id else {
'data': {
'id': node_id,
'attributes': attributes
}
}
def make_request(self, url, data, auth=None, expect_errors=False):
return self.app.patch_json_api(url, data, auth=auth, expect_errors=expect_errors)
def test_admin_can_update_license(self):
data = self.make_payload(
node_id=self.preprint._id,
license_id=self.cc0_license._id
)
assert_equal(self.preprint.license, None)
res = self.make_request(self.url, data, auth=self.admin_contributor.auth)
assert_equal(res.status_code, 200)
self.preprint.reload()
assert_equal(self.preprint.license.node_license, self.cc0_license)
assert_equal(self.preprint.license.year, None)
assert_equal(self.preprint.license.copyright_holders, [])
# check logs
log = self.preprint.node.logs[-1]
assert_equal(log.action, 'preprint_license_updated')
assert_equal(log.params.get('preprint'), self.preprint._id)
def test_admin_can_update_license_record(self):
data = self.make_payload(
node_id=self.preprint._id,
license_id=self.no_license._id,
license_year='2015',
#.........这里部分代码省略.........
示例6: TestPreprintRelationshipPreprintProvider
# 需要导入模块: from tests.factories import PreprintFactory [as 别名]
# 或者: from tests.factories.PreprintFactory import reload [as 别名]
class TestPreprintRelationshipPreprintProvider(ApiTestCase):
def setUp(self):
super(TestPreprintRelationshipPreprintProvider, self).setUp()
self.user = AuthUserFactory()
self.read_write_user = AuthUserFactory()
self.preprint = PreprintFactory(creator=self.user, providers=None)
self.preprint.add_contributor(self.read_write_user)
self.preprint.save()
self.preprint_provider_one = PreprintProviderFactory()
self.preprint_provider_two = PreprintProviderFactory()
self.preprint_preprint_providers_url = self.create_url(self.preprint._id)
def create_url(self, preprint_id):
return '/{0}preprints/{1}/relationships/preprint_providers/'.format(API_BASE, preprint_id)
def create_payload(self, *preprint_provider_ids):
data = []
for provider_id in preprint_provider_ids:
data.append({'type': 'preprint_providers', 'id': provider_id})
return {'data': data}
def test_add_preprint_providers(self):
assert_equal(self.preprint.preprint_providers, None)
res = self.app.post_json_api(
self.preprint_preprint_providers_url,
self.create_payload(self.preprint_provider_one._id, self.preprint_provider_two._id),
auth=self.user.auth
)
assert_equal(res.status_code, 201)
# check the relationship
self.preprint.reload()
assert_in(self.preprint_provider_one, self.preprint.preprint_providers)
assert_in(self.preprint_provider_two, self.preprint.preprint_providers)
def test_add_through_patch_one_provider_while_removing_other(self):
self.preprint.preprint_providers = [self.preprint_provider_one]
self.preprint.save()
assert_in(self.preprint_provider_one, self.preprint.preprint_providers)
assert_not_in(self.preprint_provider_two, self.preprint.preprint_providers)
res = self.app.patch_json_api(
self.preprint_preprint_providers_url,
self.create_payload(self.preprint_provider_two._id),
auth=self.user.auth
)
assert_equal(res.status_code, 200)
self.preprint.reload()
assert_not_in(self.preprint_provider_one, self.preprint.preprint_providers)
assert_in(self.preprint_provider_two, self.preprint.preprint_providers)
def test_add_through_post_to_preprint_with_provider(self):
self.preprint.preprint_providers = [self.preprint_provider_one]
self.preprint.save()
assert_in(self.preprint_provider_one, self.preprint.preprint_providers)
assert_not_in(self.preprint_provider_two, self.preprint.preprint_providers)
res = self.app.post_json_api(
self.preprint_preprint_providers_url,
self.create_payload(self.preprint_provider_two._id),
auth=self.user.auth
)
assert_equal(res.status_code, 201)
self.preprint.reload()
assert_in(self.preprint_provider_one, self.preprint.preprint_providers)
assert_in(self.preprint_provider_two, self.preprint.preprint_providers)
def test_add_provider_with_no_permissions(self):
new_user = AuthUserFactory()
new_user.save()
res = self.app.post_json_api(
self.preprint_preprint_providers_url,
self.create_payload(self.preprint_provider_one._id),
auth=new_user.auth,
expect_errors=True,
)
assert_equal(res.status_code, 403)
def test_delete_nothing(self):
res = self.app.delete_json_api(
self.preprint_preprint_providers_url,
self.create_payload(),
auth=self.user.auth
)
assert_equal(res.status_code, 204)
def test_remove_providers(self):
self.preprint.preprint_providers = [self.preprint_provider_one]
self.preprint.save()
#.........这里部分代码省略.........