Beispiel #1
0
 def node_with_abstract(self, user):
     node_with_abstract = NodeFactory(title='Sambolera', creator=user, is_public=True)
     node_with_abstract.set_description(
         'Sambolera by Khadja Nin',
         auth=Auth(user),
         save=True)
     return node_with_abstract
Beispiel #2
0
    def test_fork_reverts_to_using_user_storage_default(self):
        user = UserFactory()
        user2 = UserFactory()
        us = RegionFactory()
        canada = RegionFactory()

        user_settings = user.get_addon('osfstorage')
        user_settings.default_region = us
        user_settings.save()
        user2_settings = user2.get_addon('osfstorage')
        user2_settings.default_region = canada
        user2_settings.save()

        project = ProjectFactory(creator=user, is_public=True)
        child = NodeFactory(parent=project, creator=user, is_public=True)
        child_settings = child.get_addon('osfstorage')
        child_settings.region_id = canada.id
        child_settings.save()

        fork = project.fork_node(Auth(user))
        child_fork = models.Node.objects.get_children(fork).first()
        assert fork.get_addon('osfstorage').region_id == us.id
        assert fork.get_addon('osfstorage').user_settings == user.get_addon('osfstorage')
        assert child_fork.get_addon('osfstorage').region_id == us.id

        fork = project.fork_node(Auth(user2))
        child_fork = models.Node.objects.get_children(fork).first()
        assert fork.get_addon('osfstorage').region_id == canada.id
        assert fork.get_addon('osfstorage').user_settings == user2.get_addon('osfstorage')
        assert child_fork.get_addon('osfstorage').region_id == canada.id
Beispiel #3
0
    def test__initiate_embargo_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)

        embargo = registration._initiate_embargo(
            project.creator,
            self.valid_embargo_end_date,
            for_existing_registration=True
        )
        assert_in(project_admin._id, embargo.approval_state)
        assert_in(child_admin._id, embargo.approval_state)
        assert_in(grandchild_admin._id, embargo.approval_state)

        assert_not_in(project_non_admin._id, embargo.approval_state)
        assert_not_in(child_non_admin._id, embargo.approval_state)
Beispiel #4
0
    def test_node_serializer(self, user):

    #   test_node_serialization
        parent = ProjectFactory(creator=user)
        node = NodeFactory(creator=user, parent=parent)
        req = make_drf_request_with_version(version='2.0')
        result = NodeSerializer(node, context={'request': req}).data
        data = result['data']
        assert data['id'] == node._id
        assert data['type'] == 'nodes'

        # Attributes
        attributes = data['attributes']
        assert attributes['title'] == node.title
        assert attributes['description'] == node.description
        assert attributes['public'] == node.is_public
        assert attributes['tags'] == [str(each.name) for each in node.tags.all()]
        assert attributes['current_user_can_comment'] == False
        assert attributes['category'] == node.category
        assert attributes['registration'] == node.is_registration
        assert attributes['fork'] == node.is_fork
        assert attributes['collection'] == node.is_collection

        # Relationships
        relationships = data['relationships']
        assert 'children' in relationships
        assert 'contributors' in relationships
        assert 'files' in relationships
        assert 'parent' in relationships
        assert 'affiliated_institutions' in relationships
        assert 'registrations' in relationships
        # Not a fork, so forked_from is removed entirely
        assert 'forked_from' not in relationships
        parent_link = relationships['parent']['links']['related']['href']
        assert urlparse(parent_link).path == '/{}nodes/{}/'.format(API_BASE, parent._id)

    #   test_fork_serialization
        node = NodeFactory(creator=user)
        fork = node.fork_node(auth=Auth(user))
        req = make_drf_request_with_version(version='2.0')
        result = NodeSerializer(fork, context={'request': req}).data
        data = result['data']

        # Relationships
        relationships = data['relationships']
        forked_from = relationships['forked_from']['links']['related']['href']
        assert urlparse(forked_from).path == '/{}nodes/{}/'.format(API_BASE, node._id)

    #   test_template_serialization
        node = NodeFactory(creator=user)
        fork = node.use_as_template(auth=Auth(user))
        req = make_drf_request_with_version(version='2.0')
        result = NodeSerializer(fork, context={'request': req}).data
        data = result['data']

        # Relationships
        relationships = data['relationships']
        templated_from = relationships['template_node']['links']['related']['href']
        assert urlparse(templated_from).path == '/{}nodes/{}/'.format(API_BASE, node._id)
Beispiel #5
0
 def test_is_current_with_single_version(self):
     node = NodeFactory()
     page = NodeWikiPage(page_name='foo', node=node)
     page.save()
     node.wiki_pages_current['foo'] = page._id
     node.wiki_pages_versions['foo'] = [page._id]
     node.save()
     assert page.is_current is True
 def test_get_nodes_deleted_component(self):
     node = NodeFactory(creator=self.project.creator, parent=self.project)
     node.is_deleted = True
     collector = rubeus.NodeFileCollector(
         self.project, Auth(user=UserFactory())
     )
     nodes = collector._get_nodes(self.project)
     assert_equal(len(nodes['children']), 0)
Beispiel #7
0
 def test_collect_components_deleted(self):
     node = NodeFactory(creator=self.project.creator, parent=self.project)
     node.is_deleted = True
     collector = rubeus.NodeFileCollector(
         self.project, Auth(user=UserFactory())
     )
     nodes = collector._collect_components(self.project, visited=[])
     assert_equal(len(nodes), 0)
 def child_node_two(self, user, parent_project, institution):
     child_node_two = NodeFactory(
         parent=parent_project,
         creator=user,
         is_public=True)
     child_node_two.affiliated_institutions.add(institution)
     child_node_two.save()
     return child_node_two
 def great_grandchild_node_two(
         self, user, grandchild_node_two,
         institution
 ):
     great_grandchild_node_two = NodeFactory(
         parent=grandchild_node_two, creator=user, is_public=True)
     great_grandchild_node_two.affiliated_institutions.add(institution)
     great_grandchild_node_two.save()
     return great_grandchild_node_two
Beispiel #10
0
    def test_serialize_node_search_returns_only_visible_contributors(self):
        node = NodeFactory()
        non_visible_contributor = UserFactory()
        node.add_contributor(non_visible_contributor, visible=False)
        serialized_node = _serialize_node_search(node)

        assert_equal(serialized_node['firstAuthor'], node.visible_contributors[0].family_name)
        assert_equal(len(node.visible_contributors), 1)
        assert_false(serialized_node['etal'])
class TestValidProject(OsfTestCase):

    def setUp(self):
        super(TestValidProject, self).setUp()
        self.project = ProjectFactory()
        self.node = NodeFactory()
        self.auth = Auth(user=self.project.creator)

    def test_populates_kwargs_node(self):
        res = valid_project_helper(pid=self.project._id)
        assert_equal(res['node'], self.project)
        assert_is_none(res['parent'])

    def test_populates_kwargs_node_and_parent(self):
        res = valid_project_helper(pid=self.project._id, nid=self.node._id)
        assert_equal(res['parent'], self.project)
        assert_equal(res['node'], self.node)

    def test_project_not_found(self):
        with assert_raises(HTTPError) as exc_info:
            valid_project_helper(pid='fakepid')
        assert_equal(exc_info.exception.code, 404)

    def test_project_deleted(self):
        self.project.is_deleted = True
        self.project.save()
        with assert_raises(HTTPError) as exc_info:
            valid_project_helper(pid=self.project._id)
        assert_equal(exc_info.exception.code, 410)

    def test_node_not_found(self):
        with assert_raises(HTTPError) as exc_info:
            valid_project_helper(pid=self.project._id, nid='fakenid')
        assert_equal(exc_info.exception.code, 404)

    def test_node_deleted(self):
        self.node.is_deleted = True
        self.node.save()
        with assert_raises(HTTPError) as exc_info:
            valid_project_helper(pid=self.project._id, nid=self.node._id)
        assert_equal(exc_info.exception.code, 410)

    def test_valid_project_as_factory_allow_retractions_is_retracted(self):
        registration = RegistrationFactory(project=self.project)
        registration.retraction = RetractionFactory()
        registration.retraction.state = Sanction.UNAPPROVED
        registration.retraction.save()
        res = as_factory_allow_retractions(pid=registration._id)
        assert_equal(res['node'], registration)

    def test_collection_guid_not_found(self):
        collection = CollectionFactory()
        collection.collect_object(self.project, self.auth.user)
        with assert_raises(HTTPError) as exc_info:
            valid_project_helper(pid=collection._id, nid=collection._id)
        assert_equal(exc_info.exception.code, 404)
 def test_serialize_deleted(self):
     node = NodeFactory()
     info = serialize_node(node)
     assert_false(info['deleted'])
     node.is_deleted = True
     info = serialize_node(node)
     assert_true(info['deleted'])
     node.is_deleted = False
     info = serialize_node(node)
     assert_false(info['deleted'])
 def test_affiliated_component_with_affiliated_parent_not_returned(self, app, user, institution, public_node, institution_node_url):
     # version < 2.2
     component = NodeFactory(parent=public_node, is_public=True)
     component.affiliated_institutions.add(institution)
     component.save()
     res = app.get(institution_node_url, auth=user.auth)
     affiliated_node_ids = [node['id'] for node in res.json['data']]
     assert res.status_code == 200
     assert public_node._id in affiliated_node_ids
     assert component._id not in affiliated_node_ids
 def test_user_is_admin(self):
     node = NodeFactory(creator=self.user)
     res = self.app.post_json_api(
         self.institution_nodes_url,
         self.create_payload(node._id),
         auth=self.user.auth
     )
     assert_equal(res.status_code, 201)
     node.reload()
     assert_in(self.institution, node.affiliated_institutions.all())
Beispiel #15
0
 def test_a_public_component_from_home_page(self):
     component = NodeFactory(title='Foobar Component', is_public=True)
     # Searches a part of the name
     res = self.app.get('/').maybe_follow()
     component.reload()
     form = res.forms['searchBar']
     form['q'] = 'Foobar'
     res = form.submit().maybe_follow()
     # A link to the component is shown as a result
     assert_in('Foobar Component', res)
 def test_email_not_sent_to_parent_admins_on_submit(self, mock_mail, app, project, noncontrib, url, create_payload, second_admin):
     component = NodeFactory(parent=project, creator=second_admin)
     component.is_public = True
     project.save()
     url = '/{}nodes/{}/requests/'.format(API_BASE, component._id)
     res = app.post_json_api(url, create_payload, auth=noncontrib.auth)
     assert res.status_code == 201
     assert component.admin_contributors.count() == 2
     assert component.contributors.count() == 1
     assert mock_mail.call_count == 1
Beispiel #17
0
 def test_is_current_with_multiple_versions(self):
     node = NodeFactory()
     ver1 = NodeWikiPage(page_name='foo', node=node)
     ver2 = NodeWikiPage(page_name='foo', node=node)
     ver1.save()
     ver2.save()
     node.wiki_pages_current['foo'] = ver2._id
     node.wiki_pages_versions['foo'] = [ver1._id, ver2._id]
     node.save()
     assert ver1.is_current is False
     assert ver2.is_current is True
 def test_affiliated_component_without_affiliated_parent_returned(self, app, user, institution, public_node, institution_node_url):
     # version 2.2
     node = ProjectFactory(is_public=True)
     component = NodeFactory(parent=node, is_public=True)
     component.affiliated_institutions.add(institution)
     component.save()
     url = '{}?version=2.2'.format(institution_node_url)
     res = app.get(url, auth=user.auth)
     affiliated_node_ids = [item['id'] for item in res.json['data']]
     assert res.status_code == 200
     assert node._id not in affiliated_node_ids
     assert component._id in affiliated_node_ids
Beispiel #19
0
    def test_serialize_node_for_logs(self):
        node = NodeFactory()
        d = node.serialize()

        assert_equal(d['id'], node._primary_key)
        assert_equal(d['category'], node.category_display)
        assert_equal(d['node_type'], node.project_or_component)
        assert_equal(d['url'], node.url)
        assert_equal(d['title'], node.title)
        assert_equal(d['api_url'], node.api_url)
        assert_equal(d['is_public'], node.is_public)
        assert_equal(d['is_registration'], node.is_registration)
    def test_user_does_not_have_node(self):
        node = NodeFactory()
        res = self.app.post_json_api(
            self.institution_nodes_url,
            self.create_payload(node._id),
            expect_errors=True,
            auth=self.user.auth
        )

        assert_equal(res.status_code, 403)
        node.reload()
        assert_not_in(self.institution, node.affiliated_institutions.all())
Beispiel #21
0
    def test_swapping_guids(self):
        user = UserFactory()
        node = NodeFactory()

        user_guid = user.guids[0]
        node_guid = node.guids[0]

        user._id = node_guid._id
        node._id = user_guid._id

        assert node_guid._id == user._id
        assert user_guid._id == node._id
Beispiel #22
0
 def component_public(self, user_two, project_public):
     component_public = NodeFactory(
         parent=project_public,
         title='Ultralight Beam',
         creator=user_two,
         is_public=True)
     component_public.set_description(
         'This is my part, nobody else speak',
         auth=Auth(user_two),
         save=True)
     component_public.add_tag('trumpets', auth=Auth(user_two), save=True)
     return component_public
