Пример #1
0
 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)
Пример #2
0
    def test_private_components_shown(self):
        user = UserFactory()
        public_project = ProjectFactory(creator=user, is_public=True)
        private_child = NodeFactory(parent=public_project,
                                    creator=user,
                                    is_public=False)
        public_grandchild = NodeFactory(parent=private_child,
                                        creator=user,
                                        is_public=True)

        serializer = rubeus.NodeFileCollector(node=public_project,
                                              auth=Auth(user))
        ret = serializer.to_hgrid()

        children = ret[0]['children']

        assert 'osfstorage' == children[0]['provider']

        assert private_child._id == children[1]['nodeID']
        assert private_child.title == children[1]['name']
        assert True == children[1]['permissions']['edit']

        assert public_grandchild._id == children[1]['children'][1]['nodeID']
        assert public_grandchild.title == children[1]['children'][1]['name']
        assert True == children[1]['children'][1]['permissions']['edit']

        assert 'Private Component' not in ret
Пример #3
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)
Пример #4
0
 def setUp(self):
     super(TestSerializingNodeWithAddon, self).setUp()
     self.auth = AuthFactory()
     self.project = ProjectFactory(creator=self.auth.user)
     self.project.get_addons = mock.Mock()
     self.project.get_addons.return_value = [mock_addon]
     self.serializer = rubeus.NodeFileCollector(node=self.project, auth=self.auth)
Пример #5
0
 def test_serialized_pointer_has_flag_indicating_its_a_pointer(self):
     project = ProjectFactory(creator=self.consolidated_auth.user)
     pointed_project = ProjectFactory(is_public=True)
     project.add_pointer(pointed_project, auth=self.consolidated_auth)
     serializer = rubeus.NodeFileCollector(node=project, auth=self.consolidated_auth)
     ret = serializer._serialize_node(project)
     child = ret['children'][1]  # first child is OSFStorage, second child is pointer
     assert_true(child['isPointer'])
Пример #6
0
    def test_serialize_private_node(self):
        user = UserFactory()
        auth = Auth(user=user)
        public = ProjectFactory.build(is_public=True)
        public.add_contributor(user)
        public.save()
        private = ProjectFactory(project=public, is_public=False)
        NodeFactory(project=private)
        collector = rubeus.NodeFileCollector(node=public, auth=auth)

        private_dummy = collector._serialize_node(private)
        assert_false(private_dummy['permissions']['edit'])
        assert_false(private_dummy['permissions']['view'])
        assert_equal(private_dummy['name'], 'Private Component')
        assert_equal(len(private_dummy['children']), 0)
Пример #7
0
    def test_serialize_private_node(self):
        user = UserFactory()
        auth = Auth(user=user)
        public = ProjectFactory.create(is_public=True)
        # Add contributor with write permissions to avoid admin permission cascade
        public.add_contributor(user, permissions=['read', 'write'])
        public.save()
        private = ProjectFactory(parent=public, is_public=False)
        NodeFactory(parent=private)
        collector = rubeus.NodeFileCollector(node=public, auth=auth)

        private_dummy = collector._serialize_node(private)
        assert_false(private_dummy['permissions']['edit'])
        assert_false(private_dummy['permissions']['view'])
        assert_equal(private_dummy['name'], 'Private Component')
        assert_equal(len(private_dummy['children']), 0)
Пример #8
0
    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')
Пример #9
0
 def test_serialized_pointer_has_flag_indicating_its_a_pointer(self):
     pointer = PointerFactory()
     serializer = rubeus.NodeFileCollector(node=pointer,
                                           auth=self.consolidated_auth)
     ret = serializer._serialize_node(pointer)
     assert_true(ret['isPointer'])