Ejemplo n.º 1
0
    def test_comments_move_when_file_moved_to_osfstorage(self, project, user):
        osfstorage = project.get_addon('osfstorage')
        root_node = osfstorage.get_root()
        osf_file = root_node.append_file('file.txt')
        osf_file.create_version(user, {
            'object': '06d80e',
            'service': 'cloud',
            osfstorage_settings.WATERBUTLER_RESOURCE: 'osf',
        }, {
            'size': 1337,
            'contentType': 'img/png',
            'etag': 'abcdefghijklmnop'
        }).save()

        source = {
            'path': '/file.txt',
            'node': project,
            'provider': self.provider
        }
        destination = {
            'path': osf_file.path,
            'node': project,
            'provider': 'osfstorage'
        }
        self._create_file_with_comment(node=source['node'], path=source['path'], user=user)
        payload = self._create_payload('move', user, source, destination, self.file._id, destination_file_id=destination['path'].strip('/'))
        update_file_guid_referent(self=None, node=destination['node'], event_type='addon_file_moved', payload=payload)
        self.guid.reload()

        file_node = BaseFileNode.resolve_class('osfstorage', BaseFileNode.FILE).get_or_create(destination['node'], destination['path'])
        assert self.guid._id == file_node.get_guid()._id
        file_comments = Comment.objects.filter(root_target=self.guid.pk)
        assert file_comments.count() == 1
Ejemplo n.º 2
0
    def test_comments_move_when_file_moved_to_different_provider(self, destination_provider, destination_path):
        if self.provider == destination_provider:
            return True

        self.project.add_addon(destination_provider, auth=Auth(self.user))
        self.project.save()
        self.addon_settings = self.project.get_addon(destination_provider)
        self.addon_settings.folder = '/AddonFolder'
        self.addon_settings.save()

        source = {
            'path': '/file.txt',
            'node': self.project,
            'provider': self.provider
        }
        destination = {
            'path': destination_path,
            'node': self.project,
            'provider': destination_provider
        }
        self._create_file_with_comment(node=source['node'], path=source['path'])
        payload = self._create_payload('move', self.user, source, destination, self.file._id)
        update_file_guid_referent(self=None, node=destination['node'], event_type='addon_file_moved', payload=payload)
        self.guid.reload()

        file_node = FileNode.resolve_class(destination_provider, FileNode.FILE).get_or_create(destination['node'], destination['path'])
        assert_equal(self.guid._id, file_node.get_guid()._id)
        file_comments = Comment.find(Q('root_target', 'eq', self.guid._id))
        assert_equal(file_comments.count(), 1)
Ejemplo n.º 3
0
    def test_comments_move_when_folder_moved_to_different_provider(self, destination_provider, destination_path):
        if self.provider == destination_provider:
            return True

        self.project.add_addon(destination_provider, auth=Auth(self.user))
        self.project.save()
        self.addon_settings = self.project.get_addon(destination_provider)
        self.addon_settings.folder = '/AddonFolder'
        self.addon_settings.save()

        source = {
            'path': '/subfolder/',
            'node': self.project,
            'provider': self.provider
        }
        destination = {
            'path': '/subfolder/',
            'node': self.project,
            'provider': destination_provider,
            'children': [{
                    'path': '/subfolder/file.txt',
                    'node': self.project,
                    'provider': destination_provider
            }]
        }
        file_name = 'file.txt'
        self._create_file_with_comment(node=source['node'], path='{}{}'.format(source['path'], file_name))
        payload = self._create_payload('move', self.user, source, destination, self.file._id)
        update_file_guid_referent(self=None, node=destination['node'], event_type='addon_file_moved', payload=payload)
        self.guid.reload()

        file_node = FileNode.resolve_class(destination_provider, FileNode.FILE).get_or_create(destination['node'], destination_path)
        assert_equal(self.guid._id, file_node.get_guid()._id)
        file_comments = Comment.find(Q('root_target', 'eq', self.guid._id))
        assert_equal(file_comments.count(), 1)
