Exemplo n.º 1
0
 def test_get_list_event_ids(self):
     """Test get list event id."""
     sftp_shake_data = SftpShakeData(working_dir=temp_dir('realtime-test'))
     list_id = sftp_shake_data.get_list_event_ids()
     expected_list_id = [SHAKE_ID]
     message = 'I got %s for the event ID in the server, Expectation %s' % (
         list_id, expected_list_id)
     self.assertEqual(list_id, expected_list_id, message)
Exemplo n.º 2
0
 def test_extract(self):
     """Test extracting data to be used in earth quake realtime."""
     sftp_shake_data = SftpShakeData(working_dir=temp_dir('realtime-test'))
     sftp_shake_data.extract()
     final_grid_xml_file = os.path.join(
         sftp_shake_data.extract_dir(), 'grid.xml')
     self.assertTrue(
         os.path.exists(final_grid_xml_file), 'grid.xml not found')
Exemplo n.º 3
0
 def test_fetch_file(self):
     """Test fetch data."""
     sftp_shake_data = SftpShakeData(working_dir=temp_dir('realtime-test'))
     local_path = sftp_shake_data.fetch_file()
     expected_path = os.path.join(shakemap_cache_dir(), SHAKE_ID)
     message = 'File should be fetched to %s, I got %s' % (
         expected_path, local_path)
     self.assertEqual(local_path, expected_path, message)
Exemplo n.º 4
0
 def test_extract(self):
     """Test extracting data to be used in earth quake realtime."""
     sftp_shake_data = SftpShakeData(working_dir=temp_dir('realtime-test'))
     sftp_shake_data.extract()
     final_grid_xml_file = os.path.join(sftp_shake_data.extract_dir(),
                                        'grid.xml')
     self.assertTrue(os.path.exists(final_grid_xml_file),
                     'grid.xml not found')
Exemplo n.º 5
0
 def test_fetch_file(self):
     """Test fetch data."""
     sftp_shake_data = SftpShakeData(working_dir=temp_dir('realtime-test'))
     local_path = sftp_shake_data.fetch_file()
     expected_path = os.path.join(shakemap_cache_dir(), SHAKE_ID)
     message = 'File should be fetched to %s, I got %s' % (expected_path,
                                                           local_path)
     self.assertEqual(local_path, expected_path, message)
Exemplo n.º 6
0
 def test_get_list_event_ids(self):
     """Test get list event id."""
     sftp_shake_data = SftpShakeData(working_dir=temp_dir('realtime-test'))
     list_id = sftp_shake_data.get_list_event_ids()
     expected_list_id = [SHAKE_ID]
     message = 'I got %s for the event ID in the server, Expectation %s' % (
         list_id, expected_list_id)
     self.assertEqual(list_id, expected_list_id, message)
Exemplo n.º 7
0
 def test_get_latest_event_id(self):
     """Test get latest event id."""
     sftp_shake_data = SftpShakeData(working_dir=temp_dir('realtime-test'))
     latest_id = sftp_shake_data.get_latest_event_id()
     # The latest event ID should be = SHAKE_ID since there's only one
     expected_event_id = SHAKE_ID
     message = 'I got %s for this latest event id, Expectation %s' % (
         latest_id, expected_event_id)
     self.assertEqual(expected_event_id, latest_id, message)
Exemplo n.º 8
0
 def test_get_latest_event_id(self):
     """Test get latest event id."""
     sftp_shake_data = SftpShakeData(working_dir=temp_dir('realtime-test'))
     latest_id = sftp_shake_data.get_latest_event_id()
     # The latest event ID should be = SHAKE_ID since there's only one
     expected_event_id = SHAKE_ID
     message = 'I got %s for this latest event id, Expectation %s' % (
         latest_id, expected_event_id)
     self.assertEqual(expected_event_id, latest_id, message)
Exemplo n.º 9
0
    def test_reconnect_sftp(self):
        """Test to reconnect SFTP."""
        sftp_shake_data = SftpShakeData(working_dir=temp_dir('realtime-test'))
        sftp_client = sftp_shake_data.sftp_client
        sftp_shake_data.reconnect_sftp()
        new_sftp_client = sftp_shake_data.sftp_client

        message = 'Oh no, we got the same sftp client after reconnecting!'
        self.assertNotEqual(sftp_client, new_sftp_client, message)
        message = 'Oh dear, the new sftp object is None after reconnecting'
        self.assertIsNotNone(new_sftp_client, message)
Exemplo n.º 10
0
    def test_reconnect_sftp(self):
        """Test to reconnect SFTP."""
        sftp_shake_data = SftpShakeData(working_dir=temp_dir('realtime-test'))
        sftp_client = sftp_shake_data.sftp_client
        sftp_shake_data.reconnect_sftp()
        new_sftp_client = sftp_shake_data.sftp_client

        message = 'Oh no, we got the same sftp client after reconnecting!'
        self.assertNotEqual(sftp_client, new_sftp_client, message)
        message = 'Oh dear, the new sftp object is None after reconnecting'
        self.assertIsNotNone(new_sftp_client, message)
Exemplo n.º 11
0
    def test_constructor(self):
        """Test create shake data."""
        try:
            event_one = SftpShakeData(working_dir=temp_dir('realtime-test'))
            event_two = SftpShakeData(event=SHAKE_ID,
                                      working_dir=temp_dir('realtime-test'))

            self.assertIsNotNone(event_one)
            self.assertIsNotNone(event_two)
        except:
            raise
Exemplo n.º 12
0
 def test_create_event(self):
     """Test create shake data
     """
     try:
         event_one = SftpShakeData()
         event_two = SftpShakeData(theEvent='20130110041009')
         event_three = SftpShakeData(theEvent='20130110041009',
                                     theForceFlag=True)
         assert event_one is not None
         assert event_two is not None
         assert event_three is not None
     except:
         raise
Exemplo n.º 13
0
 def test_is_on_server(self):
     """Test to check if a event is in server."""
     sftp_shake_data = SftpShakeData(working_dir=temp_dir('realtime-test'))
     message = 'Event does not exist in the server.'
     self.assertTrue(sftp_shake_data.is_on_server(), message)
Exemplo n.º 14
0
 def test_is_on_server(self):
     """Test to check if a event is in server."""
     sftp_shake_data = SftpShakeData(working_dir=temp_dir('realtime-test'))
     message = 'Event does not exist in the server.'
     self.assertTrue(sftp_shake_data.is_on_server(), message)
Exemplo n.º 15
0
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.

"""

__author__ = '*****@*****.**'
__version__ = '0.5.0'
__date__ = '10/01/2013'
__copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
                 'Disaster Reduction')
import unittest
from realtime.sftp_shake_data import SftpShakeData
import os

sftp_data = SftpShakeData()


class SFtpShakeDataTest(unittest.TestCase):
    def test_create_event(self):
        """Test create shake data
        """
        try:
            event_one = SftpShakeData()
            event_two = SftpShakeData(theEvent='20130110041009')
            event_three = SftpShakeData(theEvent='20130110041009',
                                        theForceFlag=True)
            assert event_one is not None
            assert event_two is not None
            assert event_three is not None
        except: