Example #1
0
    def test_ims_parser(self):
        ''' Test IMS1.0 bulletin file parser.
        '''
        # Create an event with valid time limits.
        bulletin_file = os.path.join(self.data_path, 'bulletin_ims1.0_1.txt')
        #bulletin_file = os.path.join(self.data_path, 'bulletin_zamg_ims1.0_1.txt')
        parser = bulletin.ImsParser()
        parser.parse(bulletin_file)
        catalog = parser.get_catalog()

        cur_events = catalog.events
        self.assertEqual(len(cur_events), 1)
        self.assertEqual(cur_events[0].public_id, '112460')
        self.assertEqual(cur_events[0].description, 'Southeast of Honshu, Japan')

        bulletin_file = os.path.join(self.data_path, 'bulletin_zamg_ims1.0_1.txt')
        parser = bulletin.ImsParser()
        parser.parse(bulletin_file)
        catalog = parser.get_catalog()

        cur_events = catalog.events
        self.assertEqual(len(cur_events), 13)
Example #2
0
    def test_load_catalog_from_db(self):
        ''' Test the loading of catalogs from the database.
        '''
        # Write event data to the database.
        bulletin_file = os.path.join(self.data_path, 'bulletin_ims1.0_1.txt')
        parser = ev_bulletin.ImsParser()
        parser.parse(bulletin_file)
        catalog = parser.get_catalog(name='REB', agency_uri='REB')
        catalog.write_to_database(self.project)

        bulletin_file = os.path.join(self.data_path,
                                     'bulletin_zamg_ims1.0_1.txt')
        parser = ev_bulletin.ImsParser()
        parser.parse(bulletin_file)
        catalog = parser.get_catalog(name='ZAMG_AUTODRM', agency_uri='ZAMG')
        catalog.write_to_database(self.project)

        # Create the library and test the loading of one catalog.
        library = ev_core.Library(name='test_name')
        library.load_catalog_from_db(project=self.project, name='REB')

        self.assertEqual(len(library.catalogs), 1)
        self.assertEqual(library.catalogs.keys(), ['REB'])
        self.assertIsInstance(library.catalogs['REB'], ev_core.Catalog)

        cur_catalog = library.catalogs['REB']
        self.assertEqual(len(cur_catalog.events), 1)
        cur_event = cur_catalog.events[0]
        self.assertIsInstance(cur_event, ev_core.Event)
        self.assertEqual(cur_event.public_id, '112460')

        # Create the library and test the loading of multiple catalogs.
        library = ev_core.Library(name='test_name')
        library.load_catalog_from_db(project=self.project,
                                     name=['REB', 'ZAMG_AUTODRM'])
        self.assertEqual(len(library.catalogs), 2)
        self.assertListEqual(sorted(library.catalogs.keys()),
                             ['REB', 'ZAMG_AUTODRM'])
Example #3
0
    def test_write_bulletin_to_database(self):
        ''' Test the import of a bulletin into the database.
        '''
        bulletin_file = os.path.join(self.data_path, 'bulletin_ims1.0_1.txt')
        parser = ev_bulletin.ImsParser()
        parser.parse(bulletin_file)
        catalog = parser.get_catalog(name='REB', agency_uri='REB')

        catalog.write_to_database(self.project)

        db_catalog_orm = self.project.dbTables['event_catalog']
        db_session = self.project.getDbSession()
        result = db_session.query(db_catalog_orm).all()
        db_session.close()
        self.assertEqual(len(result), 1)
        tmp = result[0]
        self.assertEqual(tmp.name, 'REB')
        self.assertEqual(len(tmp.events), 1)
        cur_event = tmp.events[0]
        self.assertEqual(cur_event.public_id, '112460')
        self.assertEqual(cur_event.description, 'Southeast of Honshu, Japan')

        # Clear the database tables.
        clear_project_database_tables(self.project)

        bulletin_file = os.path.join(self.data_path,
                                     'bulletin_zamg_ims1.0_1.txt')
        parser = ev_bulletin.ImsParser()
        parser.parse(bulletin_file)
        catalog = parser.get_catalog(name='ZAMG_AUTODRM', agency_uri='ZAMG')

        catalog.write_to_database(self.project)

        db_catalog_orm = self.project.dbTables['event_catalog']
        db_session = self.project.getDbSession()
        result = db_session.query(db_catalog_orm).all()
        db_session.close()
        self.assertEqual(len(result), 1)
Example #4
0
    def test_get_catalogs_in_db(self):
        ''' Test the query of catalog names from the database.
        '''
        # Write event data to the database.
        bulletin_file = os.path.join(self.data_path,
                                     'bulletin_zamg_ims1.0_1.txt')
        parser = ev_bulletin.ImsParser()
        parser.parse(bulletin_file)
        catalog = parser.get_catalog(name='ZAMG_AUTODRM', agency_uri='ZAMG')
        catalog.write_to_database(self.project)

        bulletin_file = os.path.join(self.data_path, 'bulletin_ims1.0_1.txt')
        parser = ev_bulletin.ImsParser()
        parser.parse(bulletin_file)
        catalog = parser.get_catalog(name='REB', agency_uri='REB')
        catalog.write_to_database(self.project)

        # Create the library.
        library = ev_core.Library(name='test_name')
        catalog_names = library.get_catalogs_in_db(project=self.project)

        self.assertIsInstance(catalog_names, list)
        self.assertEqual(len(catalog_names), 2)
        self.assertListEqual(catalog_names, ['REB', 'ZAMG_AUTODRM'])