Пример #1
0
 def withdrawn_registration_with_child(self, user, registration_with_child):
     withdrawn_registration = WithdrawnRegistrationFactory(
         registration=registration_with_child,
         user=registration_with_child.creator)
     withdrawn_registration.justification = 'We made a major error.'
     withdrawn_registration.save()
     return withdrawn_registration
Пример #2
0
 def withdrawn_registration(self, registration_withdrawn, user_admin):
     registration_withdrawn.add_tag(
         'existing-tag', auth=Auth(user=user_admin))
     registration_withdrawn.save()
     withdrawn_registration = WithdrawnRegistrationFactory(
         registration=registration_withdrawn, user=user_admin)
     withdrawn_registration.justification = 'We made a major error.'
     withdrawn_registration.save()
     return withdrawn_registration
 def withdrawn_registration(self, registration_withdrawn, user_admin):
     registration_withdrawn.add_tag('existing-tag',
                                    auth=Auth(user=user_admin))
     registration_withdrawn.save()
     withdrawn_registration = WithdrawnRegistrationFactory(
         registration=registration_withdrawn, user=user_admin)
     withdrawn_registration.justification = 'We made a major error.'
     withdrawn_registration.save()
     return withdrawn_registration
    def setUp(self):
        super(TestWithdrawnRegistrations, self).setUp()
        self.registration = RegistrationFactory(creator=self.user,
                                                project=self.public_project)
        self.withdrawn_registration = WithdrawnRegistrationFactory(
            registration=self.registration, user=self.registration.creator)

        self.public_pointer_project = ProjectFactory(is_public=True)
        self.public_pointer = self.public_project.add_pointer(
            self.public_pointer_project, auth=Auth(self.user), save=True)
        self.withdrawn_url = '/{}registrations/{}/?version=2.2'.format(
            API_BASE, self.registration._id)
        self.withdrawn_registration.justification = 'We made a major error.'
        self.withdrawn_registration.save()
    def test_auth_get_registrations(self, app, admin, registration_no_owner,
                                    registration_no_affiliation,
                                    registration_pending, registration_public,
                                    url_institution_registrations):

        # test getting registrations without auth (for complete registrations)
        res = app.get(url_institution_registrations)
        assert res.status_code == 200
        registration_ids = [reg['id'] for reg in res.json['data']]
        assert registration_no_affiliation._id not in registration_ids
        assert registration_pending._id not in registration_ids
        assert registration_no_owner._id not in registration_ids
        assert registration_public._id in registration_ids

        # Withdraw a registration, make sure it still shows up
        WithdrawnRegistrationFactory(registration=registration_public,
                                     user=admin)

        # test getting registrations with auth (for embargoed and pending)
        res = app.get(url_institution_registrations, auth=admin.auth)
        assert res.status_code == 200
        registration_ids = [reg['id'] for reg in res.json['data']]
        assert registration_no_affiliation._id not in registration_ids
        assert registration_pending._id in registration_ids
        assert registration_public._id in registration_ids
        assert registration_no_owner._id not in registration_ids
Пример #6
0
    def test_cannot_fork_retractions(self, app, user, private_registration, fork_data):
        with mock.patch('osf.models.AbstractNode.update_search'):
            retraction = WithdrawnRegistrationFactory(registration=private_registration, user=user)
        url = '/{}registrations/{}/forks/{}'.format(API_BASE, private_registration._id, '?embed=forked_from')

        res = app.post_json_api(url, fork_data, auth=user.auth, expect_errors=True)
        assert res.status_code == 403
Пример #7
0
    def setUp(self):
        super(TestWithdrawnRegistrations, self).setUp()
        self.registration = RegistrationFactory(creator=self.user, project=self.public_project)
        self.withdrawn_registration = WithdrawnRegistrationFactory(registration=self.registration, user=self.registration.creator)

        self.public_pointer_project = ProjectFactory(is_public=True)
        self.public_pointer = self.public_project.add_pointer(self.public_pointer_project,
                                                              auth=Auth(self.user),
                                                              save=True)
        self.withdrawn_url = '/{}registrations/{}/?version=2.2'.format(API_BASE, self.registration._id)
        self.withdrawn_registration.justification = 'We made a major error.'
        self.withdrawn_registration.save()
    def test_cannot_fork_retractions(self):
        with mock.patch('osf.models.AbstractNode.update_search'):
            retraction = WithdrawnRegistrationFactory(
                registration=self.private_registration, user=self.user)
        url = '/{}registrations/{}/forks/'.format(
            API_BASE, self.private_registration._id) + '?embed=forked_from'

        res = self.app.post_json_api(url,
                                     self.fork_data,
                                     auth=self.user.auth,
                                     expect_errors=True)
        assert_equal(res.status_code, 403)
    def test_doesnt_return_retractions_with_auth(self):
        retraction = WithdrawnRegistrationFactory(
            registration=self.registration2, user=self.user1)

        assert_true(self.registration2.is_retracted)

        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_not_in(self.registration2._id, ids)
    def test_linked_by_registrations_doesnt_show_retracted(self, app, url_public, user, project_public, project_private):
        project_private.add_pointer(project_public, auth=Auth(user), save=True)
        registration = RegistrationFactory(project=project_private, creator=user)
        project_public.reload()

        res = app.get(url_public, auth=user.auth)
        assert len(res.json['data']) == 1
        assert res.json['data'][0]['id'] == registration._id

        WithdrawnRegistrationFactory(registration=registration, user=user)
        project_public.reload()

        res = app.get(url_public, auth=user.auth)
        assert len(res.json['data']) == 0
    def test_add_withdrawn_registration(self, app,
                                        url_institution_registrations, admin,
                                        registration_no_affiliation,
                                        institution):
        WithdrawnRegistrationFactory(registration=registration_no_affiliation,
                                     user=admin)

        res = app.post_json_api(url_institution_registrations,
                                make_registration_payload(
                                    registration_no_affiliation._id),
                                auth=admin.auth)

        assert res.status_code == 201
        registration_no_affiliation.reload()
        assert institution in registration_no_affiliation.affiliated_institutions.all(
        )
Пример #12
0
    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.public_project.creator)
        self.embargoed_registration.embargo_registration(
            self.embargoed_registration.creator,
            timezone.now() + 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)

        # Add Spam
        self.spam_node = ProjectFactory(spam_status=2)

        self.date = timezone.now() - datetime.timedelta(days=1)

        for node in AbstractNode.objects.all():
            node.created = self.date
            node.save()
        # modify_node_dates_in_mongo(self.date - datetime.timedelta(0.1))

        self.results = NodeSummary().get_events(self.date.date())[0]
 def withdrawn_registration_with_child(self, user, registration_with_child):
     withdrawn_registration = WithdrawnRegistrationFactory(
         registration=registration_with_child, user=registration_with_child.creator)
     withdrawn_registration.justification = 'We made a major error.'
     withdrawn_registration.save()
     return withdrawn_registration