Beispiel #23
0
    def test_new_draft_registration_POST(self):
        target = NodeFactory(creator=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)
        assert_equal(res.status_code, http.FOUND)
        target.reload()
        draft = DraftRegistration.objects.get(branched_from=target)
        assert_equal(draft.registration_schema, self.meta_schema)
    def test_user_is_admin_but_not_affiliated(
            self, app, url_institution_nodes, institution):
        user = AuthUserFactory()
        node = NodeFactory(creator=user)
        res = app.post_json_api(
            url_institution_nodes,
            make_payload(node._id),
            expect_errors=True, auth=user.auth
        )

        assert res.status_code == 403
        node.reload()
        assert institution not in node.affiliated_institutions.all()
    def test_user_is_admin_but_not_affiliated(self):
        user = AuthUserFactory()
        node = NodeFactory(creator=user)
        res = self.app.post_json_api(
            self.institution_nodes_url,
            self.create_payload(node._id),
            expect_errors=True,
            auth=user.auth
        )

        assert_equal(res.status_code, 403)
        node.reload()
        assert_not_in(self.institution, node.affiliated_institutions.all())
 def child_node_one(
         self, user, parent_project,
         institution, parent_project_one
 ):
     child_node_one = NodeFactory(
         parent=parent_project,
         title='Friend of {}'.format(
             parent_project_one._id),
         creator=user,
         is_public=True)
     child_node_one.affiliated_institutions.add(institution)
     child_node_one.save()
     return child_node_one
    def test_user_with_nodes_and_permissions(self):
        node = NodeFactory(creator=self.user)
        res = self.app.post_json_api(
            self.institution_nodes_url,
            self.create_payload(node._id),
            auth=self.user.auth
        )

        assert_equal(res.status_code, 201)
        node_ids = [node_['id'] for node_ in res.json['data']]
        assert_in(node._id, node_ids)

        node.reload()
        assert_in(self.institution, node.affiliated_institutions.all())
    def test_only_add_existent_with_permissions(self):
        node = NodeFactory(creator=self.user)
        node.affiliated_institutions.add(self.institution)
        node.save()
        assert_in(self.institution, self.node1.affiliated_institutions.all())
        assert_in(self.institution, node.affiliated_institutions.all())

        res = self.app.post_json_api(
            self.institution_nodes_url,
            self.create_payload(node._id, self.node1._id),
            auth=self.user.auth
        )

        assert_equal(res.status_code, 204)
Beispiel #29
0
 def setUp(self):
     super(TestNodeLinkedNodes, self).setUp()
     self.user = AuthUserFactory()
     self.auth = Auth(self.user)
     self.linking_node = 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.add_pointer(self.linked_node, auth=self.auth)
     self.linking_node.add_pointer(self.linked_node2, auth=self.auth)
     self.linking_node.add_pointer(self.public_node, auth=self.auth)
     self.linking_node.save()
     self.url = '/{}nodes/{}/linked_nodes/'.format(API_BASE, self.linking_node._id)
     self.node_ids = self.linking_node.linked_nodes.values_list('guids___id', flat=True)
    def test_add_some_existant_others_not(self):
        assert_in(self.institution, self.node1.affiliated_institutions.all())

        node = NodeFactory(creator=self.user)
        res = self.app.post_json_api(
            self.institution_nodes_url,
            self.create_payload(node._id, self.node1._id),
            auth=self.user.auth
        )

        assert_equal(res.status_code, 201)
        node.reload()
        self.node1.reload()
        assert_in(self.institution, self.node1.affiliated_institutions.all())
        assert_in(self.institution, node.affiliated_institutions.all())
Beispiel #31
0
 def node_two(self, user):
     return NodeFactory(creator=user)
 def node_private(self, user):
     return NodeFactory(title='Classified', creator=user)
 def node_one(self, user):
     return NodeFactory(title='Ismael Lo: Tajabone', creator=user, is_public=True)
Beispiel #34
0
 def other_node(self):
     return NodeFactory()
 def node_with_file(self):
     node = NodeFactory()
     file = create_test_file(node, node.creator)
     file.save()
     node.save()
     return node
Beispiel #36
0
 def child_node_one(self, user, parent_project, parent_project_one):
     return NodeFactory(parent=parent_project,
                        title='Friend of {}'.format(parent_project_one._id),
                        creator=user)
Beispiel #37
0
 def public_node(self, user):
     return NodeFactory(is_public=True, creator=user)