Ejemplo n.º 4
0
    def test_comments_move_when_folder_moved_to_different_provider(self, destination_provider, destination_path, project, user):
        if self.provider == destination_provider:
            return True

        project.add_addon(destination_provider, auth=Auth(user))
        project.save()
        self.addon_settings = project.get_addon(destination_provider)
        self.addon_settings.folder = '/AddonFolder'
        self.addon_settings.save()

        source = {
            'path': '/',
            'node': project,
            'provider': self.provider
        }
        destination = {
            'path': '/subfolder/',
            'node': project,
            'provider': destination_provider,
            'children': [{
                    'path': '/subfolder/file.txt',
                    'node': project,
                    'provider': destination_provider
            }]
        }
        file_name = 'file.txt'
        self._create_file_with_comment(node=source['node'], path='{}{}'.format(source['path'], file_name), user=user)
        payload = self._create_payload('move', user, source, destination, self.file._id)
        update_file_guid_referent(self=None, node=destination['node'], event_type='addon_file_moved', payload=payload)
        self.guid.reload()

        file_node = BaseFileNode.resolve_class(destination_provider, BaseFileNode.FILE).get_or_create(destination['node'], destination_path)
        assert self.guid._id == file_node.get_guid()._id
        file_comments = Comment.objects.filter(root_target=self.guid.pk)
        assert file_comments.count() == 1
Ejemplo n.º 5
0
    def test_comments_move_when_file_moved_to_osfstorage(self, project, user):
        osfstorage = project.get_addon('osfstorage')
        root_node = osfstorage.get_root()
        osf_file = root_node.append_file('file.txt')
        osf_file.create_version(user, {
            'object': '06d80e',
            'service': 'cloud',
            osfstorage_settings.WATERBUTLER_RESOURCE: 'osf',
        }, {
            'size': 1337,
            'contentType': 'img/png',
            'etag': 'abcdefghijklmnop'
        }).save()

        source = {
            'path': '/file.txt',
            'node': project,
            'provider': self.provider
        }
        destination = {
            'path': osf_file.path,
            'node': project,
            'provider': 'osfstorage'
        }
        self._create_file_with_comment(node=source['node'], path=source['path'], user=user)
        payload = self._create_payload('move', user, source, destination, self.file._id, destination_file_id=destination['path'].strip('/'))
        update_file_guid_referent(self=None, target=destination['node'], event_type='addon_file_moved', payload=payload)
        self.guid.reload()

        file_node = BaseFileNode.resolve_class('osfstorage', BaseFileNode.FILE).get_or_create(destination['node'], destination['path'])
        assert self.guid._id == file_node.get_guid()._id
        file_comments = Comment.objects.filter(root_target=self.guid.pk)
        assert file_comments.count() == 1
Ejemplo n.º 6
0
    def test_comments_move_when_folder_moved_to_different_provider(self, destination_provider, destination_path):
        if self.provider == destination_provider:
            return True

        self.project.add_addon(destination_provider, auth=Auth(self.user))
        self.project.save()
        self.addon_settings = self.project.get_addon(destination_provider)
        self.addon_settings.folder = "/AddonFolder"
        self.addon_settings.save()

        source = {"path": "/subfolder/", "node": self.project, "provider": self.provider}
        destination = {
            "path": "/subfolder/",
            "node": self.project,
            "provider": destination_provider,
            "children": [{"path": "/subfolder/file.txt", "node": self.project, "provider": destination_provider}],
        }
        file_name = "file.txt"
        self._create_file_with_comment(node=source["node"], path="{}{}".format(source["path"], file_name))
        payload = self._create_payload("move", self.user, source, destination, self.file._id)
        update_file_guid_referent(self=None, node=destination["node"], event_type="addon_file_moved", payload=payload)
        self.guid.reload()

        file_node = FileNode.resolve_class(destination_provider, FileNode.FILE).get_or_create(
            destination["node"], destination_path
        )
        assert_equal(self.guid._id, file_node.get_guid()._id)
        file_comments = Comment.find(Q("root_target", "eq", self.guid._id))
        assert_equal(file_comments.count(), 1)
Ejemplo n.º 7
0
    def test_comments_move_when_folder_moved_to_osfstorage(self):
        osfstorage = self.project.get_addon("osfstorage")
        root_node = osfstorage.get_root()
        osf_folder = root_node.append_folder("subfolder")
        osf_file = osf_folder.append_file("file.txt")
        osf_file.create_version(
            self.user,
            {"object": "06d80e", "service": "cloud", osfstorage_settings.WATERBUTLER_RESOURCE: "osf"},
            {"size": 1337, "contentType": "img/png", "etag": "1234567890abcde"},
        ).save()

        source = {"path": "/subfolder/", "node": self.project, "provider": self.provider}
        destination = {
            "path": "/subfolder/",
            "node": self.project,
            "provider": "osfstorage",
            "children": [{"path": "/subfolder/file.txt", "node": self.project, "provider": "osfstorage"}],
        }
        file_name = "file.txt"
        self._create_file_with_comment(node=source["node"], path="{}{}".format(source["path"], file_name))
        payload = self._create_payload(
            "move", self.user, source, destination, self.file._id, destination_file_id=osf_file._id
        )
        update_file_guid_referent(self=None, node=destination["node"], event_type="addon_file_moved", payload=payload)
        self.guid.reload()

        file_node = FileNode.resolve_class("osfstorage", FileNode.FILE).get_or_create(destination["node"], osf_file._id)
        assert_equal(self.guid._id, file_node.get_guid()._id)
        file_comments = Comment.find(Q("root_target", "eq", self.guid._id))
        assert_equal(file_comments.count(), 1)