class TestWithdrawnRegistrations(NodeCRUDTestCase):
    def setUp(self):
        super(TestWithdrawnRegistrations, self).setUp()
        self.registration = RegistrationFactory(creator=self.user,
                                                project=self.public_project)
        self.withdrawn_registration = WithdrawnRegistrationFactory(
            registration=self.registration, user=self.registration.creator)

        self.public_pointer_project = ProjectFactory(is_public=True)
        self.public_pointer = self.public_project.add_pointer(
            self.public_pointer_project, auth=Auth(self.user), save=True)
        self.withdrawn_url = '/{}registrations/{}/?version=2.2'.format(
            API_BASE, self.registration._id)
        self.withdrawn_registration.justification = 'We made a major error.'
        self.withdrawn_registration.save()

    def test_can_access_withdrawn_contributors(self):
        url = '/{}registrations/{}/contributors/'.format(
            API_BASE, self.registration._id)
        res = self.app.get(url, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 200)

    def test_cannot_access_withdrawn_children(self):
        url = '/{}registrations/{}/children/'.format(API_BASE,
                                                     self.registration._id)
        res = self.app.get(url, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 403)

    def test_cannot_access_withdrawn_comments(self):
        self.public_project = ProjectFactory(is_public=True, creator=self.user)
        self.public_comment = CommentFactory(node=self.public_project,
                                             user=self.user)
        url = '/{}registrations/{}/comments/'.format(API_BASE,
                                                     self.registration._id)
        res = self.app.get(url, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 403)

    def test_can_access_withdrawn_contributor_detail(self):
        url = '/{}registrations/{}/contributors/{}/'.format(
            API_BASE, self.registration._id, self.user._id)
        res = self.app.get(url, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 200)

    def test_cannot_return_a_withdrawn_registration_at_node_detail_endpoint(
            self):
        url = '/{}nodes/{}/'.format(API_BASE, self.registration._id)
        res = self.app.get(url, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 404)

    def test_cannot_delete_a_withdrawn_registration(self):
        url = '/{}registrations/{}/'.format(API_BASE, self.registration._id)
        res = self.app.delete_json_api(url,
                                       auth=self.user.auth,
                                       expect_errors=True)
        self.registration.reload()
        assert_equal(res.status_code, 405)

    def test_cannot_access_withdrawn_files_list(self):
        url = '/{}registrations/{}/files/'.format(API_BASE,
                                                  self.registration._id)
        res = self.app.get(url, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 403)

    def test_cannot_access_withdrawn_node_links_detail(self):
        url = '/{}registrations/{}/node_links/{}/'.format(
            API_BASE, self.registration._id, self.public_pointer._id)
        res = self.app.get(url, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 403)

    def test_cannot_access_withdrawn_node_links_list(self):
        url = '/{}registrations/{}/node_links/'.format(API_BASE,
                                                       self.registration._id)
        res = self.app.get(url, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 403)

    def test_cannot_access_withdrawn_node_logs(self):
        self.public_project = ProjectFactory(is_public=True, creator=self.user)
        url = '/{}registrations/{}/logs/'.format(API_BASE,
                                                 self.registration._id)
        res = self.app.get(url, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 403)

    def test_cannot_access_withdrawn_registrations_list(self):
        self.registration.save()
        url = '/{}registrations/{}/registrations/'.format(
            API_BASE, self.registration._id)
        res = self.app.get(url, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 403)

    def test_withdrawn_registrations_display_limited_fields(self):
        registration = self.registration
        res = self.app.get(self.withdrawn_url, auth=self.user.auth)
        assert_equal(res.status_code, 200)
        attributes = res.json['data']['attributes']
        registration.reload()
        expected_attributes = {
            'title':
            registration.title,
            'description':
            registration.description,
            'date_created':
            registration.date_created.isoformat().replace('+00:00', 'Z'),
            'date_registered':
            registration.registered_date.isoformat().replace('+00:00', 'Z'),
            'date_modified':
            registration.date_modified.isoformat().replace('+00:00', 'Z'),
            'date_withdrawn':
            registration.retraction.date_retracted.isoformat().replace(
                '+00:00', 'Z'),
            'withdrawal_justification':
            registration.retraction.justification,
            'public':
            None,
            'category':
            None,
            'registration':
            True,
            'fork':
            None,
            'collection':
            None,
            'tags':
            None,
            'withdrawn':
            True,
            'pending_withdrawal':
            None,
            'pending_registration_approval':
            None,
            'pending_embargo_approval':
            None,
            'embargo_end_date':
            None,
            'registered_meta':
            None,
            'current_user_permissions':
            None,
            'registration_supplement':
            registration.registered_schema.first().name
        }

        for attribute in expected_attributes:
            assert_equal(expected_attributes[attribute], attributes[attribute])

        contributors = urlparse(
            res.json['data']['relationships']['contributors']['links']
            ['related']['href']).path
        assert_equal(
            contributors,
            '/{}registrations/{}/contributors/'.format(API_BASE,
                                                       registration._id))

        assert_not_in('children', res.json['data']['relationships'])
        assert_not_in('comments', res.json['data']['relationships'])
        assert_not_in('node_links', res.json['data']['relationships'])
        assert_not_in('registrations', res.json['data']['relationships'])
        assert_not_in('parent', res.json['data']['relationships'])
        assert_not_in('forked_from', res.json['data']['relationships'])
        assert_not_in('files', res.json['data']['relationships'])
        assert_not_in('logs', res.json['data']['relationships'])
        assert_not_in('registered_by', res.json['data']['relationships'])
        assert_not_in('registered_from', res.json['data']['relationships'])
        assert_not_in('root', res.json['data']['relationships'])

    def test_field_specific_related_counts_ignored_if_hidden_field_on_withdrawn_registration(
            self):
        url = '/{}registrations/{}/?related_counts=children'.format(
            API_BASE, self.registration._id)
        res = self.app.get(url, auth=self.user.auth)
        assert_equal(res.status_code, 200)
        assert_not_in('children', res.json['data']['relationships'])
        assert_in('contributors', res.json['data']['relationships'])

    def test_field_specific_related_counts_retrieved_if_visible_field_on_withdrawn_registration(
            self):
        url = '/{}registrations/{}/?related_counts=contributors'.format(
            API_BASE, self.registration._id)
        res = self.app.get(url, auth=self.user.auth)
        assert_equal(res.status_code, 200)
        assert_equal(
            res.json['data']['relationships']['contributors']['links']
            ['related']['meta']['count'], 1)