Beispiel #38
0
 def project(self, submitter):
     return NodeFactory(creator=submitter)
    def test_node_serializer(self, user):

        #   test_node_serialization
        parent = ProjectFactory(creator=user)
        node = NodeFactory(creator=user, parent=parent)
        req = make_drf_request_with_version(version='2.0')
        result = NodeSerializer(node, context={'request': req}).data
        data = result['data']
        assert data['id'] == node._id
        assert data['type'] == 'nodes'

        # Attributes
        attributes = data['attributes']
        assert attributes['title'] == node.title
        assert attributes['description'] == node.description
        assert attributes['public'] == node.is_public
        assert attributes['tags'] == [
            str(each.name) for each in node.tags.all()
        ]
        assert attributes['current_user_can_comment'] == False
        assert attributes['category'] == node.category
        assert attributes['registration'] == node.is_registration
        assert attributes['fork'] == node.is_fork
        assert attributes['collection'] == node.is_collection

        # Relationships
        relationships = data['relationships']
        assert 'children' in relationships
        assert 'contributors' in relationships
        assert 'files' in relationships
        assert 'parent' in relationships
        assert 'affiliated_institutions' in relationships
        assert 'registrations' in relationships
        # Not a fork, so forked_from is removed entirely
        assert 'forked_from' not in relationships
        parent_link = relationships['parent']['links']['related']['href']
        assert urlparse(parent_link).path == '/{}nodes/{}/'.format(
            API_BASE, parent._id)

        #   test_fork_serialization
        node = NodeFactory(creator=user)
        fork = node.fork_node(auth=Auth(user))
        req = make_drf_request_with_version(version='2.0')
        result = NodeSerializer(fork, context={'request': req}).data
        data = result['data']

        # Relationships
        relationships = data['relationships']
        forked_from = relationships['forked_from']['links']['related']['href']
        assert urlparse(forked_from).path == '/{}nodes/{}/'.format(
            API_BASE, node._id)

        #   test_template_serialization
        node = NodeFactory(creator=user)
        fork = node.use_as_template(auth=Auth(user))
        req = make_drf_request_with_version(version='2.0')
        result = NodeSerializer(fork, context={'request': req}).data
        data = result['data']

        # Relationships
        relationships = data['relationships']
        templated_from = relationships['template_node']['links']['related'][
            'href']
        assert urlparse(templated_from).path == '/{}nodes/{}/'.format(
            API_BASE, node._id)
Beispiel #40
0
 def project_two(self):
     return NodeFactory()
 def resource(self, user):
     return NodeFactory(creator=user, is_public=True)
Beispiel #42
0
class TestComponents(OsfTestCase):
    def setUp(self):
        super(TestComponents, self).setUp()
        self.user = AuthUserFactory()
        self.consolidate_auth = Auth(user=self.user)
        self.project = ProjectFactory(creator=self.user)
        self.project.add_contributor(contributor=self.user,
                                     auth=self.consolidate_auth)
        # A non-project componenet
        self.component = NodeFactory(
            category='hypothesis',
            creator=self.user,
            parent=self.project,
        )
        self.component.save()
        self.component.set_privacy('public', self.consolidate_auth)
        self.component.set_privacy('private', self.consolidate_auth)
        self.project.save()
        self.project_url = self.project.web_url_for('view_project')

    def test_sees_parent(self):
        res = self.app.get(self.component.url,
                           auth=self.user.auth).maybe_follow()
        parent_title = res.html.find_all('h2', class_='node-parent-title')
        assert_equal(len(parent_title), 1)
        assert_in(self.project.title,
                  parent_title[0].text)  # Bs4 will handle unescaping HTML here

    def test_delete_project(self):
        res = self.app.get(self.component.url + 'settings/',
                           auth=self.user.auth).maybe_follow()
        assert_in('Delete {0}'.format(self.component.project_or_component),
                  res)

    def test_cant_delete_project_if_not_admin(self):
        non_admin = AuthUserFactory()
        self.component.add_contributor(
            non_admin,
            permissions=['read', 'write'],
            auth=self.consolidate_auth,
            save=True,
        )
        res = self.app.get(self.component.url + 'settings/',
                           auth=non_admin.auth).maybe_follow()
        assert_not_in('Delete {0}'.format(self.component.project_or_component),
                      res)

    def test_can_configure_comments_if_admin(self):
        res = self.app.get(
            self.component.url + 'settings/',
            auth=self.user.auth,
        ).maybe_follow()
        assert_in('Commenting', res)

    def test_cant_configure_comments_if_not_admin(self):
        non_admin = AuthUserFactory()
        self.component.add_contributor(
            non_admin,
            permissions=['read', 'write'],
            auth=self.consolidate_auth,
            save=True,
        )
        res = self.app.get(self.component.url + 'settings/',
                           auth=non_admin.auth).maybe_follow()
        assert_not_in('Commenting', res)

    def test_components_should_have_component_list(self):
        res = self.app.get(self.component.url, auth=self.user.auth)
        assert_in('Components', res)
Beispiel #43
0
 def contributor_node(self, user, contributor):
     contributor_node = NodeFactory(creator=contributor)
     contributor_node.add_contributor(user, auth=Auth(contributor))
     contributor_node.save()
     return contributor_node
Beispiel #44
0
 def child_node_two(self, user, parent_project):
     return NodeFactory(parent=parent_project,
                        title='Lait Cafe au Choco',
                        creator=user)
Beispiel #45
0
 def public_node(self):
     return NodeFactory(is_public=True)
Beispiel #46
0
 def grandchild_node_one(self, user, child_node_one):
     return NodeFactory(parent=child_node_one, creator=user)
Beispiel #47
0
 def private_node_two(self, user):
     return NodeFactory(creator=user)
