コード例 #1
0
    def test_successfully(self, mock_execute, mock_exists, mock_makedirs):
        '''Tests calling NfsBroker.download_files() successfully'''

        def new_exists(path):
            return False
        mock_exists.side_effect = new_exists

        download_dir = os.path.join('the', 'download', 'dir')
        work_dir = os.path.join('the', 'work', 'dir')
        file_1 = 'my_file.txt'
        file_2 = 'my_file.json'
        local_path_file_1 = os.path.join('my_dir_1', file_1)
        local_path_file_2 = os.path.join('my_dir_2', file_2)
        workspace_path_file_1 = os.path.join('my_wrk_dir_1', file_1)
        workspace_path_file_2 = os.path.join('my_wrk_dir_2', file_2)
        full_local_path_file_1 = os.path.join(download_dir, local_path_file_1)
        full_local_path_file_2 = os.path.join(download_dir, local_path_file_2)
        full_workspace_path_file_1 = os.path.join(work_dir, workspace_path_file_1)
        full_workspace_path_file_2 = os.path.join(work_dir, workspace_path_file_2)
        full_local_path_dir_1 = os.path.dirname(full_local_path_file_1)
        full_local_path_dir_2 = os.path.dirname(full_local_path_file_2)

        # Call method to test
        broker = NfsBroker()
        broker.download_files(download_dir, work_dir, [(workspace_path_file_1, local_path_file_1),
                                                       (workspace_path_file_2, local_path_file_2)])

        # Check results
        two_calls = [call(full_local_path_dir_1, mode=0755),
                     call(full_local_path_dir_2, mode=0755)]
        mock_makedirs.assert_has_calls(two_calls)
        two_calls = [call(['ln', '-s', full_workspace_path_file_1, full_local_path_file_1]),
                     call(['ln', '-s', full_workspace_path_file_2, full_local_path_file_2])]
        mock_execute.assert_has_calls(two_calls)
コード例 #2
0
class TestNfsBrokerDownloadFiles(TestCase):
    def setUp(self):
        django.setup()

        self.broker = NfsBroker()
        self.broker.load_configuration({
            'type': NfsBroker().broker_type,
            'nfs_path': 'host:/path'
        })

    @patch('storage.brokers.nfs_broker.os.path.exists')
    @patch('storage.brokers.nfs_broker.execute_command_line')
    def test_successfully(self, mock_execute, mock_exists):
        """Tests calling NfsBroker.download_files() successfully"""
        def new_exists(path):
            return False

        mock_exists.side_effect = new_exists

        volume_path = os.path.join('the', 'volume', 'path')
        file_name_1 = 'my_file.txt'
        file_name_2 = 'my_file.json'
        local_path_file_1 = os.path.join('my_dir_1', file_name_1)
        local_path_file_2 = os.path.join('my_dir_2', file_name_2)
        workspace_path_file_1 = os.path.join('my_wrk_dir_1', file_name_1)
        workspace_path_file_2 = os.path.join('my_wrk_dir_2', file_name_2)
        full_workspace_path_file_1 = os.path.join(volume_path,
                                                  workspace_path_file_1)
        full_workspace_path_file_2 = os.path.join(volume_path,
                                                  workspace_path_file_2)

        file_1 = storage_test_utils.create_file(
            file_path=workspace_path_file_1)
        file_2 = storage_test_utils.create_file(
            file_path=workspace_path_file_2)
        file_1_dl = FileDownload(file_1, local_path_file_1)
        file_2_dl = FileDownload(file_2, local_path_file_2)

        # Call method to test
        self.broker.download_files(volume_path, [file_1_dl, file_2_dl])

        # Check results
        two_calls = [
            call(['ln', '-s', full_workspace_path_file_1, local_path_file_1]),
            call(['ln', '-s', full_workspace_path_file_2, local_path_file_2])
        ]
        mock_execute.assert_has_calls(two_calls)
コード例 #3
0
ファイル: test_nfs_broker.py プロジェクト: droessne/scale
class TestNfsBrokerDownloadFiles(TestCase):

    def setUp(self):
        django.setup()

        self.broker = NfsBroker()
        self.broker.load_configuration({'type': NfsBroker().broker_type, 'nfs_path': 'host:/path'})

    @patch('storage.brokers.nfs_broker.os.path.exists')
    @patch('storage.brokers.nfs_broker.execute_command_line')
    def test_successfully(self, mock_execute, mock_exists):
        """Tests calling NfsBroker.download_files() successfully"""

        def new_exists(path):
            return False
        mock_exists.side_effect = new_exists

        volume_path = os.path.join('the', 'volume', 'path')
        file_name_1 = 'my_file.txt'
        file_name_2 = 'my_file.json'
        local_path_file_1 = os.path.join('my_dir_1', file_name_1)
        local_path_file_2 = os.path.join('my_dir_2', file_name_2)
        workspace_path_file_1 = os.path.join('my_wrk_dir_1', file_name_1)
        workspace_path_file_2 = os.path.join('my_wrk_dir_2', file_name_2)
        full_workspace_path_file_1 = os.path.join(volume_path, workspace_path_file_1)
        full_workspace_path_file_2 = os.path.join(volume_path, workspace_path_file_2)

        file_1 = storage_test_utils.create_file(file_path=workspace_path_file_1)
        file_2 = storage_test_utils.create_file(file_path=workspace_path_file_2)
        file_1_dl = FileDownload(file_1, local_path_file_1, False)
        file_2_dl = FileDownload(file_2, local_path_file_2, False)

        # Call method to test
        self.broker.download_files(volume_path, [file_1_dl, file_2_dl])

        # Check results
        two_calls = [call(['ln', '-s', full_workspace_path_file_1, local_path_file_1]),
                     call(['ln', '-s', full_workspace_path_file_2, local_path_file_2])]
        mock_execute.assert_has_calls(two_calls)