本文整理汇总了Python中tests.factories.RegistrationFactory.add_contributor方法的典型用法代码示例。如果您正苦于以下问题:Python RegistrationFactory.add_contributor方法的具体用法?Python RegistrationFactory.add_contributor怎么用?Python RegistrationFactory.add_contributor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.factories.RegistrationFactory
的用法示例。
在下文中一共展示了RegistrationFactory.add_contributor方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestInstitutionRegistrationList
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import add_contributor [as 别名]
class TestInstitutionRegistrationList(ApiTestCase):
def setUp(self):
super(TestInstitutionRegistrationList, self).setUp()
self.institution = InstitutionFactory()
self.registration1 = RegistrationFactory(is_public=True, is_registration=True)
self.registration1.primary_institution = self.institution
self.registration1.save()
self.user1 = AuthUserFactory()
self.user2 = AuthUserFactory()
self.registration2 = RegistrationFactory(creator=self.user1, is_public=False, is_registration=True)
self.registration2.primary_institution = self.institution
self.registration2.add_contributor(self.user2, auth=Auth(self.user1))
self.registration2.save()
self.registration3 = RegistrationFactory(creator=self.user2, is_public=False, is_registration=True)
self.registration3.primary_institution = self.institution
self.registration3.save()
self.institution_node_url = '/{0}institutions/{1}/registrations/'.format(API_BASE, self.institution._id)
def test_return_all_public_nodes(self):
res = self.app.get(self.institution_node_url)
assert_equal(res.status_code, 200)
ids = [each['id'] for each in res.json['data']]
assert_in(self.registration1._id, ids)
assert_not_in(self.registration2._id, ids)
assert_not_in(self.registration3._id, ids)
def test_return_private_nodes_with_auth(self):
res = self.app.get(self.institution_node_url, auth=self.user1.auth)
assert_equal(res.status_code, 200)
ids = [each['id'] for each in res.json['data']]
assert_in(self.registration1._id, ids)
assert_in(self.registration2._id, ids)
assert_not_in(self.registration3._id, ids)
def test_return_private_nodes_mixed_auth(self):
res = self.app.get(self.institution_node_url, auth=self.user2.auth)
assert_equal(res.status_code, 200)
ids = [each['id'] for each in res.json['data']]
assert_in(self.registration1._id, ids)
assert_in(self.registration2._id, ids)
assert_in(self.registration3._id, ids)
示例2: TestMetadataGeneration
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import add_contributor [as 别名]
class TestMetadataGeneration(OsfTestCase):
def setUp(self):
OsfTestCase.setUp(self)
self.visible_contrib = AuthUserFactory()
visible_contrib2 = AuthUserFactory(given_name=u'ヽ༼ ಠ益ಠ ༽ノ', family_name=u'ლ(´◉❥◉`ლ)')
self.invisible_contrib = AuthUserFactory()
self.node = RegistrationFactory(is_public=True)
self.identifier = Identifier(referent=self.node, category='catid', value='cat:7')
self.node.add_contributor(self.visible_contrib, visible=True)
self.node.add_contributor(self.invisible_contrib, visible=False)
self.node.add_contributor(visible_contrib2, visible=True)
self.node.save()
def test_metadata_for_node_only_includes_visible_contribs(self):
metadata_xml = datacite_metadata_for_node(self.node, doi=self.identifier.value)
# includes visible contrib name
assert_in(u'{}, {}'.format(
self.visible_contrib.family_name, self.visible_contrib.given_name),
metadata_xml)
# doesn't include invisible contrib name
assert_not_in(self.invisible_contrib.family_name, metadata_xml)
assert_in(self.identifier.value, metadata_xml)
def test_metadata_for_node_has_correct_structure(self):
metadata_xml = datacite_metadata_for_node(self.node, doi=self.identifier.value)
root = lxml.etree.fromstring(metadata_xml)
xsi_location = '{http://www.w3.org/2001/XMLSchema-instance}schemaLocation'
expected_location = 'http://datacite.org/schema/kernel-3 http://schema.datacite.org/meta/kernel-3/metadata.xsd'
assert_equal(root.attrib[xsi_location], expected_location)
identifier = root.find('{%s}identifier' % metadata.NAMESPACE)
assert_equal(identifier.attrib['identifierType'], 'DOI')
assert_equal(identifier.text, self.identifier.value)
creators = root.find('{%s}creators' % metadata.NAMESPACE)
assert_equal(len(creators.getchildren()), len(self.node.visible_contributors))
publisher = root.find('{%s}publisher' % metadata.NAMESPACE)
assert_equal(publisher.text, 'Open Science Framework')
pub_year = root.find('{%s}publicationYear' % metadata.NAMESPACE)
assert_equal(pub_year.text, str(self.node.registered_date.year))
示例3: RegistrationRetractionViewsTestCase
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import add_contributor [as 别名]
class RegistrationRetractionViewsTestCase(OsfTestCase):
def setUp(self):
super(RegistrationRetractionViewsTestCase, self).setUp()
self.user = AuthUserFactory()
self.registered_from = ProjectFactory(creator=self.user, is_public=True)
self.registration = RegistrationFactory(project=self.registered_from, is_public=True)
self.retraction_post_url = self.registration.api_url_for('node_registration_retraction_post')
self.retraction_get_url = self.registration.web_url_for('node_registration_retraction_get')
self.justification = fake.sentence()
def test_GET_retraction_page_when_pending_retraction_returns_HTTPError_BAD_REQUEST(self):
self.registration.retract_registration(self.user)
self.registration.save()
res = self.app.get(
self.retraction_get_url,
auth=self.user.auth,
expect_errors=True,
)
assert_equal(res.status_code, http.BAD_REQUEST)
def test_POST_retraction_to_private_registration_returns_HTTPError_FORBIDDEN(self):
self.registration.is_public = False
self.registration.save()
res = self.app.post_json(
self.retraction_post_url,
{'justification': ''},
auth=self.user.auth,
expect_errors=True,
)
assert_equal(res.status_code, http.FORBIDDEN)
self.registration.reload()
assert_is_none(self.registration.retraction)
@mock.patch('website.mails.send_mail')
def test_POST_retraction_does_not_send_email_to_unregistered_admins(self, mock_send_mail):
unreg = UnregUserFactory()
self.registration.add_contributor(
unreg,
auth=Auth(self.user),
permissions=['read', 'write', 'admin']
)
self.registration.save()
self.app.post_json(
self.retraction_post_url,
{'justification': ''},
auth=self.user.auth,
)
# Only the creator gets an email; the unreg user does not get emailed
assert_equal(mock_send_mail.call_count, 1)
def test_POST_pending_embargo_returns_HTTPError_HTTPOK(self):
self.registration.embargo_registration(
self.user,
(datetime.datetime.utcnow() + datetime.timedelta(days=10)),
for_existing_registration=True
)
self.registration.save()
assert_true(self.registration.is_pending_embargo)
res = self.app.post_json(
self.retraction_post_url,
{'justification': ''},
auth=self.user.auth,
expect_errors=True,
)
assert_equal(res.status_code, http.OK)
self.registration.reload()
assert_true(self.registration.is_pending_retraction)
def test_POST_active_embargo_returns_HTTPOK(self):
self.registration.embargo_registration(
self.user,
(datetime.datetime.utcnow() + datetime.timedelta(days=10)),
for_existing_registration=True
)
self.registration.save()
assert_true(self.registration.is_pending_embargo)
approval_token = self.registration.embargo.approval_state[self.user._id]['approval_token']
self.registration.embargo.approve(self.user, approval_token)
assert_true(self.registration.embargo_end_date)
res = self.app.post_json(
self.retraction_post_url,
{'justification': ''},
auth=self.user.auth,
expect_errors=True,
)
assert_equal(res.status_code, http.OK)
self.registration.reload()
assert_true(self.registration.is_pending_retraction)
def test_POST_retraction_by_non_admin_retract_HTTPError_UNAUTHORIZED(self):
res = self.app.post_json(self.retraction_post_url, expect_errors=True)
assert_equals(res.status_code, http.UNAUTHORIZED)
self.registration.reload()
assert_is_none(self.registration.retraction)
#.........这里部分代码省略.........
示例4: RegistrationEmbargoViewsTestCase
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import add_contributor [as 别名]
#.........这里部分代码省略.........
assert_true(node.is_registration)
assert_false(node.is_public)
@mock.patch('framework.celery_tasks.handlers.enqueue_task')
def test_POST_invalid_embargo_end_date_returns_HTTPBad_Request(self, mock_enqueue):
res = self.app.post(
self.project.api_url_for('register_draft_registration', draft_id=self.draft._id),
self.invalid_embargo_date_payload,
content_type='application/json',
auth=self.user.auth,
expect_errors=True
)
assert_equal(res.status_code, 400)
@mock.patch('framework.celery_tasks.handlers.enqueue_task')
def test_valid_POST_embargo_adds_to_parent_projects_log(self, mock_enquque):
initial_project_logs = len(self.project.logs)
self.app.post(
self.project.api_url_for('register_draft_registration', draft_id=self.draft._id),
self.valid_embargo_payload,
content_type='application/json',
auth=self.user.auth
)
self.project.reload()
# Logs: Created, registered, embargo initiated
assert_equal(len(self.project.logs), initial_project_logs + 1)
@mock.patch('website.project.sanctions.TokenApprovableSanction.ask')
def test_embargoed_registration_set_privacy_requests_embargo_termination(self, mock_ask):
# Initiate and approve embargo
for i in range(3):
c = AuthUserFactory()
self.registration.add_contributor(c, [permissions.ADMIN], auth=Auth(self.user))
self.registration.save()
self.registration.embargo_registration(
self.user,
datetime.datetime.utcnow() + datetime.timedelta(days=10)
)
for user_id, embargo_tokens in self.registration.embargo.approval_state.iteritems():
approval_token = embargo_tokens['approval_token']
self.registration.embargo.approve_embargo(User.load(user_id), approval_token)
self.registration.save()
res = self.app.post(
self.registration.api_url_for('project_set_privacy', permissions='public'),
auth=self.user.auth,
)
assert_equal(res.status_code, 200)
for reg in self.registration.node_and_primary_descendants():
reg.reload()
assert_false(reg.is_public)
assert_true(reg.embargo_termination_approval)
assert_true(reg.embargo_termination_approval.is_pending_approval)
def test_cannot_request_termination_on_component_of_embargo(self):
node = ProjectFactory()
child = ProjectFactory(parent=node, creator=node.creator)
with utils.mock_archive(node, embargo=True, autocomplete=True, autoapprove=True) as reg:
with assert_raises(NodeStateError):
reg.nodes[0].request_embargo_termination(Auth(node.creator))
@mock.patch('website.mails.send_mail')
def test_embargoed_registration_set_privacy_sends_mail(self, mock_send_mail):
"""
示例5: RegistrationRetractionViewsTestCase
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import add_contributor [as 别名]
class RegistrationRetractionViewsTestCase(OsfTestCase):
def setUp(self):
super(RegistrationRetractionViewsTestCase, self).setUp()
self.user = AuthUserFactory()
self.auth = self.user.auth
self.registration = RegistrationFactory(creator=self.user, is_public=True)
self.retraction_post_url = self.registration.api_url_for('node_registration_retraction_post')
self.retraction_get_url = self.registration.web_url_for('node_registration_retraction_get')
self.justification = fake.sentence()
def test_GET_retraction_page_when_pending_retraction_returns_HTTPBad_Request(self):
self.registration.retract_registration(self.user)
self.registration.save()
res = self.app.get(
self.retraction_get_url,
auth=self.auth,
expect_errors=True,
)
assert_equal(res.status_code, 400)
def test_POST_retraction_to_private_registration_returns_HTTPBad_request(self):
self.registration.is_public = False
self.registration.save()
res = self.app.post_json(
self.retraction_post_url,
auth=self.auth,
expect_errors=True,
)
assert_equal(res.status_code, 400)
self.registration.reload()
assert_is_none(self.registration.retraction)
# https://trello.com/c/bYyt6nYT/89-clicking-retract-registration-with-unregistered-users-as-project-admins-gives-500-error
@mock.patch('website.project.views.register.mails.send_mail')
def test_POST_retraction_does_not_send_email_to_unregistered_admins(self, mock_send_mail):
unreg = UnregUserFactory()
self.registration.add_contributor(
unreg,
auth=Auth(self.user),
permissions=('read', 'write', 'admin')
)
self.registration.save()
self.app.post_json(
self.retraction_post_url,
{'justification': ''},
auth=self.auth,
)
# Only the creator gets an email; the unreg user does not get emailed
assert_equal(mock_send_mail.call_count, 1)
def test_POST_pending_embargo_returns_HTTPBad_request(self):
self.registration.embargo_registration(
self.user,
(datetime.datetime.utcnow() + datetime.timedelta(days=10)),
for_existing_registration=True
)
self.registration.save()
assert_true(self.registration.pending_embargo)
res = self.app.post_json(
self.retraction_post_url,
auth=self.auth,
expect_errors=True,
)
assert_equal(res.status_code, 400)
self.registration.reload()
assert_is_none(self.registration.retraction)
def test_POST_retraction_by_non_admin_retract_HTTPUnauthorized(self):
res = self.app.post_json(self.retraction_post_url, expect_errors=True)
assert_equals(res.status_code, 401)
self.registration.reload()
assert_is_none(self.registration.retraction)
def test_POST_retraction_without_justification_returns_HTTPOK(self):
res = self.app.post_json(
self.retraction_post_url,
{'justification': ''},
auth=self.auth,
)
assert_equal(res.status_code, 200)
self.registration.reload()
assert_false(self.registration.retraction.is_retracted)
assert_equal(self.registration.retraction.state, Retraction.PENDING)
assert_is_none(self.registration.retraction.justification)
def test_valid_POST_retraction_adds_to_parent_projects_log(self):
initial_project_logs = len(self.registration.registered_from.logs)
self.app.post_json(
self.retraction_post_url,
{'justification': ''},
auth=self.auth,
)
self.registration.registered_from.reload()
# Logs: Created, registered, retraction initiated
assert_equal(len(self.registration.registered_from.logs), initial_project_logs + 1)
示例6: TestRegistrationUpdate
# 需要导入模块: from tests.factories import RegistrationFactory [as 别名]
# 或者: from tests.factories.RegistrationFactory import add_contributor [as 别名]
class TestRegistrationUpdate(ApiTestCase):
def setUp(self):
self.maxDiff = None
super(TestRegistrationUpdate, self).setUp()
self.user = AuthUserFactory()
self.user_two = AuthUserFactory()
self.user_three = AuthUserFactory()
self.public_project = ProjectFactory(title="Project One", is_public=True, creator=self.user)
self.private_project = ProjectFactory(title="Project Two", is_public=False, creator=self.user)
self.public_registration = RegistrationFactory(project=self.public_project, creator=self.user, is_public=True)
self.private_registration = RegistrationFactory(project=self.private_project, creator=self.user)
self.public_url = '/{}registrations/{}/'.format(API_BASE, self.public_registration._id)
self.private_url = '/{}registrations/{}/'.format(API_BASE, self.private_registration._id)
self.private_registration.add_contributor(self.user_two, permissions=[permissions.READ])
self.private_registration.add_contributor(self.user_three, permissions=[permissions.WRITE])
self.private_registration.save()
self.payload = {
"data": {
"id": self.private_registration._id,
"type": "registrations",
"attributes": {
"public": True,
}
}
}
def test_update_private_registration_logged_out(self):
res = self.app.put_json_api(self.private_url, self.payload, expect_errors=True)
assert_equal(res.status_code, 401)
def test_update_private_registration_logged_in_admin(self):
res = self.app.put_json_api(self.private_url, self.payload, auth=self.user.auth)
assert_equal(res.status_code, 200)
assert_equal(res.json['data']['attributes']['public'], True)
def test_update_private_registration_logged_in_read_only_contributor(self):
res = self.app.put_json_api(self.private_url, self.payload, auth=self.user_two.auth, expect_errors=True)
assert_equal(res.status_code, 403)
def test_update_private_registration_logged_in_read_write_contributor(self):
res = self.app.put_json_api(self.private_url, self.payload, auth=self.user_three.auth, expect_errors=True)
assert_equal(res.status_code, 403)
def test_update_public_registration_to_private(self):
payload = {
"data": {
"id": self.public_registration._id,
"type": "registrations",
"attributes": {
"public": False,
}
}
}
res = self.app.put_json_api(self.public_url, payload, auth=self.user.auth, expect_errors=True)
assert_equal(res.status_code, 400)
assert_equal(res.json['errors'][0]['detail'], 'Registrations can only be turned from private to public.')
def test_public_field_has_invalid_value(self):
payload = {
"data": {
"id": self.public_registration._id,
"type": "registrations",
"attributes": {
"public": "Yes"
}
}
}
res = self.app.put_json_api(self.public_url, payload, auth=self.user.auth, expect_errors=True)
assert_equal(res.status_code, 400)
assert_equal(res.json['errors'][0]['detail'], '"Yes" is not a valid boolean.')
def test_fields_other_than_public_are_ignored(self):
payload = {
"data": {
"id": self.private_registration._id,
"type": "registrations",
"attributes": {
"public": True,
"category": "instrumentation",
"title": "New title",
"description": "New description"
}
}
}
res = self.app.put_json_api(self.private_url, payload, auth=self.user.auth)
assert_equal(res.status_code, 200)
assert_equal(res.json['data']['attributes']['public'], True)
assert_equal(res.json['data']['attributes']['category'], 'project')
assert_equal(res.json['data']['attributes']['description'], self.private_registration.description)
assert_equal(res.json['data']['attributes']['title'], self.private_registration.title)
def test_type_field_must_match(self):
payload = {
"data": {
"id": self.private_registration._id,
#.........这里部分代码省略.........