Beispiel #48
0
 def great_grandchild_node_two(self, user, grandchild_node_two):
     return NodeFactory(parent=grandchild_node_two, creator=user)
Beispiel #49
0
 def admin_node(self, user):
     return NodeFactory(creator=user)
Beispiel #50
0
 def node_admin(self, user):
     return NodeFactory(creator=user)
 def node(self, greg):
     return NodeFactory(creator=greg)
Beispiel #52
0
 def node_contrib(self, user, user_two):
     node_contrib = NodeFactory(creator=user_two)
     node_contrib.add_contributor(user, auth=Auth(user_two))
     node_contrib.save()
     return node_contrib
 def node_two(self, user):
     return NodeFactory(title='Sambolera', creator=user, is_public=True)
Beispiel #54
0
 def node_other(self):
     return NodeFactory()
 def component_private(self, user_one, project_public):
     return NodeFactory(
         parent=project_public,
         description='',
         title='Wavves',
         creator=user_one)
Beispiel #56
0
 def node_private(self, user):
     return NodeFactory(creator=user)
Beispiel #57
0
 def node_one(self, institution):
     node_one = NodeFactory(is_public=True)
     node_one.affiliated_institutions.add(institution)
     node_one.save()
     return node_one
Beispiel #58
0
 def linking_node_source(self, user, auth, private_node, admin_node):
     linking_node_source = NodeFactory(creator=user)
     linking_node_source.add_pointer(private_node, auth=auth)
     linking_node_source.add_pointer(admin_node, auth=auth)
     return linking_node_source
Beispiel #59
0
 def setUp(self):
     super(TestResolveGuid, self).setUp()
     self.node = NodeFactory()
