Exemplo n.º 1
0
    def test_write_src_with_multi_files(self, mock_st_medium, mock_st_method,
                                        mock_st_obj, mock_copy):
        disk_storage_backend = DiskStorageBackend()
        mock_st_medium.storage_target.target = self.datadir
        mock_st_method.containers = True
        src_list = ["some_src", "some_src2", "some_src3"]

        disk_storage_backend.write(src=src_list,
                                   ip=mock.ANY,
                                   container=mock_st_method.containers,
                                   storage_medium=mock_st_medium)

        expected_dest = self.datadir
        expected_copy_calls = [
            mock.call(src, expected_dest, block_size=DEFAULT_BLOCK_SIZE)
            for src in src_list
        ]

        self.assertEqual(mock_copy.call_count, 3)
        mock_copy.assert_has_calls(expected_copy_calls)
        mock_st_obj.assert_called_once_with(
            container=True,
            content_location_type=DISK,
            content_location_value='bar.tar',
            ip=mock.ANY,
            storage_medium=mock_st_medium,
        )
Exemplo n.º 2
0
    def test_write_src_with_multi_files_not_container(self, mock_st_medium,
                                                      mock_st_method,
                                                      mock_st_obj, mock_copy):
        disk_storage_backend = DiskStorageBackend()
        mock_st_medium.storage_target.target = self.datadir
        mock_st_method.containers = False
        ip = InformationPackage.objects.create(
            object_identifier_value='objid', )
        src_list = ["some_src", "some_src2", "some_src3"]

        disk_storage_backend.write(src=src_list,
                                   ip=ip,
                                   container=mock_st_method.containers,
                                   storage_medium=mock_st_medium)

        expected_dest = os.path.join(self.datadir, "objid")
        expected_copy_calls = [
            mock.call(src, expected_dest, block_size=DEFAULT_BLOCK_SIZE)
            for src in src_list
        ]

        self.assertEqual(mock_copy.call_count, 3)
        mock_copy.assert_has_calls(expected_copy_calls)
        mock_st_obj.assert_called_once_with(
            container=False,
            content_location_type=DISK,
            content_location_value='objid',
            ip=mock.ANY,
            storage_medium=mock_st_medium,
        )
Exemplo n.º 3
0
    def test_write_dest_is_path_to_container(self, mock_st_medium,
                                             mock_st_method, mock_st_obj,
                                             mock_copy):
        disk_storage_backend = DiskStorageBackend()
        mock_st_medium.storage_target.target = self.datadir
        mock_st_method.containers = True

        disk_storage_backend.write(src="some_src",
                                   ip=mock.ANY,
                                   storage_method=mock_st_method,
                                   storage_medium=mock_st_medium)

        mock_copy.assert_called_once()
        mock_st_obj.assert_called_once()
Exemplo n.º 4
0
    def test_write_src_with_multi_files(self, mock_st_medium, mock_st_method,
                                        mock_st_obj, mock_copy):
        disk_storage_backend = DiskStorageBackend()
        mock_st_medium.storage_target.target = self.datadir
        mock_st_method.containers = True
        src_list = ["some_src", "some_src2", "some_src3"]

        disk_storage_backend.write(src=src_list,
                                   ip=mock.ANY,
                                   storage_method=mock_st_method,
                                   storage_medium=mock_st_medium)

        expected_dest = self.datadir
        expected_copy_calls = [
            mock.call(src, expected_dest, block_size=65536) for src in src_list
        ]

        self.assertEqual(mock_copy.call_count, 3)
        mock_copy.assert_has_calls(expected_copy_calls)
        mock_st_obj.assert_called_once()
Exemplo n.º 5
0
    def test_write_destination_not_a_dir_should_raise_exception(
            self, mock_storage_medium, mock_storage_method):
        disk_storage_backend = DiskStorageBackend()
        mock_storage_medium.storage_target.target = "some_bad_destination"

        with self.assertRaisesRegexp(
                ValueError,
                "{} is not a directory".format("some_bad_destination")):
            disk_storage_backend.write(src="some_src",
                                       ip=mock.ANY,
                                       storage_method=mock_storage_method,
                                       storage_medium=mock_storage_medium)

        with self.assertRaisesRegexp(
                ValueError,
                "{} is not a directory".format("some_bad_destination")):
            disk_storage_backend.write(src=["some_src"],
                                       ip=mock.ANY,
                                       storage_method=mock_storage_method,
                                       storage_medium=mock_storage_medium)
Exemplo n.º 6
0
    def test_write_dest_is_path_to_container(self, mock_st_medium,
                                             mock_st_method, mock_st_obj,
                                             mock_copy):
        disk_storage_backend = DiskStorageBackend()
        mock_st_medium.storage_target.target = self.datadir
        mock_st_method.containers = True

        disk_storage_backend.write(src="some_src",
                                   ip=mock.ANY,
                                   container=mock_st_method.containers,
                                   storage_medium=mock_st_medium)

        mock_copy.assert_called_once()
        mock_st_obj.assert_called_once_with(
            container=True,
            content_location_type=DISK,
            content_location_value='bar.tar',
            ip=mock.ANY,
            storage_medium=mock_st_medium,
        )
Exemplo n.º 7
0
    def test_write_src_with_multi_files_not_container(self, st_medium,
                                                      mock_st_method,
                                                      mock_st_obj, mock_copy,
                                                      ip):
        disk_storage_backend = DiskStorageBackend()
        st_medium.storage_target.target = self.datadir
        mock_st_method.containers = False
        ip.object_identifier_value = "some/object/path"
        src_list = ["some_src", "some_src2", "some_src3"]

        disk_storage_backend.write(src=src_list,
                                   ip=ip,
                                   storage_method=mock_st_method,
                                   storage_medium=st_medium)

        expected_dest = os.path.join(self.datadir, "some/object/path")
        expected_copy_calls = [
            mock.call(src, expected_dest, block_size=65536) for src in src_list
        ]

        self.assertEqual(mock_copy.call_count, 3)
        mock_copy.assert_has_calls(expected_copy_calls)
        mock_st_obj.assert_called_once()