Пример #15
0
def withdrawn_registration(registration):
    return WithdrawnRegistrationFactory(registration=registration,
                                        user=registration.creator)
Пример #16
0
class TestWithdrawnRegistrations(NodeCRUDTestCase):

    def setUp(self):
        super(TestWithdrawnRegistrations, self).setUp()
        self.registration = RegistrationFactory(creator=self.user, project=self.public_project)
        self.withdrawn_registration = WithdrawnRegistrationFactory(registration=self.registration, user=self.registration.creator)

        self.public_pointer_project = ProjectFactory(is_public=True)
        self.public_pointer = self.public_project.add_pointer(self.public_pointer_project,
                                                              auth=Auth(self.user),
                                                              save=True)
        self.withdrawn_url = '/{}registrations/{}/?version=2.2'.format(API_BASE, self.registration._id)
        self.withdrawn_registration.justification = 'We made a major error.'
        self.withdrawn_registration.save()

    def test_can_access_withdrawn_contributors(self):
        url = '/{}registrations/{}/contributors/'.format(API_BASE, self.registration._id)
        res = self.app.get(url, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 200)

    def test_cannot_access_withdrawn_children(self):
        url = '/{}registrations/{}/children/'.format(API_BASE, self.registration._id)
        res = self.app.get(url, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 403)

    def test_cannot_access_withdrawn_comments(self):
        self.public_project = ProjectFactory(is_public=True, creator=self.user)
        self.public_comment = CommentFactory(node=self.public_project, user=self.user)
        url = '/{}registrations/{}/comments/'.format(API_BASE, self.registration._id)
        res = self.app.get(url, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 403)

    def test_can_access_withdrawn_contributor_detail(self):
        url = '/{}registrations/{}/contributors/{}/'.format(API_BASE, self.registration._id, self.user._id)
        res = self.app.get(url, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 200)

    def test_cannot_return_a_withdrawn_registration_at_node_detail_endpoint(self):
        url = '/{}nodes/{}/'.format(API_BASE, self.registration._id)
        res = self.app.get(url, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 404)

    def test_cannot_delete_a_withdrawn_registration(self):
        url = '/{}registrations/{}/'.format(API_BASE, self.registration._id)
        res = self.app.delete_json_api(url, auth=self.user.auth, expect_errors=True)
        self.registration.reload()
        assert_equal(res.status_code, 405)

    def test_cannot_access_withdrawn_files_list(self):
        url = '/{}registrations/{}/files/'.format(API_BASE, self.registration._id)
        res = self.app.get(url, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 403)

    def test_cannot_access_withdrawn_node_links_detail(self):
        url = '/{}registrations/{}/node_links/{}/'.format(API_BASE, self.registration._id, self.public_pointer._id)
        res = self.app.get(url, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 403)

    def test_cannot_access_withdrawn_node_links_list(self):
        url = '/{}registrations/{}/node_links/'.format(API_BASE, self.registration._id)
        res = self.app.get(url, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 403)

    def test_cannot_access_withdrawn_node_logs(self):
        self.public_project = ProjectFactory(is_public=True, creator=self.user)
        url = '/{}registrations/{}/logs/'.format(API_BASE, self.registration._id)
        res = self.app.get(url, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 403)

    def test_cannot_access_withdrawn_registrations_list(self):
        self.registration.save()
        url = '/{}registrations/{}/registrations/'.format(API_BASE, self.registration._id)
        res = self.app.get(url, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 403)

    def test_withdrawn_registrations_display_limited_fields(self):
        registration = self.registration
        res = self.app.get(self.withdrawn_url, auth=self.user.auth)
        assert_equal(res.status_code, 200)
        attributes = res.json['data']['attributes']
        registration.reload()
        expected_attributes = {
            'title': registration.title,
            'description': registration.description,
            'date_created': registration.date_created.isoformat().replace('+00:00', 'Z'),
            'date_registered': registration.registered_date.isoformat().replace('+00:00', 'Z'),
            'date_modified': registration.date_modified.isoformat().replace('+00:00', 'Z'),
            'date_withdrawn': registration.retraction.date_retracted.isoformat().replace('+00:00', 'Z'),
            'withdrawal_justification': registration.retraction.justification,
            'public': None,
            'category': None,
            'registration': True,
            'fork': None,
            'collection': None,
            'tags': None,
            'withdrawn': True,
            'pending_withdrawal': None,
            'pending_registration_approval': None,
            'pending_embargo_approval': None,
            'embargo_end_date': None,
            'registered_meta': None,
            'current_user_permissions': None,
            'registration_supplement': registration.registered_schema.first().name
        }

        for attribute in expected_attributes:
            assert_equal(expected_attributes[attribute], attributes[attribute])

        contributors = urlparse(res.json['data']['relationships']['contributors']['links']['related']['href']).path
        assert_equal(contributors, '/{}registrations/{}/contributors/'.format(API_BASE, registration._id))

        assert_not_in('children', res.json['data']['relationships'])
        assert_not_in('comments', res.json['data']['relationships'])
        assert_not_in('node_links', res.json['data']['relationships'])
        assert_not_in('registrations', res.json['data']['relationships'])
        assert_not_in('parent', res.json['data']['relationships'])
        assert_not_in('forked_from', res.json['data']['relationships'])
        assert_not_in('files', res.json['data']['relationships'])
        assert_not_in('logs', res.json['data']['relationships'])
        assert_not_in('registered_by', res.json['data']['relationships'])
        assert_not_in('registered_from', res.json['data']['relationships'])
        assert_not_in('root', res.json['data']['relationships'])

    def test_field_specific_related_counts_ignored_if_hidden_field_on_withdrawn_registration(self):
        url = '/{}registrations/{}/?related_counts=children'.format(API_BASE, self.registration._id)
        res = self.app.get(url, auth=self.user.auth)
        assert_equal(res.status_code, 200)
        assert_not_in('children', res.json['data']['relationships'])
        assert_in('contributors', res.json['data']['relationships'])

    def test_field_specific_related_counts_retrieved_if_visible_field_on_withdrawn_registration(self):
        url = '/{}registrations/{}/?related_counts=contributors'.format(API_BASE, self.registration._id)
        res = self.app.get(url, auth=self.user.auth)
        assert_equal(res.status_code, 200)
        assert_equal(res.json['data']['relationships']['contributors']['links']['related']['meta']['count'], 1)
Пример #17
0
 def withdrawn_registration(self, registration):
     withdrawn_registration = WithdrawnRegistrationFactory(
         registration=registration, user=registration.creator)
     withdrawn_registration.justification = 'We made a major error.'
     withdrawn_registration.save()
     return withdrawn_registration
 def withdrawn_registration(self, registration):
     withdrawn_registration = WithdrawnRegistrationFactory(
         registration=registration, user=registration.creator)
     withdrawn_registration.justification = 'We made a major error.'
     withdrawn_registration.save()
     return withdrawn_registration
Пример #19
0
 def retraction(self, resource, user):
     return WithdrawnRegistrationFactory(registration=resource)
Пример #20
0
 def withdrawn_registration(self):
     retraction = WithdrawnRegistrationFactory()
     registration = retraction.target_registration
     return registration