Beispiel #60
0
class TestResolveGuid(OsfTestCase):

    def setUp(self):
        super(TestResolveGuid, self).setUp()
        self.node = NodeFactory()

    def test_resolve_guid(self):
        res_guid = self.app.get(self.node.web_url_for('node_setting', _guid=True), auth=self.node.creator.auth)
        res_full = self.app.get(self.node.web_url_for('node_setting'), auth=self.node.creator.auth)
        assert res_guid.text == res_full.text

    def test_resolve_guid_no_referent(self):
        guid = Guid.load(self.node._id)
        guid.referent = None
        guid.save()
        res = self.app.get(
            self.node.web_url_for('node_setting', _guid=True),
            auth=self.node.creator.auth,
            expect_errors=True,
        )
        assert res.status_code == 404

    @mock.patch('osf.models.node.Node.deep_url', None)
    def test_resolve_guid_no_url(self):
        res = self.app.get(
            self.node.web_url_for('node_setting', _guid=True),
            auth=self.node.creator.auth,
            expect_errors=True,
        )
        assert res.status_code == 404

    def test_resolve_guid_download_file(self):
        pp = PreprintFactory(finish=True)

        res = self.app.get(pp.url + 'download')
        assert res.status_code == 302
        assert '{}/v1/resources/{}/providers/{}{}?action=download&version=1&direct'.format(WATERBUTLER_URL, pp._id, pp.primary_file.provider, pp.primary_file.path) in res.location

        res = self.app.get(pp.url + 'download/')
        assert res.status_code == 302
        assert '{}/v1/resources/{}/providers/{}{}?action=download&version=1&direct'.format(WATERBUTLER_URL, pp._id, pp.primary_file.provider, pp.primary_file.path) in res.location

        res = self.app.get('/{}/download'.format(pp.primary_file.get_guid(create=True)._id))
        assert res.status_code == 302
        assert '{}/v1/resources/{}/providers/{}{}?action=download&version=1&direct'.format(WATERBUTLER_URL, pp._id, pp.primary_file.provider, pp.primary_file.path) in res.location

        pp.primary_file.create_version(
            creator=pp.creator,
            location={u'folder': u'osf', u'object': u'deadbe', u'service': u'cloud'},
            metadata={u'contentType': u'img/png', u'size': 9001}
        )
        pp.primary_file.save()

        res = self.app.get(pp.url + 'download/')
        assert res.status_code == 302
        assert '{}/v1/resources/{}/providers/{}{}?action=download&version=2&direct'.format(WATERBUTLER_URL, pp._id, pp.primary_file.provider, pp.primary_file.path) in res.location

        res = self.app.get(pp.url + 'download/?version=1')
        assert res.status_code == 302
        assert '{}/v1/resources/{}/providers/{}{}?action=download&version=1&direct'.format(WATERBUTLER_URL, pp._id, pp.primary_file.provider, pp.primary_file.path) in res.location

        unpub_pp = PreprintFactory(project=self.node, is_published=False)
        res = self.app.get(unpub_pp.url + 'download/?version=1', auth=unpub_pp.creator.auth)
        assert res.status_code == 302
        assert '{}/v1/resources/{}/providers/{}{}?action=download&version=1&direct'.format(WATERBUTLER_URL, unpub_pp._id, unpub_pp.primary_file.provider, unpub_pp.primary_file.path) in res.location

    @mock.patch('website.settings.USE_EXTERNAL_EMBER', True)
    @mock.patch('website.settings.EXTERNAL_EMBER_APPS', {
        'preprints': {
            'server': 'http://*****:*****@mock.patch('website.settings.USE_EXTERNAL_EMBER', True)
    @mock.patch('website.settings.EXTERNAL_EMBER_APPS', {
        'preprints': {
            'server': 'http://localhost:4200',
            'path': '/preprints/'
        },
    })
    def test_resolve_guid_download_file_from_emberapp_preprints_unpublished(self):
        # non-branded domains
        provider = PreprintProviderFactory(_id='sockarxiv', name='Sockarxiv', reviews_workflow='pre-moderation')

        # branded domains
        branded_provider = PreprintProviderFactory(_id='spot', name='Spotarxiv', reviews_workflow='pre-moderation')
        branded_provider.allow_submissions = False
        branded_provider.domain = 'https://www.spotarxiv.com'
        branded_provider.description = 'spots not dots'
        branded_provider.domain_redirect_enabled = True
        branded_provider.share_publish_type = 'Thesis'
        branded_provider.save()

        # test_provider_submitter_can_download_unpublished
        submitter = AuthUserFactory()
        pp = PreprintFactory(finish=True, provider=provider, is_published=False, creator=submitter)
        pp.run_submit(submitter)
        pp_branded = PreprintFactory(finish=True, provider=branded_provider, is_published=False, filename='preprint_file_two.txt', creator=submitter)
        pp_branded.run_submit(submitter)

        res = self.app.get('{}download'.format(pp.url), auth=submitter.auth)
        assert res.status_code == 302
        assert '{}/v1/resources/{}/providers/{}{}?action=download&version=1&direct'.format(WATERBUTLER_URL, pp._id, pp.primary_file.provider, pp.primary_file.path) in res.location

        res = self.app.get('{}download'.format(pp_branded.url), auth=submitter.auth)
        assert res.status_code == 302

        # test_provider_super_user_can_download_unpublished
        super_user = AuthUserFactory()
        super_user.is_superuser = True
        super_user.save()

        res = self.app.get('{}download'.format(pp.url), auth=super_user.auth)
        assert res.status_code == 302
        assert '{}/v1/resources/{}/providers/{}{}?action=download&version=1&direct'.format(WATERBUTLER_URL, pp._id, pp.primary_file.provider, pp.primary_file.path) in res.location

        res = self.app.get('{}download'.format(pp_branded.url), auth=super_user.auth)
        assert res.status_code == 302

        # test_provider_moderator_can_download_unpublished
        moderator = AuthUserFactory()
        provider.add_to_group(moderator, 'moderator')
        provider.save()

        res = self.app.get('{}download'.format(pp.url), auth=moderator.auth)
        assert res.status_code == 302
        assert '{}/v1/resources/{}/providers/{}{}?action=download&version=1&direct'.format(WATERBUTLER_URL, pp._id, pp.primary_file.provider, pp.primary_file.path) in res.location

        branded_provider.add_to_group(moderator, 'moderator')
        branded_provider.save()

        res = self.app.get('{}download'.format(pp_branded.url), auth=moderator.auth)
        assert res.status_code == 302

        # test_provider_admin_can_download_unpublished
        admin = AuthUserFactory()
        provider.add_to_group(admin, ADMIN)
        provider.save()

        res = self.app.get('{}download'.format(pp.url), auth=admin.auth)
        assert res.status_code == 302
        assert '{}/v1/resources/{}/providers/{}{}?action=download&version=1&direct'.format(WATERBUTLER_URL, pp._id, pp.primary_file.provider, pp.primary_file.path) in res.location

        branded_provider.add_to_group(admin, ADMIN)
        branded_provider.save()

        res = self.app.get('{}download'.format(pp_branded.url), auth=admin.auth)
        assert res.status_code == 302

    def test_resolve_guid_download_file_export(self):
        pp = PreprintFactory(finish=True)

        res = self.app.get(pp.url + 'download?format=asdf')
        assert res.status_code == 302
        assert '{}/export?format=asdf&url='.format(MFR_SERVER_URL) in res.location
        assert '{}/v1/resources/{}/providers/{}{}%3Faction%3Ddownload'.format(quote(WATERBUTLER_URL), pp._id, pp.primary_file.provider, pp.primary_file.path) in res.location

        res = self.app.get(pp.url + 'download/?format=asdf')
        assert res.status_code == 302
        assert '{}/export?format=asdf&url='.format(MFR_SERVER_URL) in res.location
        assert '{}/v1/resources/{}/providers/{}{}%3Faction%3Ddownload'.format(quote(WATERBUTLER_URL), pp._id, pp.primary_file.provider, pp.primary_file.path) in res.location

        res = self.app.get('/{}/download?format=asdf'.format(pp.primary_file.get_guid(create=True)._id))
        assert res.status_code == 302
        assert '{}/export?format=asdf&url='.format(MFR_SERVER_URL) in res.location
        assert '{}/v1/resources/{}/providers/{}{}%3Faction%3Ddownload'.format(quote(WATERBUTLER_URL), pp._id, pp.primary_file.provider, pp.primary_file.path) in res.location

        res = self.app.get('/{}/download/?format=asdf'.format(pp.primary_file.get_guid(create=True)._id))
        assert res.status_code == 302
        assert '{}/export?format=asdf&url='.format(MFR_SERVER_URL) in res.location
        assert '{}/v1/resources/{}/providers/{}{}%3Faction%3Ddownload'.format(quote(WATERBUTLER_URL), pp._id, pp.primary_file.provider, pp.primary_file.path) in res.location

        pp.primary_file.create_version(
            creator=pp.creator,
            location={u'folder': u'osf', u'object': u'deadbe', u'service': u'cloud'},
            metadata={u'contentType': u'img/png', u'size': 9001}
        )
        pp.primary_file.save()

        res = self.app.get(pp.url + 'download/?format=asdf')
        assert res.status_code == 302
        assert '{}/export?format=asdf&url='.format(MFR_SERVER_URL) in res.location
        assert '{}/v1/resources/{}/providers/{}{}%3F'.format(quote(WATERBUTLER_URL), pp._id, pp.primary_file.provider, pp.primary_file.path) in res.location
        quarams = res.location.split('%3F')[1].split('%26')
        assert 'action%3Ddownload' in quarams
        assert 'version%3D2' in quarams
        assert 'direct' in quarams

        res = self.app.get(pp.url + 'download/?format=asdf&version=1')
        assert res.status_code == 302
        assert '{}/export?format=asdf&url='.format(MFR_SERVER_URL) in res.location
        assert '{}/v1/resources/{}/providers/{}{}%3F'.format(quote(WATERBUTLER_URL), pp._id, pp.primary_file.provider, pp.primary_file.path) in res.location
        quarams = res.location.split('%3F')[1].split('%26')
        assert 'action%3Ddownload' in quarams
        assert 'version%3D1' in quarams
        assert 'direct' in quarams

        unpub_pp = PreprintFactory(project=self.node, is_published=False)
        res = self.app.get(unpub_pp.url + 'download?format=asdf', auth=unpub_pp.creator.auth)
        assert res.status_code == 302
        assert res.status_code == 302
        assert '{}/export?format=asdf&url='.format(MFR_SERVER_URL) in res.location
        assert '{}/v1/resources/{}/providers/{}{}%3F'.format(quote(WATERBUTLER_URL), unpub_pp._id, unpub_pp.primary_file.provider, unpub_pp.primary_file.path) in res.location
        quarams = res.location.split('%3F')[1].split('%26')
        assert 'action%3Ddownload' in quarams
        assert 'version%3D1' in quarams
        assert 'direct' in quarams

    def test_resolve_guid_download_file_export_same_format_optimization(self):
        pp = PreprintFactory(filename='test.pdf', finish=True)

        res = self.app.get(pp.url + 'download/?format=pdf')
        assert res.status_code == 302
        assert '{}/export?'.format(MFR_SERVER_URL) not in res.location
        assert '{}/v1/resources/{}/providers/{}{}?action=download&version=1&direct'.format(WATERBUTLER_URL, pp._id, pp.primary_file.provider, pp.primary_file.path) in res.location

    def test_resolve_guid_download_errors(self):
        testfile = TestFile.get_or_create(self.node, 'folder/path')
        testfile.name = 'asdf'
        testfile.materialized_path = '/folder/path'
        guid = testfile.get_guid(create=True)
        testfile.save()
        testfile.delete()
        res = self.app.get('/{}/download'.format(guid), expect_errors=True)
        assert res.status_code == 404

        pp = PreprintFactory(is_published=False)

        res = self.app.get(pp.url + 'download', expect_errors=True)
        assert res.status_code == 404

        pp.is_published = True
        pp.save()
        pp.is_public = False
        pp.save()

        non_contrib = AuthUserFactory()

        res = self.app.get(pp.url + 'download', auth=non_contrib.auth, expect_errors=True)
        assert res.status_code == 403

        pp.deleted = timezone.now()
        pp.save()

        res = self.app.get(pp.url + 'download', auth=non_contrib.auth, expect_errors=True)
        assert res.status_code == 410