Ejemplo n.º 8
0
    def test_comments_move_when_folder_moved_to_different_provider(self, destination_provider, destination_path, project, user):
        if self.provider == destination_provider:
            return True

        project.add_addon(destination_provider, auth=Auth(user))
        project.save()
        self.addon_settings = project.get_addon(destination_provider)
        self.addon_settings.folder = '/AddonFolder'
        self.addon_settings.save()

        source = {
            'path': '/',
            'node': project,
            'provider': self.provider
        }
        destination = {
            'path': '/subfolder/',
            'node': project,
            'provider': destination_provider,
            'children': [{
                    'path': '/subfolder/file.txt',
                    'node': project,
                    'provider': destination_provider
            }]
        }
        file_name = 'file.txt'
        self._create_file_with_comment(node=source['node'], path='{}{}'.format(source['path'], file_name), user=user)
        payload = self._create_payload('move', user, source, destination, self.file._id)
        update_file_guid_referent(self=None, target=destination['node'], event_type='addon_file_moved', payload=payload)
        self.guid.reload()

        file_node = BaseFileNode.resolve_class(destination_provider, BaseFileNode.FILE).get_or_create(destination['node'], destination_path)
        assert self.guid._id == file_node.get_guid()._id
        file_comments = Comment.objects.filter(root_target=self.guid.pk)
        assert file_comments.count() == 1
Ejemplo n.º 9
0
    def test_comments_move_when_file_moved_from_subfolder_to_root(self):
        source = {"path": "/subfolder/file.txt", "node": self.project, "provider": self.provider}
        destination = {"path": "/file.txt", "node": self.project, "provider": self.provider}
        self._create_file_with_comment(node=source["node"], path=source["path"])
        payload = self._create_payload("move", self.user, source, destination, self.file._id)
        update_file_guid_referent(self=None, node=destination["node"], event_type="addon_file_moved", payload=payload)
        self.guid.reload()

        file_node = FileNode.resolve_class(self.provider, FileNode.FILE).get_or_create(
            destination["node"], self._format_path(destination["path"], file_id=self.file._id)
        )
        assert_equal(self.guid._id, file_node.get_guid()._id)
        file_comments = Comment.find(Q("root_target", "eq", self.guid._id))
        assert_equal(file_comments.count(), 1)
Ejemplo n.º 10
0
 def test_comments_move_on_file_rename(self, project, user):
     source = {
         'path': '/file.txt',
         'node': project,
         'provider': self.provider
     }
     destination = {
         'path': '/file_renamed.txt',
         'node': project,
         'provider': self.provider
     }
     self._create_file_with_comment(node=source['node'], path=source['path'], user=user)
     payload = self._create_payload('move', user, source, destination, self.file._id)
     update_file_guid_referent(self=None, node=destination['node'], event_type='addon_file_renamed', payload=payload)
     self.guid.reload()
     file_node = BaseFileNode.resolve_class(self.provider, BaseFileNode.FILE).get_or_create(destination['node'], self._format_path(destination['path'], file_id=self.file._id))
     assert self.guid._id == file_node.get_guid()._id
     file_comments = Comment.objects.filter(root_target=self.guid.pk)
     assert file_comments.count() == 1
Ejemplo n.º 11
0
 def test_comments_move_on_file_rename(self, project, user):
     source = {
         'path': '/file.txt',
         'node': project,
         'provider': self.provider
     }
     destination = {
         'path': '/file_renamed.txt',
         'node': project,
         'provider': self.provider
     }
     self._create_file_with_comment(node=source['node'], path=source['path'], user=user)
     payload = self._create_payload('move', user, source, destination, self.file._id)
     update_file_guid_referent(self=None, target=destination['node'], event_type='addon_file_renamed', payload=payload)
     self.guid.reload()
     file_node = BaseFileNode.resolve_class(self.provider, BaseFileNode.FILE).get_or_create(destination['node'], self._format_path(destination['path'], file_id=self.file._id))
     assert self.guid._id == file_node.get_guid()._id
     file_comments = Comment.objects.filter(root_target=self.guid.pk)
     assert file_comments.count() == 1
