def test_road_report_template(self): """Test Road Report Template.""" with open(ROAD_JSON_FILE) as json_file: impact_data = json.load(json_file) road_report_template = GenericReportTemplate(impact_data=impact_data) report = road_report_template.generate_message_report() self.assertIn(impact_data['question'], report.message[0].to_text()) expected = ''' --- **17459.7365945**, 41,116, 58,576--- ''' result = report.message[1].to_text() self.assertIn(expected, result)
def test_road_report_template(self): """Test Road Report Template.""" with open(ROAD_JSON_FILE) as json_file: impact_data = json.load(json_file) road_report_template = GenericReportTemplate( impact_data=impact_data) report = road_report_template.generate_message_report() self.assertIn( impact_data['question'], report.message[0].to_text()) expected = ''' --- **17459.7365945**, 41,116, 58,576--- ''' result = report.message[1].to_text() self.assertIn(expected, result)
def test_building_report_template(self): """Test Building Report Template.""" with open(BUILDING_JSON_FILE) as json_file: impact_data = json.load(json_file) building_report_template = GenericReportTemplate( impact_data=impact_data) report = building_report_template.generate_message_report() self.assertIn(impact_data['question'], report.message[0].to_text()) text = ''' --- **High**, 0------ **Medium**, 181------ **Low**, 0------ **Affected buildings**, 181------ **Not affected buildings**, 0------ **Total**, 181--- ''' self.assertIn(text, report.message[1].to_text())
def test_building_report_template(self): """Test Building Report Template.""" with open(BUILDING_JSON_FILE) as json_file: impact_data = json.load(json_file) building_report_template = GenericReportTemplate( impact_data=impact_data) report = building_report_template.generate_message_report() self.assertIn( impact_data['question'], report.message[0].to_text()) text = ''' --- **High**, 0------ **Medium**, 181------ **Low**, 0------ **Affected buildings**, 181------ **Not affected buildings**, 0------ **Total**, 181--- ''' self.assertIn(text, report.message[1].to_text())
def get_report_template( impact_layer_path=None, json_file=None, impact_data=None): """Return matching report template object. :param impact_layer_path: Path to impact layer. :type impact_layer_path: str :param json_file: Path to json impact data. :type json_file: str :param impact_data: Dictionary that represent impact data. :type impact_data: dict :returns: Report template object :rtype: GenericReportTemplate, BuildingReportTemplate """ # Check for impact layer path first if impact_layer_path: impact_data_path = os.path.splitext(impact_layer_path)[0] + '.json' json_file = impact_data_path if json_file: if os.path.exists(json_file): with open(json_file) as json_file: impact_data = json.load(json_file) if not impact_data: raise MissingImpactReport if impact_data['exposure'] in ['building', 'road', 'place']: return GenericReportTemplate(impact_data=impact_data) elif impact_data['exposure'] == 'population': return PopulationReportTemplate(impact_data=impact_data) elif impact_data['exposure'] == 'polygon people': return PolygonPeopleReportTemplate(impact_data=impact_data) elif impact_data['exposure'] == 'land cover': return LandCoverReportTemplate(impact_data=impact_data) else: raise MissingImpactReport( 'The exposure %s is not recognized' % impact_data.get('exposure'))