def test_cannot_update_a_retraction(self): registration = RegistrationFactory(creator=self.user, project=self.public_project) url = "/{}nodes/{}/".format(API_BASE, registration._id) retraction = RetractedRegistrationFactory(registration=registration, user=registration.creator) res = self.app.put_json_api( url, { "data": { "id": registration._id, "type": "nodes", "attributes": { "title": fake.catch_phrase(), "description": fake.bs(), "category": "hypothesis", "public": True, }, } }, auth=self.user.auth, expect_errors=True, ) registration.reload() assert_equal(res.status_code, 404) assert_equal(registration.title, registration.title) assert_equal(registration.description, registration.description)
def test_rejecting_embargo_for_existing_registration_does_not_deleted_component_registrations(self): component = NodeFactory( creator=self.user, parent=self.project, title='Component' ) subcomponent = NodeFactory( creator=self.user, parent=component, title='Subcomponent' ) project_registration = RegistrationFactory(project=self.project) component_registration = project_registration.nodes[0] subcomponent_registration = component_registration.nodes[0] project_registration.embargo_registration( self.user, datetime.datetime.utcnow() + datetime.timedelta(days=10), for_existing_registration=True ) rejection_token = project_registration.embargo.approval_state[self.user._id]['rejection_token'] project_registration.embargo.disapprove_embargo(self.user, rejection_token) project_registration.save() assert_equal(project_registration.embargo.state, Embargo.REJECTED) assert_false(project_registration.is_deleted) assert_false(component_registration.is_deleted) assert_false(subcomponent_registration.is_deleted)
def test_cannot_access_retracted_registrations_list(self): registration = RegistrationFactory(creator=self.user, project=self.public_project) retraction = RetractedRegistrationFactory(registration=registration, user=registration.creator) registration.save() url = '/{}nodes/{}/registrations/'.format(API_BASE, registration._id) res = self.app.get(url, auth=self.user.auth, expect_errors=True) assert_equal(res.status_code, 404)
def test_cancelling_registration_approval_deletes_component_registrations(self): component = NodeFactory( creator=self.user, parent=self.project, title='Component' ) NodeFactory( creator=self.user, parent=component, title='Subcomponent' ) project_registration = RegistrationFactory(project=self.project) component_registration = project_registration.nodes[0] subcomponent_registration = component_registration.nodes[0] project_registration.require_approval( self.user ) project_registration.save() rejection_token = project_registration.registration_approval.approval_state[self.user._id]['rejection_token'] project_registration.registration_approval.reject(self.user, rejection_token) assert_equal(project_registration.registration_approval.state, Sanction.REJECTED) assert_true(project_registration.is_deleted) assert_true(component_registration.is_deleted) assert_true(subcomponent_registration.is_deleted)
def test_view_project_pending_registration_for_admin_contributor_does_contain_cancel_link(self): pending_reg = RegistrationFactory(project=self.node, archive=True) assert_true(pending_reg.is_pending_registration) result = _view_project(pending_reg, Auth(self.user)) assert_not_equal(result["node"]["disapproval_link"], "") assert_in("/?token=", result["node"]["disapproval_link"]) pending_reg.remove()
def test_cannot_delete_a_retraction(self): registration = RegistrationFactory(creator=self.user, project=self.public_project) url = '/{}nodes/{}/'.format(API_BASE, registration._id) retraction = RetractedRegistrationFactory(registration=registration, user=registration.creator) res = self.app.delete_json_api(url, auth=self.user.auth, expect_errors=True) registration.reload() assert_equal(res.status_code, 404) assert_equal(registration.title, registration.title) assert_equal(registration.description, registration.description)
def test_view_project_pending_registration_for_write_contributor_does_not_contain_cancel_link(self): write_user = UserFactory() self.node.add_contributor(write_user, permissions=permissions.WRITE, auth=Auth(self.user), save=True) pending_reg = RegistrationFactory(project=self.node, archive=True) assert_true(pending_reg.is_pending_registration) result = _view_project(pending_reg, Auth(write_user)) assert_equal(result["node"]["disapproval_link"], "") pending_reg.remove()
def test_has_permission_on_parent_node_metadata_pass_if_registration(self): component_admin = AuthUserFactory() component = ProjectFactory(creator=component_admin, parent=self.node, is_public=False) component_registration = RegistrationFactory(project=component, creator=component_admin) assert_false(component_registration.has_permission(self.user, 'read')) res = views.check_access(component_registration, Auth(user=self.user), 'metadata', None) assert_true(res)
def test_register_draft_registration_already_registered(self): reg = RegistrationFactory(user=self.user) res = self.app.post_json( reg.api_url_for('register_draft_registration', draft_id=self.draft._id), self.invalid_payload, auth=self.user.auth, expect_errors=True ) assert_equal(res.status_code, http.BAD_REQUEST)
def test_new_draft_registration_on_registration(self): target = RegistrationFactory(user=self.user) payload = { 'schema_name': self.meta_schema.name, 'schema_version': self.meta_schema.schema_version } url = target.web_url_for('new_draft_registration') res = self.app.post(url, payload, auth=self.user.auth, expect_errors=True) assert_equal(res.status_code, http.FORBIDDEN)
def test_check_draft_state_registered_but_deleted(self): reg = RegistrationFactory() self.draft.registered_node = reg reg.is_deleted = True self.draft.save() try: draft_views.check_draft_state(self.draft) except Exception: self.fail()
def test_is_public_node_register_page(self): self.node.is_public = True self.node.save() reg = RegistrationFactory(project=self.node) reg.is_public = True reg.save() url = reg.web_url_for('node_register_page') res = self.app.get(url, auth=None) assert_equal(res.status_code, http.OK)
def test_check_draft_state_registered_and_deleted_and_approved(self): reg = RegistrationFactory() self.draft.registered_node = reg self.draft.save() reg.is_deleted = True reg.save() with mock.patch('website.project.model.DraftRegistration.is_approved', mock.PropertyMock(return_value=True)): try: draft_views.check_draft_state(self.draft) except HTTPError: self.fail()
def test_non_admin_can_view_node_register_page(self): non_admin = AuthUserFactory() self.node.add_contributor( non_admin, permissions.DEFAULT_CONTRIBUTOR_PERMISSIONS, auth=self.auth, save=True ) reg = RegistrationFactory(project=self.node) url = reg.web_url_for('node_register_page') res = self.app.get(url, auth=non_admin.auth) assert_equal(res.status_code, http.OK)
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"], {})
def test__on_complete_makes_project_and_components_public(self): project_admin = UserFactory() child_admin = UserFactory() grandchild_admin = UserFactory() project = ProjectFactory(creator=project_admin, is_public=False) child = NodeFactory(creator=child_admin, parent=project, is_public=False) grandchild = NodeFactory(creator=grandchild_admin, parent=child, is_public=False) # noqa registration = RegistrationFactory(project=project) registration._initiate_retraction(self.user) registration.retraction._on_complete(self.user) for each in registration.node_and_primary_descendants(): assert_true(each.is_public)
def test_cancelling_embargo_deletes_component_registrations(self): component = NodeFactory(creator=self.user, parent=self.project, title="Component") subcomponent = NodeFactory(creator=self.user, parent=component, title="Subcomponent") project_registration = RegistrationFactory(project=self.project) component_registration = project_registration.nodes[0] subcomponent_registration = component_registration.nodes[0] project_registration.embargo_registration(self.user, datetime.datetime.utcnow() + datetime.timedelta(days=10)) project_registration.save() rejection_token = project_registration.embargo.approval_state[self.user._id]["rejection_token"] project_registration.embargo.disapprove_embargo(self.user, rejection_token) assert_equal(project_registration.embargo.state, Embargo.REJECTED) assert_true(project_registration.is_deleted) assert_true(component_registration.is_deleted) assert_true(subcomponent_registration.is_deleted)
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 _set_up_registration_with_wiki_page(self): self._set_up_private_project_with_wiki_page() self.registration = RegistrationFactory(project=self.private_project, user=self.user) self.registration_wiki_id = self.registration.wiki_pages_versions["home"][0] self.registration.wiki_pages_current = {"home": self.registration_wiki_id} self.registration.save() self.registration_url = "/{}registrations/{}/wikis/".format(API_BASE, self.registration._id)
def setUp(self): super(TestRetractRegistrations, self).setUp() self.user = UserFactory() self.registration = RegistrationFactory(creator=self.user) self.registration.is_public = True self.registration.retract_registration(self.user) self.registration.save()
def setUp(self): super(RegistrationEmbargoModelsTestCase, self).setUp() self.user = UserFactory() self.project = ProjectFactory(creator=self.user) self.registration = RegistrationFactory(project=self.project) self.embargo = EmbargoFactory(user=self.user) self.valid_embargo_end_date = datetime.datetime.utcnow() + datetime.timedelta(days=3)
def _set_up_private_registration_with_wiki_page(self): self._set_up_private_project_with_wiki_page() self.private_registration = RegistrationFactory(project=self.private_project, user=self.user) self.private_registration_wiki_id = self.private_registration.wiki_pages_versions['home'][0] self.private_registration.wiki_pages_current = {'home': self.private_registration_wiki_id} self.private_registration.save() self.private_registration_url = '/{}wikis/{}/'.format(API_BASE, self.private_registration_wiki_id)
def _set_up_public_registration_with_wiki_page(self): self._set_up_public_project_with_wiki_page() self.public_registration = RegistrationFactory(project=self.public_project, user=self.user, is_public=True) self.public_registration_wiki_id = self.public_registration.wiki_pages_versions['home'][0] self.public_registration.wiki_pages_current = {'home': self.public_registration_wiki_id} self.public_registration.save() self.public_registration_url = '/{}registrations/{}/wikis/'.format(API_BASE, self.public_registration._id)
def setUp(self): super(RegistrationEmbargoViewsTestCase, self).setUp() ensure_schemas() self.user = AuthUserFactory() self.project = ProjectFactory(creator=self.user) self.draft = DraftRegistrationFactory(branched_from=self.project) self.registration = RegistrationFactory(project=self.project, creator=self.user) current_month = datetime.datetime.now().strftime("%B") current_year = datetime.datetime.now().strftime("%Y") self.valid_make_public_payload = json.dumps({ u'embargoEndDate': u'Fri, 01, {month} {year} 00:00:00 GMT'.format( month=current_month, year=current_year ), u'registrationChoice': 'immediate', u'summary': unicode(fake.sentence()) }) valid_date = datetime.datetime.now() + datetime.timedelta(days=180) self.valid_embargo_payload = json.dumps({ u'embargoEndDate': unicode(valid_date.strftime('%a, %d, %B %Y %H:%M:%S')) + u' GMT', u'registrationChoice': 'embargo', u'summary': unicode(fake.sentence()) }) self.invalid_embargo_date_payload = json.dumps({ u'embargoEndDate': u"Thu, 01 {month} {year} 05:00:00 GMT".format( month=current_month, year=str(int(current_year)-1) ), u'registrationChoice': 'embargo', u'summary': unicode(fake.sentence()) })
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 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 setUp(self): super(TestRetractRegistrations, self).setUp() self.user = UserFactory() self.registration = RegistrationFactory(creator=self.user) self.registration.embargo_registration( self.user, datetime.utcnow() + timedelta(days=10) ) self.registration.save()
def test_get_node_name(self): user = UserFactory() auth = Auth(user=user) another_user = UserFactory() another_auth = Auth(user=another_user) # Public (Can View) public_project = ProjectFactory(is_public=True) collector = rubeus.NodeFileCollector(node=public_project, auth=another_auth) node_name = u"{0}: {1}".format( public_project.project_or_component.capitalize(), sanitize.unescape_entities(public_project.title) ) assert_equal(collector._get_node_name(public_project), node_name) # Private (Can't View) registration_private = RegistrationFactory(creator=user) registration_private.is_public = False registration_private.save() collector = rubeus.NodeFileCollector(node=registration_private, auth=another_auth) assert_equal(collector._get_node_name(registration_private), u"Private Registration") content = ProjectFactory(creator=user) node = ProjectFactory(creator=user) forked_private = node.fork_node(auth=auth) forked_private.is_public = False forked_private.save() collector = rubeus.NodeFileCollector(node=forked_private, auth=another_auth) assert_equal(collector._get_node_name(forked_private), u"Private Fork") pointer_private = node.add_pointer(content, auth=auth) pointer_private.is_public = False pointer_private.save() collector = rubeus.NodeFileCollector(node=pointer_private, auth=another_auth) assert_equal(collector._get_node_name(pointer_private), u"Private Link") private_project = ProjectFactory(is_public=False) collector = rubeus.NodeFileCollector(node=private_project, auth=another_auth) assert_equal(collector._get_node_name(private_project), u"Private Component") private_node = NodeFactory(is_public=False) collector = rubeus.NodeFileCollector(node=private_node, auth=another_auth) assert_equal(collector._get_node_name(private_node), u"Private Component")
def test_cannot_update_a_retraction(self): registration = RegistrationFactory(creator=self.user, project=self.public_project) url = '/{}nodes/{}/'.format(API_BASE, registration._id) retraction = RetractedRegistrationFactory(registration=registration, user=registration.creator) res = self.app.put_json_api(url, { 'data': { 'id': registration._id, 'type': 'nodes', 'attributes': { 'title': fake.catch_phrase(), 'description': fake.bs(), 'category': 'hypothesis', 'public': True } } }, auth=self.user.auth, expect_errors=True) registration.reload() assert_equal(res.status_code, 404) assert_equal(registration.title, registration.title) assert_equal(registration.description, registration.description)
def test_make_child_embargoed_registration_public_asks_all_admins_in_tree(self, mock_ask): # Initiate and approve embargo node = NodeFactory(creator=self.user) c1 = AuthUserFactory() child = NodeFactory(parent=node, creator=c1) c2 = AuthUserFactory() NodeFactory(parent=child, creator=c2) registration = RegistrationFactory(project=node) registration.embargo_registration( self.user, datetime.datetime.utcnow() + datetime.timedelta(days=10) ) for user_id, embargo_tokens in registration.embargo.approval_state.iteritems(): approval_token = embargo_tokens['approval_token'] registration.embargo.approve_embargo(User.load(user_id), approval_token) self.registration.save() res = self.app.post( registration.api_url_for('project_set_privacy', permissions='public'), auth=self.user.auth ) assert_equal(res.status_code, 200) asked_admins = [(admin._id, n._id) for admin, n in mock_ask.call_args[0][0]] for admin, node in registration.get_admin_contributors_recursive(): assert_in((admin._id, node._id), asked_admins)
def test_rejecting_embargo_for_existing_registration_does_not_deleted_component_registrations( self): component = NodeFactory(creator=self.user, parent=self.project, title='Component') subcomponent = NodeFactory(creator=self.user, parent=component, title='Subcomponent') project_registration = RegistrationFactory(project=self.project) component_registration = project_registration.nodes[0] subcomponent_registration = component_registration.nodes[0] project_registration.embargo_registration( self.user, datetime.datetime.utcnow() + datetime.timedelta(days=10), for_existing_registration=True) rejection_token = project_registration.embargo.approval_state[ self.user._id]['rejection_token'] project_registration.embargo.disapprove_embargo( self.user, rejection_token) project_registration.save() assert_equal(project_registration.embargo.state, Embargo.REJECTED) assert_false(project_registration.is_deleted) assert_false(component_registration.is_deleted) assert_false(subcomponent_registration.is_deleted)
def _set_up_registration_with_comment(self): self.registration = RegistrationFactory(creator=self.user) self.registration_url = '/{}registrations/{}/'.format( API_BASE, self.registration._id) self.registration_comment = CommentFactory(node=self.registration, user=self.user) self.comment_url = '/{}comments/{}/'.format( API_BASE, self.registration_comment._id) reply_target = Guid.load(self.registration_comment._id) self.registration_comment_reply = CommentFactory( node=self.registration, target=reply_target, user=self.user) self.replies_url = '/{}registrations/{}/comments/?filter[target]={}'.format( API_BASE, self.registration._id, self.registration_comment._id)
def setUp(self): super(TestNodeCount, self).setUp() self.user = UserFactory() # 3 Projects - Public, Private, Private Component self.public_project = ProjectFactory(is_public=True) self.private_project = ProjectFactory(is_public=False) self.private_component = ProjectFactory(parent=self.private_project) # 5 Registrations - Public, Public Registrations of Private Proj + Component, Embargoed, Withdrawn self.public_registration = RegistrationFactory(project=self.public_project, is_public=True) self.registration_of_components = RegistrationFactory(project=self.private_project, is_public=True) registration_of_component = self.private_component.registrations_all[0] registration_of_component.is_public = True registration_of_component.save() self.embargoed_registration = RegistrationFactory(project=self.public_project, creator=self.user) self.embargoed_registration.embargo_registration( self.user, datetime.datetime.utcnow() + datetime.timedelta(days=10) ) self.embargoed_registration.save() self.reg_to_be_withdrawn = RegistrationFactory(project=self.public_project) self.withdrawn_registration = WithdrawnRegistrationFactory( registration=self.reg_to_be_withdrawn, user=self.reg_to_be_withdrawn.creator ) # Add Deleted Nodes self.deleted_node = ProjectFactory(is_deleted=True) self.deleted_node2 = ProjectFactory(is_deleted=True) self.date = datetime.datetime.utcnow() - datetime.timedelta(1) modify_node_dates_in_mongo(self.date - datetime.timedelta(0.1)) self.results = NodeSummary().get_events(self.date.date())[0]
def test_adding_registration_to_dashboard_increases_json_size_by_one( self, mock_from_kwargs): mock_from_kwargs.return_value = Auth(user=self.user) with app.test_request_context(): url = api_url_for('get_dashboard') res = self.app.get(url + ALL_MY_REGISTRATIONS_ID) init_len = len(res.json[u'data']) RegistrationFactory(creator=self.user) res = self.app.get(url + ALL_MY_REGISTRATIONS_ID) assert_equal(len(res.json[u'data']), init_len + 1)
def setUp(self): super(TestExplorePublicActivity, self).setUp() self.project = ProjectFactory(is_public=True) self.registration = RegistrationFactory(project=self.project) self.private_project = ProjectFactory(title="Test private project") # Add project to new and noteworthy projects self.new_and_noteworthy_links_node = ProjectFactory() self.new_and_noteworthy_links_node._id = settings.NEW_AND_NOTEWORTHY_LINKS_NODE self.new_and_noteworthy_links_node.add_pointer( self.project, auth=Auth(self.new_and_noteworthy_links_node.creator), save=True)
def setUp(self): super(RegistrationEmbargoViewsTestCase, self).setUp() ensure_schemas() self.user = AuthUserFactory() self.project = ProjectFactory(creator=self.user) self.draft = DraftRegistrationFactory(branched_from=self.project) self.registration = RegistrationFactory(project=self.project, creator=self.user) current_month = datetime.datetime.now().strftime("%B") current_year = datetime.datetime.now().strftime("%Y") self.valid_make_public_payload = json.dumps({ u'embargoEndDate': u'Fri, 01, {month} {year} 00:00:00 GMT'.format(month=current_month, year=current_year), u'registrationChoice': 'immediate', u'summary': unicode(fake.sentence()) }) valid_date = datetime.datetime.now() + datetime.timedelta(days=180) self.valid_embargo_payload = json.dumps({ u'embargoEndDate': unicode(valid_date.strftime('%a, %d, %B %Y %H:%M:%S')) + u' GMT', u'registrationChoice': 'embargo', u'summary': unicode(fake.sentence()) }) self.invalid_embargo_date_payload = json.dumps({ u'embargoEndDate': u"Thu, 01 {month} {year} 05:00:00 GMT".format( month=current_month, year=str(int(current_year) - 1)), u'registrationChoice': 'embargo', u'summary': unicode(fake.sentence()) })
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))
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
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 setUp(self): super(TestUserRegistrations, self).setUp() self.user_one = AuthUserFactory() self.user_one.social['twitter'] = 'howtopizza' self.user_one.save() self.user_two = AuthUserFactory() self.public_project_user_one = ProjectFactory(title="Public Project User One", is_public=True, creator=self.user_one) self.private_project_user_one = ProjectFactory(title="Private Project User One", is_public=False, creator=self.user_one) self.public_project_user_two = ProjectFactory(title="Public Project User Two", is_public=True, creator=self.user_two) self.private_project_user_two = ProjectFactory(title="Private Project User Two", is_public=False, creator=self.user_two) self.deleted_project_user_one = CollectionFactory(title="Deleted Project User One", is_public=False, creator=self.user_one, is_deleted=True) self.folder = CollectionFactory() self.deleted_folder = CollectionFactory(title="Deleted Folder User One", is_public=False, creator=self.user_one, is_deleted=True) self.bookmark_collection = BookmarkCollectionFactory() self.reg_public_project_user_one = RegistrationFactory(project=self.public_project_user_one, creator=self.user_one, is_public=True) self.reg_private_project_user_one = RegistrationFactory(project = self.private_project_user_one, creator=self.user_one, is_private=True) self.reg_public_project_user_two = RegistrationFactory(project = self.public_project_user_two, creator=self.user_two, is_public=True) self.reg_private_project_user_two = RegistrationFactory(project = self.private_project_user_two, creator=self.user_two, is_private=True)
def _set_up_registration_with_comment(self): self.registration = RegistrationFactory(creator=self.user, comment_level='private') self.registration_file = test_utils.create_test_file( self.registration, self.user) self.registration_comment = CommentFactory( node=self.registration, target=self.registration_file.get_guid(), user=self.user) self.comment_url = '/{}comments/{}/'.format( API_BASE, self.registration_comment._id) reply_target = Guid.load(self.registration_comment._id) self.registration_comment_reply = CommentFactory( node=self.registration, target=reply_target, user=self.user)
def _set_up_registration_with_comment(self): self.registration = RegistrationFactory(creator=self.user, comment_level='private') self.registration_wiki = NodeWikiFactory(node=self.registration, user=self.user) self.registration_comment = CommentFactory( node=self.registration, target=Guid.load(self.registration_wiki._id), user=self.user) self.comment_url = '/{}comments/{}/'.format( API_BASE, self.registration_comment._id) reply_target = Guid.load(self.registration_comment._id) self.registration_comment_reply = CommentFactory( node=self.registration, target=reply_target, user=self.user)
def setUp(self): super(RegistrationWithChildNodesRetractionModelTestCase, self).setUp() self.user = AuthUserFactory() self.auth = self.user.auth self.project = ProjectFactory(is_public=True, creator=self.user) self.component = NodeFactory( creator=self.user, parent=self.project, title='Component' ) self.subproject = ProjectFactory( creator=self.user, parent=self.project, title='Subproject' ) self.subproject_component = NodeFactory( creator=self.user, parent=self.subproject, title='Subcomponent' ) self.registration = RegistrationFactory(project=self.project, is_public=True) # Reload the registration; else tests won't catch failures to svae self.registration.reload()
def setUp(self): super(TestMigrateRegistrations, self).setUp() # Create registration with correct settings self.registration = RegistrationFactory() self.registration.registered_from.piwik_site_id = 1 self.registration.registered_from.save() self.registration.piwik_site_id = 2 self.registration.save() # Create registration with duplicated piwik_site_id self.broken_registration = RegistrationFactory() self.broken_registration.registered_from.piwik_site_id = 3 self.broken_registration.registered_from.save() self.broken_registration.piwik_site_id = 3 self.broken_registration.save() responses.start() responses.add( responses.GET, '{host}index.php?module=API&method=SitesManager.getAllSites&format=JSON&token_auth={auth_token}'.format( host=PIWIK_HOST, auth_token=PIWIK_ADMIN_TOKEN, ), status=200, content_type='application/json', body=json.dumps({ '1': {'name': 'Node: ' + self.registration.registered_from._id}, '2': {'name': 'Node: ' + self.registration._id}, '3': {'name': 'Node: ' + self.broken_registration.registered_from._id}, '4': {'name': 'Node: ' + self.broken_registration._id}, }), match_querystring=True, )
def setUp(self): super(TestRegistrationIdentifierList, self).setUp() self.user = AuthUserFactory() self.user_two = AuthUserFactory() self.registration = RegistrationFactory(creator=self.user, is_public=True) self.identifier = IdentifierFactory(referent=self.registration) self.url = '/{}registrations/{}/identifiers/'.format( API_BASE, self.registration._id) self.res = self.app.get(self.url) self.data = self.res.json['data'] self.all_identifiers = Identifier.find()
def test__initiate_retraction_adds_admins_on_child_nodes(self): project_admin = UserFactory() project_non_admin = UserFactory() child_admin = UserFactory() child_non_admin = UserFactory() grandchild_admin = UserFactory() project = ProjectFactory(creator=project_admin) project.add_contributor(project_non_admin, auth=Auth(project.creator), save=True) child = NodeFactory(creator=child_admin, parent=project) child.add_contributor(child_non_admin, auth=Auth(child.creator), save=True) grandchild = NodeFactory(creator=grandchild_admin, parent=child) # noqa registration = RegistrationFactory(project=project) retraction = registration._initiate_retraction(registration.creator) assert_in(project_admin._id, retraction.approval_state) assert_in(child_admin._id, retraction.approval_state) assert_in(grandchild_admin._id, retraction.approval_state) assert_not_in(project_non_admin._id, retraction.approval_state) assert_not_in(child_non_admin._id, retraction.approval_state)
def setUp(self): super(RegistrationWithChildNodesEmbargoModelTestCase, self).setUp() self.user = AuthUserFactory() self.auth = self.user.auth self.valid_embargo_end_date = datetime.datetime.utcnow() + datetime.timedelta(days=3) self.project = ProjectFactory(title='Root', is_public=False, creator=self.user) self.component = NodeFactory( creator=self.user, parent=self.project, title='Component' ) self.subproject = ProjectFactory( creator=self.user, parent=self.project, title='Subproject' ) self.subproject_component = NodeFactory( creator=self.user, parent=self.subproject, title='Subcomponent' ) self.registration = RegistrationFactory(project=self.project) # Reload the registration; else tests won't catch failures to save self.registration.reload()
def test_cannot_create_child_on_a_registration(self): registration = RegistrationFactory(project=self.project, creator=self.user) url = '/{}nodes/{}/children/'.format(API_BASE, registration._id) res = self.app.post_json_api(url, { 'data': { 'type': 'nodes', 'attributes': { 'title': fake.catch_phrase(), 'description': fake.bs(), 'category': 'project', 'public': True, } } }, auth=self.user.auth, expect_errors=True) assert_equal(res.status_code, 404)
def test__on_complete_makes_project_and_components_public(self): project_admin = UserFactory() child_admin = UserFactory() grandchild_admin = UserFactory() project = ProjectFactory(creator=project_admin, is_public=False) child = NodeFactory(creator=child_admin, parent=project, is_public=False) grandchild = NodeFactory(creator=grandchild_admin, parent=child, is_public=False) # noqa registration = RegistrationFactory(project=project) with mock.patch.object(PreregCallbackMixin, '_notify_initiator'): registration.registration_approval._on_complete(self.user)
def setUp(self): super(TestRegistrations, self).setUp() ensure_schemas() self.user = UserFactory() # Add an API key for quicker authentication api_key = ApiKeyFactory() self.user.api_keys.append(api_key) self.user.save() self.auth = ('test', api_key._primary_key) self.original = ProjectFactory(creator=self.user, is_public=True) # A registration self.project = RegistrationFactory( creator=self.user, project=self.original, user=self.user, )
def test_serialization(self): user = UserFactory() req = make_drf_request_with_version(version='2.0') reg = RegistrationFactory(creator=user) result = RegistrationSerializer(reg, context={'request': req}).data data = result['data'] assert_equal(data['id'], reg._id) assert_equal(data['type'], 'registrations') should_not_relate_to_registrations = [ 'registered_from', 'registered_by', 'registration_schema' ] # Attributes attributes = data['attributes'] assert_datetime_equal( parse_date(attributes['date_registered']), reg.registered_date ) assert_equal(attributes['withdrawn'], reg.is_retracted) # Relationships relationships = data['relationships'] relationship_urls = {} for relationship in relationships: relationship_urls[relationship]=relationships[relationship]['links']['related']['href'] assert_in('registered_by', relationships) registered_by = relationships['registered_by']['links']['related']['href'] assert_equal( urlparse(registered_by).path, '/{}users/{}/'.format(API_BASE, user._id) ) assert_in('registered_from', relationships) registered_from = relationships['registered_from']['links']['related']['href'] assert_equal( urlparse(registered_from).path, '/{}nodes/{}/'.format(API_BASE, reg.registered_from._id) ) for relationship in relationship_urls: if relationship in should_not_relate_to_registrations: assert_not_in('/{}registrations/'.format(API_BASE), relationship_urls[relationship]) else: assert_in('/{}registrations/'.format(API_BASE), relationship_urls[relationship], 'For key {}'.format(relationship))
def test_cannot_delete_if_registration(self): registration = RegistrationFactory(project=self.public_project) url = '/{}registrations/{}/node_links/'.format( API_BASE, registration._id, ) res = self.app.get(url, auth=self.user.auth) assert_equal(res.status_code, 200) pointer_id = res.json['data'][0]['id'] url = '/{}nodes/{}/node_links/{}/'.format( API_BASE, registration._id, pointer_id, ) res = self.app.delete(url, auth=self.user.auth, expect_errors=True) assert_equal(res.status_code, 403)
def test_cannot_add_link_to_registration(self): registration = RegistrationFactory(creator=self.user) url = '/{}nodes/{}/node_links/'.format(API_BASE, registration._id) payload = { 'data': { 'type': 'node_links', 'relationships': { 'nodes': { 'data': { 'id': self.public_pointer_project._id, 'type': 'nodes' } } } } } res = self.app.post_json_api(url, payload, auth=self.user.auth, expect_errors=True) assert_equal(res.status_code, 404)
def setUp(self): super(TestNodeLinkedNodes, self).setUp() self.user = AuthUserFactory() self.auth = Auth(self.user) self.linking_node_source = NodeFactory(creator=self.user) self.linked_node = NodeFactory(creator=self.user) self.linked_node2 = NodeFactory(creator=self.user) self.public_node = NodeFactory(is_public=True, creator=self.user) self.linking_node_source.add_pointer(self.linked_node, auth=self.auth) self.linking_node_source.add_pointer(self.linked_node2, auth=self.auth) self.linking_node_source.add_pointer(self.public_node, auth=self.auth) self.linking_node_source.save() self.linking_node = RegistrationFactory( project=self.linking_node_source, creator=self.user) self.url = '/{}registrations/{}/linked_nodes/'.format( API_BASE, self.linking_node._id) self.node_ids = [ pointer.node._id for pointer in self.linking_node.nodes_pointer ]
def test_GET_disapprove_with_valid_token_returns_redirect_to_parent(self): project = ProjectFactory(creator=self.user) registration = RegistrationFactory(project=project) registration.embargo_registration( self.user, datetime.datetime.utcnow() + datetime.timedelta(days=10)) registration.save() assert_true(registration.is_pending_embargo) rejection_token = registration.embargo.approval_state[ self.user._id]['rejection_token'] res = self.app.get( registration.web_url_for('view_project', token=rejection_token), auth=self.user.auth, ) registration.embargo.reload() assert_equal(registration.embargo.state, Embargo.REJECTED) assert_false(registration.is_pending_embargo) assert_equal(res.status_code, 302)
def setUp(self): super(TestIdentifierDetail, self).setUp() self.user = AuthUserFactory() self.registration = RegistrationFactory(creator=self.user, is_public=True) self.registration_identifier = IdentifierFactory( referent=self.registration) self.registration_url = '/{}identifiers/{}/'.format( API_BASE, self.registration_identifier._id) self.node = NodeFactory(creator=self.user, is_public=True) self.node_identifier = IdentifierFactory(referent=self.node) self.node_url = '/{}identifiers/{}/'.format(API_BASE, self.node_identifier._id) self.registration_res = self.app.get(self.registration_url) self.registration_data = self.registration_res.json['data'] self.node_res = self.app.get(self.node_url) self.node_data = self.node_res.json['data']
def test_linked_nodes_only_return_viewable_nodes(self): user = AuthUserFactory() new_linking_node = NodeFactory(creator=user) self.linked_node.add_contributor(user, auth=self.auth, save=True) self.linked_node2.add_contributor(user, auth=self.auth, save=True) self.public_node.add_contributor(user, auth=self.auth, save=True) new_linking_node.add_pointer(self.linked_node, auth=Auth(user)) new_linking_node.add_pointer(self.linked_node2, auth=Auth(user)) new_linking_node.add_pointer(self.public_node, auth=Auth(user)) new_linking_node.save() new_linking_registration = RegistrationFactory( project=new_linking_node, creator=self.user) res = self.app.get('/{}registrations/{}/linked_nodes/'.format( API_BASE, new_linking_registration._id), auth=user.auth) assert_equal(res.status_code, 200) nodes_returned = [ linked_node['id'] for linked_node in res.json['data'] ] assert_equal(len(nodes_returned), len(self.node_ids)) for node_id in self.node_ids: assert_in(node_id, nodes_returned) self.linked_node2.remove_contributor(user, auth=self.auth) self.public_node.remove_contributor(user, auth=self.auth) res = self.app.get('/{}registrations/{}/linked_nodes/'.format( API_BASE, new_linking_registration._id), auth=user.auth) nodes_returned = [ linked_node['id'] for linked_node in res.json['data'] ] assert_equal(len(nodes_returned), len(self.node_ids) - 1) assert_in(self.linked_node._id, nodes_returned) assert_in(self.public_node._id, nodes_returned) assert_not_in(self.linked_node2._id, nodes_returned)