Ejemplo n.º 12
0
    def test_comments_move_when_file_moved_from_subfolder_to_root(self):
        source = {
            'path': '/subfolder/file.txt',
            'node': self.project,
            'provider': self.provider
        }
        destination = {
            'path': '/file.txt',
            'node': self.project,
            'provider': self.provider
        }
        self._create_file_with_comment(node=source['node'], path=source['path'])
        payload = self._create_payload('move', self.user, source, destination, self.file._id)
        update_file_guid_referent(self=None, node=destination['node'], event_type='addon_file_moved', payload=payload)
        self.guid.reload()

        file_node = FileNode.resolve_class(self.provider, FileNode.FILE).get_or_create(destination['node'], self._format_path(destination['path'], file_id=self.file._id))
        assert_equal(self.guid._id, file_node.get_guid()._id)
        file_comments = Comment.find(Q('root_target', 'eq', self.guid._id))
        assert_equal(file_comments.count(), 1)
Ejemplo n.º 13
0
    def test_comments_move_when_file_moved_from_subfolder_to_root(self):
        source = {
            'path': '/subfolder/file.txt',
            'node': self.project,
            'provider': self.provider
        }
        destination = {
            'path': '/file.txt',
            'node': self.project,
            'provider': self.provider
        }
        self._create_file_with_comment(node=source['node'], path=source['path'])
        payload = self._create_payload('move', self.user, source, destination, self.file._id)
        update_file_guid_referent(self=None, node=destination['node'], event_type='addon_file_moved', payload=payload)
        self.guid.reload()

        file_node = FileNode.resolve_class(self.provider, FileNode.FILE).get_or_create(destination['node'], self._format_path(destination['path'], file_id=self.file._id))
        assert_equal(self.guid._id, file_node.get_guid()._id)
        file_comments = Comment.find(Q('root_target', 'eq', self.guid._id))
        assert_equal(file_comments.count(), 1)
Ejemplo n.º 14
0
    def test_comments_move_when_folder_moved_from_component_to_project(self, project, component, user):
        source = {
            'path': '/subfolder/',
            'node': component,
            'provider': self.provider
        }
        destination = {
            'path': '/subfolder/',
            'node': project,
            'provider': self.provider
        }
        file_name = 'file.txt'
        self._create_file_with_comment(node=source['node'], path='{}{}'.format(source['path'], file_name), user=user)
        payload = self._create_payload('move', user, source, destination, self.file._id)
        update_file_guid_referent(self=None, target=destination['node'], event_type='addon_file_moved', payload=payload)
        self.guid.reload()

        file_node = BaseFileNode.resolve_class(self.provider, BaseFileNode.FILE).get_or_create(destination['node'], self._format_path('{}{}'.format(destination['path'], file_name), file_id=self.file._id))
        assert self.guid._id == file_node.get_guid()._id
        file_comments = Comment.objects.filter(root_target=self.guid.pk)
        assert file_comments.count() == 1
Ejemplo n.º 15
0
    def test_comments_move_on_subfolder_file_when_parent_folder_is_renamed(self, project, user):
        source = {
            'path': '/subfolder1/',
            'node': project,
            'provider': self.provider
        }
        destination = {
            'path': '/subfolder2/',
            'node': project,
            'provider': self.provider
        }
        file_path = 'sub-subfolder/file.txt'
        self._create_file_with_comment(node=source['node'], path='{}{}'.format(source['path'], file_path), user=user)
        payload = self._create_payload('move', user, source, destination, self.file._id)
        update_file_guid_referent(self=None, node=destination['node'], event_type='addon_file_renamed', payload=payload)
        self.guid.reload()

        file_node = BaseFileNode.resolve_class(self.provider, BaseFileNode.FILE).get_or_create(destination['node'], self._format_path('{}{}'.format(destination['path'], file_path), file_id=self.file._id))
        assert self.guid._id == file_node.get_guid()._id
        file_comments = Comment.find(Q('root_target', 'eq', self.guid.pk))
        assert file_comments.count() == 1
Ejemplo n.º 16
0
    def test_comments_move_when_folder_moved_from_component_to_project(self, project, component, user):
        source = {
            'path': '/subfolder/',
            'node': component,
            'provider': self.provider
        }
        destination = {
            'path': '/subfolder/',
            'node': project,
            'provider': self.provider
        }
        file_name = 'file.txt'
        self._create_file_with_comment(node=source['node'], path='{}{}'.format(source['path'], file_name), user=user)
        payload = self._create_payload('move', user, source, destination, self.file._id)
        update_file_guid_referent(self=None, node=destination['node'], event_type='addon_file_moved', payload=payload)
        self.guid.reload()

        file_node = BaseFileNode.resolve_class(self.provider, BaseFileNode.FILE).get_or_create(destination['node'], self._format_path('{}{}'.format(destination['path'], file_name), file_id=self.file._id))
        assert self.guid._id == file_node.get_guid()._id
        file_comments = Comment.objects.filter(root_target=self.guid.pk)
        assert file_comments.count() == 1
Ejemplo n.º 17
0
    def test_comments_move_when_folder_moved_to_osfstorage(self):
        osfstorage = self.project.get_addon('osfstorage')
        root_node = osfstorage.get_root()
        osf_folder = root_node.append_folder('subfolder')
        osf_file = osf_folder.append_file('file.txt')
        osf_file.create_version(self.user, {
            'object': '06d80e',
            'service': 'cloud',
            osfstorage_settings.WATERBUTLER_RESOURCE: 'osf',
        }, {
            'size': 1337,
            'contentType': 'img/png',
            'etag': '1234567890abcde'
        }).save()

        source = {
            'path': '/subfolder/',
            'node': self.project,
            'provider': self.provider
        }
        destination = {
            'path': '/subfolder/',
            'node': self.project,
            'provider': 'osfstorage',
            'children': [{
                'path': '/subfolder/file.txt',
                'node': self.project,
                'provider': 'osfstorage'
            }]
        }
        file_name = 'file.txt'
        self._create_file_with_comment(node=source['node'], path='{}{}'.format(source['path'], file_name))
        payload = self._create_payload('move', self.user, source, destination, self.file._id, destination_file_id=osf_file._id)
        update_file_guid_referent(self=None, node=destination['node'], event_type='addon_file_moved', payload=payload)
        self.guid.reload()

        file_node = FileNode.resolve_class('osfstorage', FileNode.FILE).get_or_create(destination['node'], osf_file._id)
        assert_equal(self.guid._id, file_node.get_guid()._id)
        file_comments = Comment.find(Q('root_target', 'eq', self.guid._id))
        assert_equal(file_comments.count(), 1)
Ejemplo n.º 18
0
    def test_comments_move_when_folder_moved_to_osfstorage(self):
        osfstorage = self.project.get_addon('osfstorage')
        root_node = osfstorage.get_root()
        osf_folder = root_node.append_folder('subfolder')
        osf_file = osf_folder.append_file('file.txt')
        osf_file.create_version(self.user, {
            'object': '06d80e',
            'service': 'cloud',
            osfstorage_settings.WATERBUTLER_RESOURCE: 'osf',
        }, {
            'size': 1337,
            'contentType': 'img/png',
            'etag': '1234567890abcde'
        }).save()

        source = {
            'path': '/subfolder/',
            'node': self.project,
            'provider': self.provider
        }
        destination = {
            'path': '/subfolder/',
            'node': self.project,
            'provider': 'osfstorage',
            'children': [{
                'path': '/subfolder/file.txt',
                'node': self.project,
                'provider': 'osfstorage'
            }]
        }
        file_name = 'file.txt'
        self._create_file_with_comment(node=source['node'], path='{}{}'.format(source['path'], file_name))
        payload = self._create_payload('move', self.user, source, destination, self.file._id, destination_file_id=osf_file._id)
        update_file_guid_referent(self=None, node=destination['node'], event_type='addon_file_moved', payload=payload)
        self.guid.reload()

        file_node = FileNode.resolve_class('osfstorage', FileNode.FILE).get_or_create(destination['node'], osf_file._id)
        assert_equal(self.guid._id, file_node.get_guid()._id)
        file_comments = Comment.find(Q('root_target', 'eq', self.guid._id))
        assert_equal(file_comments.count(), 1)
Ejemplo n.º 19
0
    def test_comments_move_when_file_moved_from_component_to_project(self, project, component, user):
        source = {
            'path': '/file.txt',
            'node': component,
            'provider': self.provider
        }
        destination = {
            'path': '/file.txt',
            'node': project,
            'provider': self.provider
        }
        self._create_file_with_comment(node=source['node'], path=source['path'], user=user)
        self.file.move_under(destination['node'].get_addon(self.provider).get_root())
        payload = self._create_payload('move', user, source, destination, self.file._id)
        update_file_guid_referent(self=None, node=destination['node'], event_type='addon_file_moved', payload=payload)
        self.guid.reload()

        file_node = BaseFileNode.resolve_class(self.provider, BaseFileNode.FILE).get_or_create(destination['node'], self._format_path(destination['path'], file_id=self.file._id))
        assert self.guid._id == file_node.get_guid()._id
        assert self.guid.referent.node._id == destination['node']._id
        file_comments = Comment.find(Q('root_target', 'eq', self.guid.pk))
        assert file_comments.count() == 1