Exemplo n.º 1
0
    def test_download_path(self):
        """Test to download all directories and files under a path."""
        sftp_client = SFtpClient(working_dir=temp_dir('realtime-test'))
        self.assertIsNotNone(sftp_client)

        # Download directories
        shake_path = get_shake_test_data_path()
        remote_path = os.path.abspath(os.path.join(shake_path, SHAKE_ID))
        local_path = temp_dir('realtime-test')
        sftp_client.download_path(remote_path, local_path)

        # Check the local_path consist of SHAKE_ID folder
        expected_dir = [SHAKE_ID]
        actual_dir = os.listdir(local_path)
        message = "In the local path, I got: %s dir, Expectation: %s dir" % (
            actual_dir, expected_dir)
        self.assertEqual(expected_dir, actual_dir, message)

        # Inside that SHAKE_ID folder, there should be 'output' folder
        expected_dir = ['output']
        actual_dir = os.listdir(os.path.join(local_path, SHAKE_ID))
        message = "In the local path, I got: %s dir, Expectation: %s dir" % (
            actual_dir, expected_dir)
        self.assertEqual(expected_dir, actual_dir, message)

        # Inside that output folder, there should be 'grid.xml' file
        expected_dir = ['grid.xml']
        actual_dir = os.listdir(os.path.join(local_path, SHAKE_ID, 'output'))
        message = "In the local path, I got: %s dir, Expectation: %s dir" % (
            actual_dir, expected_dir)
        self.assertEqual(expected_dir, actual_dir, message)
Exemplo n.º 2
0
    def test_download_path(self):
        """Test to download all directories and files under a path."""
        sftp_client = SFtpClient(working_dir=temp_dir('realtime-test'))
        self.assertIsNotNone(sftp_client)

        # Download directories
        shake_path = get_shake_test_data_path()
        remote_path = os.path.abspath(
            os.path.join(shake_path, SHAKE_ID))
        local_path = temp_dir('realtime-test')
        sftp_client.download_path(remote_path, local_path)

        # Check the local_path consist of SHAKE_ID folder
        expected_dir = [SHAKE_ID]
        actual_dir = os.listdir(local_path)
        message = "In the local path, I got: %s dir, Expectation: %s dir" % (
            actual_dir, expected_dir)
        self.assertEqual(expected_dir, actual_dir, message)

        # Inside that SHAKE_ID folder, there should be 'output' folder
        expected_dir = ['output']
        actual_dir = os.listdir(os.path.join(local_path, SHAKE_ID))
        message = "In the local path, I got: %s dir, Expectation: %s dir" % (
            actual_dir, expected_dir)
        self.assertEqual(expected_dir, actual_dir, message)

        # Inside that output folder, there should be 'grid.xml' file
        expected_dir = ['grid.xml']
        actual_dir = os.listdir(os.path.join(local_path, SHAKE_ID, 'output'))
        message = "In the local path, I got: %s dir, Expectation: %s dir" % (
            actual_dir, expected_dir)
        self.assertEqual(expected_dir, actual_dir, message)
Exemplo n.º 3
0
    def setUp(self):
        """Setup before each test."""
        # Call sftp client monkey patching before running each tests
        run_monkey_patching_sftp_client()

        # Download files (which are local files) to realtime-test temp folder
        # AG:
        # So since we're using local data, in instantiating SFTPShakeData,
        # please pass the working dir to the local dir
        sftp_client = SFtpClient(working_dir=temp_dir('realtime-test'))
        local_path = temp_dir('realtime-test')
        remote_path = os.path.abspath(
            os.path.join(get_shake_test_data_path(), SHAKE_ID))
        sftp_client.download_path(remote_path, local_path)
Exemplo n.º 4
0
    def setUp(self):
        """Setup before each test."""
        # Call sftp client monkey patching before running each tests
        run_monkey_patching_sftp_client()

        # Download files (which are local files) to realtime-test temp folder
        # AG:
        # So since we're using local data, in instantiating SFTPShakeData,
        # please pass the working dir to the local dir
        sftp_client = SFtpClient(working_dir=temp_dir('realtime-test'))
        local_path = temp_dir('realtime-test')
        remote_path = os.path.abspath(
            os.path.join(get_shake_test_data_path(), SHAKE_ID))
        sftp_client.download_path(remote_path, local_path)
Exemplo n.º 5
0
def mock_get_file(self, url_path, file_path):
    """Mock get_file of ftp_client.

     :param url_path: (Mandatory) The path (relative to the ftp root)
          from which the file should be retrieved.

     :param file_path: (Mandatory). The path on the filesystem to which
          the file should be saved.

     :return: The path to the downloaded file.
    """
    shake_path = get_shake_test_data_path()
    local_shake_dir = os.path.abspath(shake_path)
    source_file_path = os.path.join(local_shake_dir, url_path)
    shutil.copy(source_file_path, file_path)
