本文整理汇总了Python中osf_tests.factories.DraftRegistrationFactory.save方法的典型用法代码示例。如果您正苦于以下问题:Python DraftRegistrationFactory.save方法的具体用法?Python DraftRegistrationFactory.save怎么用?Python DraftRegistrationFactory.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osf_tests.factories.DraftRegistrationFactory
的用法示例。
在下文中一共展示了DraftRegistrationFactory.save方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_required_third_level_questions_must_be_answered_on_draft
# 需要导入模块: from osf_tests.factories import DraftRegistrationFactory [as 别名]
# 或者: from osf_tests.factories.DraftRegistrationFactory import save [as 别名]
def test_required_third_level_questions_must_be_answered_on_draft(
self, mock_enqueue, app, user, project_public,
prereg_metadata, url_registrations):
prereg_schema = MetaSchema.objects.get(
name='Prereg Challenge',
schema_version=LATEST_SCHEMA_VERSION)
prereg_draft_registration = DraftRegistrationFactory(
initiator=user,
registration_schema=prereg_schema,
branched_from=project_public
)
registration_metadata = prereg_metadata(prereg_draft_registration)
registration_metadata['q11'] = {'value': {"question": {}}}
prereg_draft_registration.registration_metadata = registration_metadata
prereg_draft_registration.save()
payload = {
'data': {
'type': 'registrations',
'attributes': {
'registration_choice': 'immediate',
'draft_registration': prereg_draft_registration._id,
}
}
}
res = app.post_json_api(
url_registrations, payload,
auth=user.auth,
expect_errors=True)
assert res.status_code == 400
assert res.json['errors'][0]['detail'] == '\'value\' is a required property'
示例2: test_required_third_level_questions_must_be_answered_on_draft
# 需要导入模块: from osf_tests.factories import DraftRegistrationFactory [as 别名]
# 或者: from osf_tests.factories.DraftRegistrationFactory import save [as 别名]
def test_required_third_level_questions_must_be_answered_on_draft(self, mock_enqueue):
prereg_schema = MetaSchema.find_one(
Q('name', 'eq', 'Prereg Challenge') &
Q('schema_version', 'eq', LATEST_SCHEMA_VERSION)
)
prereg_draft_registration = DraftRegistrationFactory(
initiator=self.user,
registration_schema=prereg_schema,
branched_from=self.public_project
)
registration_metadata = self.prereg_metadata(prereg_draft_registration)
registration_metadata['q11'] = {'value': {"question": {}}}
prereg_draft_registration.registration_metadata = registration_metadata
prereg_draft_registration.save()
payload = {
"data": {
"type": "registrations",
"attributes": {
"registration_choice": "immediate",
"draft_registration": prereg_draft_registration._id,
}
}
}
res = self.app.post_json_api(self.url, payload, auth=self.user.auth, expect_errors=True)
assert_equal(res.status_code, 400)
assert_equal(res.json['errors'][0]['detail'], "'value' is a required property")
示例3: test_required_metaschema_questions_not_required_on_post
# 需要导入模块: from osf_tests.factories import DraftRegistrationFactory [as 别名]
# 或者: from osf_tests.factories.DraftRegistrationFactory import save [as 别名]
def test_required_metaschema_questions_not_required_on_post(self):
prereg_schema = MetaSchema.find_one(
Q('name', 'eq', 'Prereg Challenge') &
Q('schema_version', 'eq', LATEST_SCHEMA_VERSION)
)
prereg_draft_registration = DraftRegistrationFactory(
initiator=self.user,
registration_schema=prereg_schema,
branched_from=self.public_project
)
url = '/{}nodes/{}/draft_registrations/?embed=initiator&embed=branched_from'.format(API_BASE, self.public_project._id)
registration_metadata = self.prereg_metadata(prereg_draft_registration)
del registration_metadata['q1']
prereg_draft_registration.registration_metadata = registration_metadata
prereg_draft_registration.save()
payload = {
"data": {
"type": "draft_registrations",
"attributes": {
"registration_supplement": prereg_schema._id,
"registration_metadata": registration_metadata
}
}
}
res = self.app.post_json_api(url, payload, auth=self.user.auth, expect_errors=True)
assert_equal(res.status_code, 201)
data = res.json['data']
assert_equal(res.json['data']['attributes']['registration_metadata']['q2']['value'], 'Test response')
assert_equal(data['attributes']['registration_supplement'], prereg_schema._id)
assert_equal(data['embeds']['branched_from']['data']['id'], self.public_project._id)
assert_equal(data['embeds']['initiator']['data']['id'], self.user._id)
示例4: TestDraftRegistrationDelete
# 需要导入模块: from osf_tests.factories import DraftRegistrationFactory [as 别名]
# 或者: from osf_tests.factories.DraftRegistrationFactory import save [as 别名]
class TestDraftRegistrationDelete(DraftRegistrationTestCase):
def setUp(self):
super(TestDraftRegistrationDelete, self).setUp()
schema = MetaSchema.find_one(
Q('name', 'eq', 'OSF-Standard Pre-Data Collection Registration') &
Q('schema_version', 'eq', LATEST_SCHEMA_VERSION)
)
self.draft_registration = DraftRegistrationFactory(
initiator=self.user,
registration_schema=schema,
branched_from=self.public_project
)
self.other_project = ProjectFactory(creator=self.user)
self.url = '/{}nodes/{}/draft_registrations/{}/'.format(API_BASE, self.public_project._id, self.draft_registration._id)
def test_admin_can_delete_draft(self):
res = self.app.delete_json_api(self.url, auth=self.user.auth)
assert_equal(res.status_code, 204)
def test_read_only_contributor_cannot_delete_draft(self):
res = self.app.delete_json_api(self.url, auth=self.read_only_user.auth, expect_errors=True)
assert_equal(res.status_code, 403)
def test_read_write_contributor_cannot_delete_draft(self):
res = self.app.delete_json_api(self.url, auth=self.read_write_user.auth, expect_errors=True)
assert_equal(res.status_code, 403)
def test_logged_in_non_contributor_cannot_delete_draft(self):
res = self.app.delete_json_api(self.url, auth=self.non_contributor.auth, expect_errors=True)
assert_equal(res.status_code, 403)
def test_unauthenticated_user_cannot_delete_draft(self):
res = self.app.delete_json_api(self.url, expect_errors=True)
assert_equal(res.status_code, 401)
def test_draft_that_has_been_registered_cannot_be_deleted(self):
reg = RegistrationFactory(project=self.public_project)
self.draft_registration.registered_node = reg
self.draft_registration.save()
res = self.app.delete_json_api(self.url, auth=self.user.auth, expect_errors=True)
assert_equal(res.status_code, 403)
assert_equal(res.json['errors'][0]['detail'], 'This draft has already been registered and cannot be modified.')
def test_reviewer_cannot_delete_draft_registration(self):
user = AuthUserFactory()
user.add_system_tag(PREREG_ADMIN_TAG)
user.save()
res = self.app.delete_json_api(self.url, auth=user.auth, expect_errors=True)
assert_equal(res.status_code, 403)
assert_equal(res.json['errors'][0]['detail'], 'You do not have permission to perform this action.')
示例5: test_required_metaschema_questions_not_required_on_post
# 需要导入模块: from osf_tests.factories import DraftRegistrationFactory [as 别名]
# 或者: from osf_tests.factories.DraftRegistrationFactory import save [as 别名]
def test_required_metaschema_questions_not_required_on_post(
self, app, user, provider, project_public, prereg_metadata):
prereg_schema = RegistrationSchema.objects.get(
name='Prereg Challenge',
schema_version=LATEST_SCHEMA_VERSION)
prereg_draft_registration = DraftRegistrationFactory(
initiator=user,
registration_schema=prereg_schema,
branched_from=project_public
)
url = '/{}nodes/{}/draft_registrations/?embed=initiator&embed=branched_from'.format(
API_BASE, project_public._id)
registration_metadata = prereg_metadata(prereg_draft_registration)
del registration_metadata['q1']
prereg_draft_registration.registration_metadata = registration_metadata
prereg_draft_registration.save()
payload = {
'data': {
'type': 'draft_registrations',
'attributes': {
'registration_metadata': registration_metadata
},
'relationships': {
'registration_schema': {
'data': {
'type': 'registration_schema',
'id': prereg_schema._id
}
},
'provider': {
'data': {
'type': 'registration-providers',
'id': provider._id,
}
}
}
}
}
res = app.post_json_api(
url, payload, auth=user.auth,
expect_errors=True)
assert res.status_code == 201
data = res.json['data']
assert res.json['data']['attributes']['registration_metadata']['q2']['value'] == 'Test response'
assert prereg_schema._id in data['relationships']['registration_schema']['links']['related']['href']
assert data['embeds']['branched_from']['data']['id'] == project_public._id
assert data['embeds']['initiator']['data']['id'] == user._id
示例6: TestDraftRegistrationUpdate
# 需要导入模块: from osf_tests.factories import DraftRegistrationFactory [as 别名]
# 或者: from osf_tests.factories.DraftRegistrationFactory import save [as 别名]
#.........这里部分代码省略.........
def test_question_in_registration_metadata_must_be_in_schema(self):
self.payload['data']['attributes']['registration_metadata']['q11'] = {
"value": "No, data collection has not begun"
}
res = self.app.put_json_api(self.url, self.payload, auth=self.user.auth, expect_errors=True)
errors = res.json['errors'][0]
assert_equal(res.status_code, 400)
assert_equal(errors['detail'], "Additional properties are not allowed (u'q11' was unexpected)")
def test_multiple_choice_question_value_must_match_value_in_schema(self):
self.payload['data']['attributes']['registration_metadata']['datacompletion'] = {
"value": "Nope, data collection has not begun"
}
res = self.app.put_json_api(self.url, self.payload, auth=self.user.auth, expect_errors=True)
errors = res.json['errors'][0]
assert_equal(res.status_code, 400)
assert_equal(errors['detail'], "u'Nope, data collection has not begun' is not one of [u'No, data collection has not begun', u'Yes, data collection is underway or complete']")
def test_cannot_update_registration_schema(self):
self.payload['data']['attributes']['registration_supplement'] = self.prereg_schema._id
res = self.app.put_json_api(self.url, self.payload, auth=self.user.auth, expect_errors=True)
assert_equal(res.status_code, 200)
assert_equal(res.json['data']['attributes']['registration_supplement'], self.schema._id)
def test_required_metaschema_questions_not_required_on_update(self):
url = '/{}nodes/{}/draft_registrations/{}/'.format(API_BASE, self.public_project._id, self.prereg_draft_registration._id)
del self.registration_metadata['q1']
self.prereg_draft_registration.registration_metadata = self.registration_metadata
self.prereg_draft_registration.save()
payload = {
"data": {
"id": self.prereg_draft_registration._id,
"type": "draft_registrations",
"attributes": {
"registration_metadata": {
'q2': {
'value': 'New response'
}
}
}
}
}
res = self.app.put_json_api(url, payload, auth=self.user.auth, expect_errors=True)
assert_equal(res.status_code, 200)
assert_equal(res.json['data']['attributes']['registration_metadata']['q2']['value'], 'New response')
assert_not_in('q1', res.json['data']['attributes']['registration_metadata'])
def test_reviewer_can_update_draft_registration(self):
user = AuthUserFactory()
user.add_system_tag(PREREG_ADMIN_TAG)
user.save()
payload = {
"data": {
"id": self.prereg_draft_registration._id,
"type": "draft_registrations",
"attributes": {
"registration_metadata": {
'q2': {
示例7: TestDraftRegistrationList
# 需要导入模块: from osf_tests.factories import DraftRegistrationFactory [as 别名]
# 或者: from osf_tests.factories.DraftRegistrationFactory import save [as 别名]
class TestDraftRegistrationList(DraftRegistrationTestCase):
def setUp(self):
super(TestDraftRegistrationList, self).setUp()
self.schema = MetaSchema.find_one(
Q('name', 'eq', 'Open-Ended Registration') &
Q('schema_version', 'eq', LATEST_SCHEMA_VERSION)
)
self.draft_registration = DraftRegistrationFactory(
initiator=self.user,
registration_schema=self.schema,
branched_from=self.public_project
)
self.url = '/{}nodes/{}/draft_registrations/'.format(API_BASE, self.public_project._id)
def test_admin_can_view_draft_list(self):
res = self.app.get(self.url, auth=self.user.auth)
assert_equal(res.status_code, 200)
data = res.json['data']
assert_equal(len(data), 1)
assert_equal(data[0]['attributes']['registration_supplement'], self.schema._id)
assert_equal(data[0]['id'], self.draft_registration._id)
assert_equal(data[0]['attributes']['registration_metadata'], {})
def test_read_only_contributor_cannot_view_draft_list(self):
res = self.app.get(self.url, auth=self.read_only_user.auth, expect_errors=True)
assert_equal(res.status_code, 403)
def test_read_write_contributor_cannot_view_draft_list(self):
res = self.app.get(self.url, auth=self.read_write_user.auth, expect_errors=True)
assert_equal(res.status_code, 403)
def test_logged_in_non_contributor_cannot_view_draft_list(self):
res = self.app.get(self.url, auth=self.non_contributor.auth, expect_errors=True)
assert_equal(res.status_code, 403)
def test_unauthenticated_user_cannot_view_draft_list(self):
res = self.app.get(self.url, expect_errors=True)
assert_equal(res.status_code, 401)
def test_draft_with_registered_node_does_not_show_up_in_draft_list(self):
reg = RegistrationFactory(project = self.public_project)
self.draft_registration.registered_node = reg
self.draft_registration.save()
res = self.app.get(self.url, auth=self.user.auth)
assert_equal(res.status_code, 200)
data = res.json['data']
assert_equal(len(data), 0)
def test_draft_with_deleted_registered_node_shows_up_in_draft_list(self):
reg = RegistrationFactory(project=self.public_project)
self.draft_registration.registered_node = reg
self.draft_registration.save()
reg.is_deleted = True
reg.save()
res = self.app.get(self.url, auth=self.user.auth)
assert_equal(res.status_code, 200)
data = res.json['data']
assert_equal(len(data), 1)
assert_equal(data[0]['attributes']['registration_supplement'], self.schema._id)
assert_equal(data[0]['id'], self.draft_registration._id)
assert_equal(data[0]['attributes']['registration_metadata'], {})