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_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_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_event_info_dict(self): """Test we can get a dictionary of location info nicely.""" working_dir = shakemap_extract_dir() shake_event = ShakeEvent( working_dir=working_dir, event_id=SHAKE_ID, data_is_local_flag=True) result = shake_event.event_dict() software_tag = ('This report was created using InaSAFE version %s. ' 'Visit http://inasafe.org for more information.' % get_version()) # noinspection PyUnresolvedReferences expected_dict = { 'place-name': u'Jayapura', 'shake-grid-location': u'Papua', 'depth-name': u'Depth', 'fatalities-name': u'Estimated fatalities', 'fatalities-count': u'0', # 44 only after render 'elapsed-time': u'', # empty as it will change 'legend-name': u'Population count per grid cell', 'fatalities-range': '0 - 100', 'longitude-name': u'Longitude', 'located-label': u'Located', 'distance-unit': u'km', 'bearing-compass': u'NW', 'elapsed-time-name': u'Elapsed time since event', 'exposure-table-name': u'Estimated number of people ' u'affected by each MMI level', 'longitude-value': u'140\xb037\u203212.00\u2033E', 'city-table-name': u'Nearby Places', 'bearing-text': u'bearing', 'limitations': ( u'This impact estimation is automatically generated and only ' u'takes into account the population and cities affected by ' u'different levels of ground shaking. The estimate is based ' u'on ground shaking data from BMKG, population count data ' u'derived by Australian Government from worldpop.org.uk, ' u'place information from geonames.org and software developed ' u'by BNPB. Limitations in the estimates of ground shaking, ' u'population and place names datasets may result in ' u'significant misrepresentation of the on-the-ground ' u'situation in the figures shown here. Consequently ' u'decisions should not be made solely on the information ' u'presented here and should always be verified by ground ' u'truthing and other reliable information sources. The ' u'fatality calculation assumes that no fatalities occur ' u'for shake levels below MMI 4. Fatality counts of less than ' u'50 are disregarded.'), 'depth-unit': u'km', 'latitude-name': u'Latitude', 'mmi': '3.6', 'map-name': u'Estimated Earthquake Impact', 'date': '5-11-2013', 'bearing-degrees': '-37.75\xb0', 'formatted-date-time': '05-Nov-13 06:08:09 +0707', 'distance': '0.02', 'direction-relation': u'of', 'software-tag': software_tag, 'credits': ( u'Supported by the Australian Government, Geoscience ' u'Australia and the World Bank-GFDRR.'), 'latitude-value': u'2\xb025\u203248.00\u2033S', 'time': '6:8:9', 'depth-value': '10.0'} result['elapsed-time'] = u'' message = 'Got:\n%s\nExpected:\n%s\n' % (result, expected_dict) self.max_diff = None difference = DictDiffer(result, expected_dict) LOGGER.debug(difference.all()) self.assertDictEqual(expected_dict, result, message)
def test_event_info_dict(self): """Test we can get a dictionary of location info nicely.""" working_dir = shakemap_extract_dir() shake_event = ShakeEvent( working_dir=working_dir, event_id=SHAKE_ID, data_is_local_flag=True) result = shake_event.event_dict() software_tag = ('This report was created using InaSAFE version %s. ' 'Visit http://inasafe.org for more information.' % get_version()) # noinspection PyUnresolvedReferences expected_dict = { 'place-name': u'n/a', 'shake-grid-location': u'Papua', 'depth-name': u'Depth', 'fatalities-name': u'Estimated fatalities', 'fatalities-count': u'0', # 44 only after render 'elapsed-time': u'', # empty as it will change 'legend-name': u'Population count per grid cell', 'fatalities-range': '0 - 100', 'longitude-name': u'Longitude', 'located-label': u'Located', 'distance-unit': u'km', 'bearing-compass': u'n/a', 'elapsed-time-name': u'Elapsed time since event', 'exposure-table-name': u'Estimated number of people ' u'affected by each MMI level', 'longitude-value': u'140\xb037\'12.00"E', 'city-table-name': u'Nearby Places', 'bearing-text': u'bearing', 'limitations': ( u'This impact estimation is automatically generated and only ' u'takes into account the population and cities affected by ' u'different levels of ground shaking. The estimate is based ' u'on ground shaking data from BMKG, population count data ' u'derived by Australian Government from worldpop.org.uk, ' u'place information from geonames.org and software developed ' u'by BNPB. Limitations in the estimates of ground shaking, ' u'population and place names datasets may result in ' u'significant misrepresentation of the on-the-ground ' u'situation in the figures shown here. Consequently ' u'decisions should not be made solely on the information ' u'presented here and should always be verified by ground ' u'truthing and other reliable information sources. The ' u'fatality calculation assumes that no fatalities occur ' u'for shake levels below MMI 4. Fatality counts of less than ' u'50 are disregarded.'), 'depth-unit': u'km', 'latitude-name': u'Latitude', 'mmi': '3.6', 'map-name': u'Estimated Earthquake Impact', 'date': '5-11-2013', 'bearing-degrees': '0.00\xb0', 'formatted-date-time': '05-Nov-13 06:08:09 +0707', 'distance': '0.00', 'direction-relation': u'of', 'software-tag': software_tag, 'credits': ( u'Supported by the Australian Government, Geoscience ' u'Australia and the World Bank-GFDRR.'), 'latitude-value': u'2\xb025\'48.00"S', 'time': '6:8:9', 'depth-value': '10.0'} result['elapsed-time'] = u'' message = 'Got:\n%s\nExpected:\n%s\n' % (result, expected_dict) self.max_diff = None difference = DictDiffer(result, expected_dict) LOGGER.debug(difference.all()) self.assertDictEqual(expected_dict, result, message)