Exemplo n.º 6
0
    def test_get_listing(self):
        """Test get_listing if it's working correctly."""
        sftp_client = SFtpClient(working_dir=temp_dir('realtime-test'))
        self.assertIsNotNone(sftp_client)

        # Download directories
        shake_path = get_shake_test_data_path()
        remote_path = os.path.abspath(os.path.join(shake_path, SHAKE_ID))
        local_path = temp_dir('realtime-test')
        sftp_client.download_path(remote_path, local_path)

        event_ids = sftp_client.get_listing(function=is_event_id)
        expected_event_ids = [SHAKE_ID]
        message = 'In the local path I got %s dir, Expectation %s dir'
        self.assertEqual(event_ids, expected_event_ids, message)
Exemplo n.º 7
0
def mock_get_file(self, url_path, file_path):
    """Mock get_file of ftp_client.

     :param url_path: (Mandatory) The path (relative to the ftp root)
          from which the file should be retrieved.

     :param file_path: (Mandatory). The path on the filesystem to which
          the file should be saved.

     :return: The path to the downloaded file.
    """
    shake_path = get_shake_test_data_path()
    local_shake_dir = os.path.abspath(shake_path)
    source_file_path = os.path.join(local_shake_dir, url_path)
    shutil.copy(source_file_path, file_path)
Exemplo n.º 8
0
    def test_get_listing(self):
        """Test get_listing if it's working correctly."""
        sftp_client = SFtpClient(working_dir=temp_dir('realtime-test'))
        self.assertIsNotNone(sftp_client)

        # Download directories
        shake_path = get_shake_test_data_path()
        remote_path = os.path.abspath(
            os.path.join(shake_path, SHAKE_ID))
        local_path = temp_dir('realtime-test')
        sftp_client.download_path(remote_path, local_path)

        event_ids = sftp_client.get_listing(function=is_event_id)
        expected_event_ids = [SHAKE_ID]
        message = 'In the local path I got %s dir, Expectation %s dir'
        self.assertEqual(event_ids, expected_event_ids, message)
Exemplo n.º 9
0
    def setUp(self):
        """Copy our cached dataset from the fixture dir to the cache dir."""
        # Since ShakeEvent will be using sftp_shake_data, we'll copy the grid
        # file inside 20131105060809 folder to
        # shakemap_cache_dir/20131105060809/grid.xml
        input_path = os.path.abspath(
            os.path.join(
                get_shake_test_data_path(),
                SHAKE_ID,
                'output/grid.xml'))
        target_folder = os.path.join(
            shakemap_extract_dir(), SHAKE_ID)
        if not os.path.exists(target_folder):
            os.makedirs(target_folder)

        target_path = os.path.abspath(os.path.join(target_folder, 'grid.xml'))
        shutil.copyfile(input_path, target_path)
Exemplo n.º 10
0
def mock_get_listing(self, extension='zip'):
    """Mock get_listing of ftp_client.

    It is pointed to local folder we have.

    :param extension: (Optional) Filename suffix to filter the listing by.
        Defaults to zip.

    :returns: A list containing the unique filenames (if any) that match
        the supplied extension suffix.
    """
    base_url = 'ftp://%s' % self.base_url
    shake_path = get_shake_test_data_path()
    local_shake_dir = os.path.abspath(shake_path)
    file_list = []
    for filename in os.listdir(local_shake_dir):
        if filename.endswith('.%s' % extension):
            file_list.append(base_url + '/' + filename)
    return file_list
Exemplo n.º 11
0
def mock_get_listing(self, extension='zip'):
    """Mock get_listing of ftp_client.

    It is pointed to local folder we have.

    :param extension: (Optional) Filename suffix to filter the listing by.
        Defaults to zip.

    :returns: A list containing the unique filenames (if any) that match
        the supplied extension suffix.
    """
    base_url = 'ftp://%s' % self.base_url
    shake_path = get_shake_test_data_path()
    local_shake_dir = os.path.abspath(shake_path)
    file_list = []
    for filename in os.listdir(local_shake_dir):
        if filename.endswith('.%s' % extension):
            file_list.append(base_url + '/' + filename)
    return file_list
Exemplo n.º 12
0
    def setUp(self):
        """Copy our cached dataset from the fixture dir to the cache dir."""
        # Run monkey patching to ftp_client
        run_monkey_patching_ftp_client()

        output_file = '20120726022003.out.zip'
        input_file = '20120726022003.inp.zip'

        shake_path = get_shake_test_data_path()
        output_path = os.path.abspath(os.path.join(shake_path, output_file))
        input_path = os.path.abspath(os.path.join(shake_path, input_file))
        shutil.copyfile(
            output_path,
            os.path.join(shakemap_zip_dir(),
                         output_file))
        shutil.copyfile(
            input_path,
            os.path.join(shakemap_zip_dir(),
                         input_file))