本文整理汇总了Python中tests.factories.PreprintFactory.save方法的典型用法代码示例。如果您正苦于以下问题:Python PreprintFactory.save方法的具体用法?Python PreprintFactory.save怎么用?Python PreprintFactory.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.factories.PreprintFactory
的用法示例。
在下文中一共展示了PreprintFactory.save方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestPreprintFactory
# 需要导入模块: from tests.factories import PreprintFactory [as 别名]
# 或者: from tests.factories.PreprintFactory import save [as 别名]
class TestPreprintFactory(OsfTestCase):
def setUp(self):
super(TestPreprintFactory, self).setUp()
self.user = AuthUserFactory()
self.auth = Auth(user=self.user)
self.preprint = PreprintFactory(creator=self.user)
self.preprint.save()
def test_is_preprint(self):
assert_true(self.preprint.node.is_preprint)
def test_preprint_is_public(self):
assert_true(self.preprint.node.is_public)
示例2: TestPreprintProviders
# 需要导入模块: from tests.factories import PreprintFactory [as 别名]
# 或者: from tests.factories.PreprintFactory import save [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)
示例3: TestPreprintFiltering
# 需要导入模块: from tests.factories import PreprintFactory [as 别名]
# 或者: from tests.factories.PreprintFactory import save [as 别名]
class TestPreprintFiltering(ApiTestCase):
def setUp(self):
super(TestPreprintFiltering, self).setUp()
self.user = AuthUserFactory()
self.provider = PreprintProviderFactory(name='wwe')
self.preprint = PreprintFactory(creator=self.user, providers=[self.provider])
self.preprint.add_tag('nature boy', Auth(self.user), save=False)
self.preprint.add_tag('ric flair', Auth(self.user), save=False)
self.preprint.save()
self.provider_two = PreprintProviderFactory(name='wcw')
self.preprint_two = PreprintFactory(creator=self.user, filename='woo.txt', providers=[self.provider_two])
self.preprint_two.add_tag('nature boy', Auth(self.user), save=False)
self.preprint_two.add_tag('woo', Auth(self.user), save=False)
self.preprint_two.save()
self.preprint_three = PreprintFactory(creator=self.user, filename='stonecold.txt', providers=[self.provider])
self.preprint_three.add_tag('stone', Auth(self.user), save=False)
self.preprint_two.add_tag('cold', Auth(self.user), save=False)
self.preprint_three.save()
def tearDown(self):
super(TestPreprintFiltering, self).tearDown()
Node.remove()
def test_filtering_tags(self):
# both preprint and preprint_two have nature boy
url = '/{}preprints/?filter[tags]={}'.format(API_BASE, 'nature boy')
res = self.app.get(url, auth=self.user.auth)
reg_json = res.json['data']
ids = [each['id'] for each in reg_json]
assert_in(self.preprint._id, ids)
assert_in(self.preprint_two._id, ids)
assert_not_in(self.preprint_three._id, ids)
# filtering two tags
# preprint has both tags; preprint_two only has one
url = '/{}preprints/?filter[tags]={}&filter[tags]={}'.format(API_BASE, 'nature boy', 'ric flair')
res = self.app.get(url, auth=self.user.auth)
reg_json = res.json['data']
ids = [each['id'] for each in reg_json]
assert_in(self.preprint._id, ids)
assert_not_in(self.preprint_two._id, ids)
assert_not_in(self.preprint_three._id, ids)
def test_filter_by_doi(self):
url = '/{}preprints/?filter[doi]={}'.format(API_BASE, self.preprint.preprint_doi)
res = self.app.get(url, auth=self.user.auth)
data = res.json['data']
assert_equal(len(data), 1)
for result in data:
assert_equal(self.preprint._id, result['id'])
示例4: create_fake_project
# 需要导入模块: from tests.factories import PreprintFactory [as 别名]
# 或者: from tests.factories.PreprintFactory import save [as 别名]
def create_fake_project(creator, n_users, privacy, n_components, name, n_tags, presentation_name, is_registration, is_preprint, preprint_providers):
auth = Auth(user=creator)
project_title = name if name else fake.science_sentence()
if is_preprint:
providers_to_add = []
if preprint_providers:
providers = preprint_providers.split(',')
for provider in providers:
try:
preprint_provider = models.PreprintProvider.find_one(Q('_id', 'eq', provider))
except NoResultsFound:
preprint_provider = PreprintProviderFactory(name=provider)
providers_to_add.append(preprint_provider)
privacy = 'public'
project = PreprintFactory(title=project_title, description=fake.science_paragraph(), creator=creator, providers=providers_to_add)
elif is_registration:
project = RegistrationFactory(title=project_title, description=fake.science_paragraph(), creator=creator)
else:
project = ProjectFactory(title=project_title, description=fake.science_paragraph(), creator=creator)
project.set_privacy(privacy)
for _ in range(n_users):
contrib = create_fake_user()
project.add_contributor(contrib, auth=auth)
if isinstance(n_components, int):
for _ in range(n_components):
NodeFactory(project=project, title=fake.science_sentence(), description=fake.science_paragraph(),
creator=creator)
elif isinstance(n_components, list):
render_generations_from_node_structure_list(project, creator, n_components)
for _ in range(n_tags):
project.add_tag(fake.science_word(), auth=auth)
if presentation_name is not None:
project.add_tag(presentation_name, auth=auth)
project.add_tag('poster', auth=auth)
project.save()
logger.info('Created project: {0}'.format(project.title))
return project
示例5: TestPreprintUpdateLicense
# 需要导入模块: from tests.factories import PreprintFactory [as 别名]
# 或者: from tests.factories.PreprintFactory import save [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 save [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()
#.........这里部分代码省略.........