def test_uses_grid_location(self): """Test regarding issue #2438 """ working_dir = shakemap_extract_dir() # population_path = shake_event = ShakeEvent( working_dir=working_dir, event_id=SHAKE_ID_2, locale='en', force_flag=True, data_is_local_flag=True, # population_raster_path=population_path ) expected_location = 'Yogyakarta' self.assertEqual( shake_event.event_dict()['shake-grid-location'], expected_location) inasafe_django = InaSAFEDjangoREST() if inasafe_django.is_configured(): # generate report shake_event.render_map() # push to realtime django push_shake_event_to_rest(shake_event) # check shake event exists session = inasafe_django.rest response = session.earthquake(SHAKE_ID_2).GET() self.assertEqual(response.status_code, requests.codes.ok) self.assertEqual( response.json()['location_description'], shake_event.event_dict()['shake-grid-location'])
def test_push_to_realtime(self): # only do the test if realtime test server is configured inasafe_django = InaSAFEDjangoREST() if inasafe_django.is_configured(): working_dir = shakemap_extract_dir() shake_event = ShakeEvent( working_dir=working_dir, event_id=SHAKE_ID, locale='en', data_is_local_flag=True) # generate report shake_event.render_map() # push to realtime django push_shake_event_to_rest(shake_event) # check shake event exists session = inasafe_django.rest response = session.earthquake(SHAKE_ID).GET() self.assertEqual(response.status_code, requests.codes.ok) event_dict = shake_event.event_dict() earthquake_data = { 'shake_id': shake_event.event_id, 'magnitude': float(event_dict.get('mmi')), 'depth': float(event_dict.get('depth-value')), 'time': shake_event.shake_grid.time, 'location': { 'type': 'Point', 'coordinates': [ shake_event.shake_grid.longitude, shake_event.shake_grid.latitude ] }, 'location_description': event_dict.get('shake-grid-location') } for key, value in earthquake_data.iteritems(): if isinstance(value, datetime.datetime): self.assertEqual( datetime.datetime.strptime( response.json()[key], '%Y-%m-%dT%H:%M:%SZ' ).replace(tzinfo=pytz.utc), value ) else: self.assertEqual(response.json()[key], value)
def test_render_map(self): """Test render_map function in shake_event.""" working_dir = shakemap_extract_dir() shake_event = ShakeEvent( working_dir=working_dir, event_id=SHAKE_ID, data_is_local_flag=True) # Render Map shake_event.render_map() # There should be exist: # 1. SHAKE_ID-en.pdf # 2. SHAKE_ID-en.png # 3. SHAKE_ID-thumb-en.png # 4. SHAKE_ID-metadata-en.pickle # 5. mmi-cities.shp, shx, dbf, prj, qml # 6. mmi-contours-nearest.shp, shx, dbf, prj, qml # 7. city-search-boxes.shp, shx, dbf, prj, qml # 8. composer-template.qpt # 9. project.qgs target_dir = os.path.join(shakemap_extract_dir(), SHAKE_ID) shapefile_extension = ['shp', 'shx', 'dbf', 'prj', 'qml'] # 1 pdf_path = os.path.join(target_dir, '%s-en.pdf' % SHAKE_ID) message = 'PDF Report is not generated successfully in %s' % pdf_path self.assertTrue(os.path.exists(pdf_path), message) # 2 png_path = os.path.join(target_dir, '%s-en.png' % SHAKE_ID) message = 'PNG Report is not generated successfully in %s' % png_path self.assertTrue(os.path.exists(png_path), message) # 3 thumbnail_path = os.path.join(target_dir, '%s-thumb-en.png' % SHAKE_ID) message = 'PNG Thumbnail is not generated successfully in %s' % ( thumbnail_path) self.assertTrue(os.path.exists(thumbnail_path), message) # 4 metadata_path = os.path.join( target_dir, '%s-metadata-en.pickle' % SHAKE_ID) message = 'Metadata file is not generated successfully in %s' % ( metadata_path) self.assertTrue(os.path.exists(metadata_path), message) # 5. mmi-cities.shp, shx, dbf, prj, qml mmi_cities_path = os.path.join(target_dir, 'mmi-cities.shp') for extension in shapefile_extension: file_path = mmi_cities_path.replace('shp', extension) message = 'mmi-cities.%s is not generated successfully in %s' % ( extension, file_path) self.assertTrue(os.path.exists(file_path), message) # 6. mmi-contours-nearest.shp, shx, dbf, prj, qml mmi_contours_path = os.path.join( target_dir, 'mmi-contours-nearest.shp') for extension in shapefile_extension: file_path = mmi_contours_path.replace('shp', extension) message = ( 'mmi-contours-nearest.%s is not generated successfully in ' '%s') % (extension, file_path) self.assertTrue(os.path.exists(file_path), message) # 7. city-search-boxes.shp, shx, dbf, prj, qml city_search_boxes_path = os.path.join( target_dir, 'city-search-boxes.shp') for extension in shapefile_extension: file_path = city_search_boxes_path.replace('shp', extension) message = ( 'city-search-boxes.%s is not generated successfully in ' '%s') % (extension, file_path) self.assertTrue(os.path.exists(file_path), message) # 8 composer_template_path = os.path.join( target_dir, 'composer-template.qpt') message = ( 'Composer template file is not generated successfully in %s' % composer_template_path) self.assertTrue(os.path.exists(composer_template_path), message) # 9 qgs_project_path = os.path.join( target_dir, 'project.qgs') message = 'QGIS Project file is not generated successfully in %s' % ( qgs_project_path) self.assertTrue(os.path.exists(qgs_project_path), message)
# coding=utf-8 """Simple helper for when you already have the grid.xml and just want a map.""" # Tim Sutton, April 2013. import sys from realtime.earthquake.shake_event import ShakeEvent if __name__ == "__main__": working_dir = sys.argv[1] SHAKE_ID = "20131105060809" # To ensure that realtime is working for not just en locale, use other # locale here to test realtime locales = ["en", "id"] for locale in locales: shake_event = ShakeEvent( working_dir=working_dir, event_id=SHAKE_ID, locale=locale, force_flag=False, data_is_local_flag=True ) shake_event.render_map(force_flag=False)
# coding=utf-8 """Simple helper for when you already have the grid.xml and just want a map.""" # Tim Sutton, April 2013. import sys from realtime.earthquake.shake_event import ShakeEvent if __name__ == '__main__': working_dir = sys.argv[1] SHAKE_ID = '20131105060809' # To ensure that realtime is working for not just en locale, use other # locale here to test realtime locales = ['en', 'id'] for locale in locales: shake_event = ShakeEvent(working_dir=working_dir, event_id=SHAKE_ID, locale=locale, force_flag=False, data_is_local_flag=True) shake_event.render_map(force_flag=False)