Beispiel #1
0
    def test__ensure_target_directory_unique_inside_target_dir(self):
        """
        Should create directory with unique name inside target directory.
        :return:
        """
        import os.path
        from artefact.localhost.file import FileCopy

        expected_target_dir = "./test_target"
        expected_unique_dir_name = "me_unique"
        collector = FileCopy(parameters={}, parent=None)
        collector._destination_directory = expected_target_dir
        try:
            with mock.patch(
                    'artefact.localhost.file.FileCopy._get_unique_directory_name',
                    MagicMock(return_value=expected_unique_dir_name)):
                collector._ensure_target_directory()
            self.assertTrue(
                os.path.exists(
                    os.path.join(expected_target_dir,
                                 expected_unique_dir_name)))
        finally:
            if os.path.exists(
                    os.path.join(expected_target_dir,
                                 expected_unique_dir_name)):
                os.rmdir(
                    os.path.join(expected_target_dir,
                                 expected_unique_dir_name))
            if os.path.exists(expected_target_dir):
                os.rmdir(expected_target_dir)
Beispiel #2
0
    def test__ensure_target_directory(self):
        """
        Should return path of unique target directory
        :return:
        """
        import os.path
        from artefact.localhost.file import FileCopy

        expected_target_dir = "./test_target"
        expected_unique_dir_name = "me_unique"
        expected_return_value = './test_target/me_unique'
        if platform.system() == "Windows":
            expected_return_value = './test_target\\me_unique'
        collector = FileCopy(parameters={}, parent=None)
        collector._destination_directory = expected_target_dir
        try:
            with mock.patch(
                    'artefact.localhost.file.FileCopy._get_unique_directory_name',
                    MagicMock(return_value=expected_unique_dir_name)):
                acutal_return_value = collector._ensure_target_directory()
                self.assertEqual(expected_return_value, acutal_return_value)
        finally:
            if os.path.exists(
                    os.path.join(expected_target_dir,
                                 expected_unique_dir_name)):
                os.rmdir(
                    os.path.join(expected_target_dir,
                                 expected_unique_dir_name))
            if os.path.exists(expected_target_dir):
                os.rmdir(expected_target_dir)