本文整理汇总了Python中osf_tests.factories.DraftRegistrationFactory类的典型用法代码示例。如果您正苦于以下问题:Python DraftRegistrationFactory类的具体用法?Python DraftRegistrationFactory怎么用?Python DraftRegistrationFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DraftRegistrationFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_required_third_level_questions_must_be_answered_on_draft
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
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: TestCommentUpdateView
class TestCommentUpdateView(AdminTestCase):
def setUp(self):
super(TestCommentUpdateView, self).setUp()
self.user = AuthUserFactory()
self.dr1 = DraftRegistrationFactory(
initiator=self.user,
registration_schema=utils.draft_reg_util(),
registration_metadata=utils.SCHEMA_DATA
)
self.dr1.submit_for_review(self.user, {}, save=True)
self.request = RequestFactory().post('/fake_path', data={'blah': 'arg'})
self.request.user = UserFactory()
self.plain_view = CommentUpdateView
self.view = setup_view(self.plain_view(), self.request, draft_pk=self.dr1._id)
self.url = reverse('pre_reg:comment', kwargs={'draft_pk': self.dr1._id})
@mock.patch('admin.pre_reg.views.json.loads')
@mock.patch('admin.pre_reg.views.DraftRegistration.update_metadata')
def test_post_comments(self, mock_json, mock_meta):
count = AdminLogEntry.objects.count()
self.view.post(self.request)
nt.assert_equal(AdminLogEntry.objects.count(), count + 1)
def test_no_user_permissions_raises_error(self):
request = RequestFactory().get(self.url)
request.user = self.user
with nt.assert_raises(PermissionDenied):
self.plain_view.as_view()(request, draft_pk=self.dr1._id)
示例4: setUp
def setUp(self, mock_archive):
super(TestDraftListView, self).setUp()
self.user = AuthUserFactory()
self.schema = utils.draft_reg_util()
self.dr1 = DraftRegistrationFactory(
initiator=self.user,
registration_schema=self.schema,
registration_metadata=utils.SCHEMA_DATA
)
self.dr1.submit_for_review(self.user, {}, save=True)
self.dr2 = DraftRegistrationFactory(
initiator=self.user,
registration_schema=self.schema,
registration_metadata=utils.SCHEMA_DATA
)
self.dr2.submit_for_review(self.user, {}, save=True)
# Simply here to NOT be returned when get_queryset is called
self.unsubmitted_prereg = DraftRegistrationFactory(
initiator=self.user,
registration_schema=self.schema,
registration_metadata=utils.SCHEMA_DATA
)
self.unsubmitted_prereg.register(Auth(self.user), save=True)
self.request = RequestFactory().get('/fake_path')
self.plain_view = DraftListView
self.view = setup_view(self.plain_view(), self.request)
self.url = reverse('pre_reg:prereg')
示例5: test_required_metaschema_questions_not_required_on_post
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)
示例6: TestDraftRegistrationDelete
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.')
示例7: TestDraftListView
class TestDraftListView(AdminTestCase):
def setUp(self):
super(TestDraftListView, self).setUp()
self.user = AuthUserFactory()
schema = utils.draft_reg_util()
self.dr1 = DraftRegistrationFactory(
initiator=self.user,
registration_schema=schema,
registration_metadata=utils.SCHEMA_DATA
)
self.dr1.submit_for_review(self.user, {}, save=True)
self.dr2 = DraftRegistrationFactory(
initiator=self.user,
registration_schema=schema,
registration_metadata=utils.SCHEMA_DATA
)
self.dr2.submit_for_review(self.user, {}, save=True)
self.request = RequestFactory().get('/fake_path')
self.plain_view = DraftListView
self.view = setup_view(self.plain_view(), self.request)
self.url = reverse('pre_reg:prereg')
def test_get_queryset(self):
res = list(self.view.get_queryset())
nt.assert_equal(len(res), 2)
nt.assert_is_instance(res[0], DraftRegistration)
def test_get_context_data(self):
self.view.object_list = self.view.get_queryset()
res = self.view.get_context_data()
nt.assert_is_instance(res, dict)
nt.assert_is_instance(res['drafts'], list)
nt.assert_equal(len(res['drafts']), 2)
def test_no_user_permissions_raises_error(self):
request = RequestFactory().get(self.url)
request.user = self.user
with nt.assert_raises(PermissionDenied):
self.plain_view.as_view()(request)
def test_correct_view_permissions(self):
view_permission = Permission.objects.get(codename='view_prereg')
self.user.user_permissions.add(view_permission)
self.user.save()
request = RequestFactory().get(self.url)
request.user = self.user
response = self.plain_view.as_view()(request)
nt.assert_equal(response.status_code, 200)
示例8: test_required_metaschema_questions_not_required_on_post
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
示例9: setUp
def setUp(self):
super(TestRegistrationCreate, self).setUp()
self.schema = MetaSchema.find_one(
Q('name', 'eq', 'Replication Recipe (Brandt et al., 2013): Post-Completion') &
Q('schema_version', 'eq', LATEST_SCHEMA_VERSION)
)
self.draft_registration = DraftRegistrationFactory(
initiator=self.user,
registration_schema=self.schema,
branched_from=self.public_project,
registration_metadata = {
'item29': {'value': 'Yes'},
'item33': {'value': 'success'}
}
)
self.url = '/{}nodes/{}/registrations/'.format(API_BASE, self.public_project._id)
self.payload = {
"data": {
"type": "registrations",
"attributes": {
"draft_registration": self.draft_registration._id,
"registration_choice": "immediate"
}
}
}
示例10: setUp
def setUp(self):
super(TestPreregFiles, self).setUp()
self.prereg_user = AuthUserFactory()
self.user = AuthUserFactory()
self.node = ProjectFactory(creator=self.user)
prereg_schema = get_prereg_schema()
self.d_of_qs = {
'q7': OsfStorageFileNode(node=self.node, name='7'),
'q11': OsfStorageFileNode(node=self.node, name='11'),
'q16': OsfStorageFileNode(node=self.node, name='16'),
'q12': OsfStorageFileNode(node=self.node, name='12'),
'q13': OsfStorageFileNode(node=self.node, name='13'),
'q19': OsfStorageFileNode(node=self.node, name='19'),
'q26': OsfStorageFileNode(node=self.node, name='26')
}
data = {}
for q, f in self.d_of_qs.iteritems():
guid = f.get_guid(create=True)._id
f.save()
if q == 'q26':
data[q] = {
'comments': [],
'value': '26',
'extra': [
{
'data': {
'provider': 'osfstorage',
'path': f.path,
},
'fileId': guid,
'nodeId': self.node._id,
}
]
}
continue
data[q] = {
'value': {
'uploader': {
'extra': [
{
'data': {
'provider': 'osfstorage',
'path': f.path,
},
'fileId': guid,
'nodeId': self.node._id,
}
]
}
}
}
self.draft = DraftRegistrationFactory(
initiator=self.user,
registration_schema=prereg_schema,
registration_metadata=data
)
self.prereg_user.save()
self.admin_user = UserFactory()
示例11: TestDraftDetailView
class TestDraftDetailView(AdminTestCase):
def setUp(self):
super(TestDraftDetailView, self).setUp()
self.user = AuthUserFactory()
schema = utils.draft_reg_util()
self.dr1 = DraftRegistrationFactory(
initiator=self.user,
registration_schema=schema,
registration_metadata=utils.SCHEMA_DATA
)
self.dr1.submit_for_review(self.user, {}, save=True)
self.request = RequestFactory().get('/fake_path')
self.plain_view = DraftDetailView
self.view = setup_view(self.plain_view(), self.request, draft_pk=self.dr1._id)
self.url = reverse('pre_reg:view_draft', kwargs={'draft_pk': self.dr1._id})
@mock.patch('admin.pre_reg.views.DraftDetailView.checkout_files')
def test_get_object(self, mock_files):
res = self.view.get_object()
nt.assert_is_instance(res, dict)
nt.assert_equal(res['pk'], self.dr1._id)
def test_no_user_permissions_raises_error(self):
request = RequestFactory().get(self.url)
request.user = self.user
with nt.assert_raises(PermissionDenied):
self.plain_view.as_view()(request, draft_pk=self.dr1._id)
@mock.patch('admin.pre_reg.views.DraftDetailView.checkout_files')
def test_correct_view_permissions(self, mock_files):
view_permission = Permission.objects.get(codename='view_prereg')
self.user.user_permissions.add(view_permission)
self.user.save()
request = RequestFactory().get(self.url)
request.user = self.user
response = self.plain_view.as_view()(request, draft_pk=self.dr1._id)
nt.assert_equal(response.status_code, 200)
示例12: setUp
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)
示例13: setUp
def setUp(self):
super(TestDraftRegistrationUpdate, self).setUp()
self.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=self.schema,
branched_from=self.public_project
)
self.prereg_schema = MetaSchema.find_one(
Q('name', 'eq', 'Prereg Challenge') &
Q('schema_version', 'eq', LATEST_SCHEMA_VERSION)
)
self.prereg_draft_registration = DraftRegistrationFactory(
initiator=self.user,
registration_schema=self.prereg_schema,
branched_from=self.public_project
)
self.registration_metadata = self.prereg_metadata(self.prereg_draft_registration)
self.other_project = ProjectFactory(creator=self.user)
self.url = '/{}nodes/{}/draft_registrations/{}/'.format(API_BASE, self.public_project._id, self.draft_registration._id)
self.payload = {
"data": {
"id": self.draft_registration._id,
"type": "draft_registrations",
"attributes": {
"registration_metadata": {
"datacompletion": {
"value": "No, data collection has not begun"
},
"looked": {
"value": "No"
},
"comments": {
"value": "This is my first registration."
}
}
}
}
}
示例14: test_queryset_returns_in_order_date_submitted
def test_queryset_returns_in_order_date_submitted(self):
created_first_submitted_second = DraftRegistrationFactory(
initiator=self.user,
registration_schema=self.schema,
registration_metadata=utils.SCHEMA_DATA
)
created_second_submitted_first = DraftRegistrationFactory(
initiator=self.user,
registration_schema=self.schema,
registration_metadata=utils.SCHEMA_DATA
)
nt.assert_greater(created_second_submitted_first.datetime_initiated, created_first_submitted_second.datetime_initiated)
created_second_submitted_first.submit_for_review(self.user, {}, save=True)
created_first_submitted_second.submit_for_review(self.user, {}, save=True)
created_second_submitted_first.datetime_updated = created_first_submitted_second.datetime_updated + datetime.timedelta(1)
assert created_second_submitted_first.datetime_updated > created_first_submitted_second.datetime_updated
res = list(self.view.get_queryset())
nt.assert_true(res[0] == created_first_submitted_second)
示例15: TestPreregFiles
class TestPreregFiles(AdminTestCase):
def setUp(self):
super(TestPreregFiles, self).setUp()
self.prereg_user = AuthUserFactory()
self.user = AuthUserFactory()
self.node = ProjectFactory(creator=self.user)
prereg_schema = get_prereg_schema()
self.d_of_qs = {
'q7': OsfStorageFileNode(node=self.node, name='7'),
'q11': OsfStorageFileNode(node=self.node, name='11'),
'q16': OsfStorageFileNode(node=self.node, name='16'),
'q12': OsfStorageFileNode(node=self.node, name='12'),
'q13': OsfStorageFileNode(node=self.node, name='13'),
'q19': OsfStorageFileNode(node=self.node, name='19'),
'q26': OsfStorageFileNode(node=self.node, name='26')
}
data = {}
for q, f in self.d_of_qs.iteritems():
guid = f.get_guid(create=True)._id
f.save()
if q == 'q26':
data[q] = {
'comments': [],
'value': '26',
'extra': [
{
'data': {
'provider': 'osfstorage',
'path': f.path,
},
'fileId': guid,
'nodeId': self.node._id,
}
]
}
continue
data[q] = {
'value': {
'uploader': {
'extra': [
{
'data': {
'provider': 'osfstorage',
'path': f.path,
},
'fileId': guid,
'nodeId': self.node._id,
}
]
}
}
}
self.draft = DraftRegistrationFactory(
initiator=self.user,
registration_schema=prereg_schema,
registration_metadata=data
)
self.prereg_user.save()
self.admin_user = UserFactory()
def test_checkout_files(self):
self.draft.submit_for_review(self.user, {}, save=True)
request = RequestFactory().get('/fake_path')
view = DraftDetailView()
view = setup_user_view(view, request, self.admin_user,
draft_pk=self.draft._id)
view.checkout_files(self.draft)
for q, f in self.d_of_qs.iteritems():
f.refresh_from_db()
nt.assert_equal(self.admin_user, f.checkout)
def test_checkin_files(self):
self.draft.submit_for_review(self.user, {}, save=True)
request = RequestFactory().get('/fake_path')
view = DraftDetailView()
view = setup_user_view(view, request, self.admin_user,
draft_pk=self.draft._id)
view.checkout_files(self.draft)
view2 = DraftFormView()
view2 = setup_view(view2, request, draft_pk=self.draft._id)
view2.checkin_files(self.draft)
for q, f in self.d_of_qs.iteritems():
nt.assert_equal(None, f.checkout)
def test_get_meta_data_files(self):
for item in get_metadata_files(self.draft):
nt.assert_in(type(item), [OsfStorageFile, OsfStorageFileNode])
def test_get_file_questions(self):
questions = get_file_questions('prereg-prize.json')
nt.assert_equal(7, len(questions))
nt.assert_list_equal(
[
(u'q7', u'Data collection procedures'),
(u'q11', u'Manipulated variables'),
(u'q12', u'Measured variables'),
(u'q13', u'Indices'),
(u'q16', u'Study design'),
(u'q19', u'Statistical models'),
#.........这里部分代码省略.........