def test_interval_block_data(self): """ Test of xml_importer.interval_block_data. """ interval_block_start = """ <IntervalBlock xmlns="http://naesb.org/espi"> <interval> <duration>31622400</duration> <start>1357027200</start> </interval> """ interval_block_end = """ </IntervalBlock> """ interval_reading_xml = """ <IntervalReading> <cost>190923</cost> <timePeriod> <duration>86400</duration> <start>1357027200</start> </timePeriod> <value>2083</value> </IntervalReading> """ single_ib_xml = (interval_block_start + interval_reading_xml + interval_block_end) multiple_ib_xml = (interval_block_start + interval_reading_xml + interval_reading_xml + interval_block_end) single_xml_data = xmltodict.parse(single_ib_xml)['IntervalBlock'] multiple_xml_data = xmltodict.parse(multiple_ib_xml)['IntervalBlock'] reading_expected = { 'cost': '190923', 'value': '2083', 'start_time': '1357027200', 'duration': '86400' } single_expected = { 'start_time': '1357027200', 'duration': '31622400', 'readings': [reading_expected] } multiple_expected = copy.deepcopy(single_expected) multiple_expected['readings'] = [reading_expected, reading_expected] # test with single and multiple IntervalReadings; xmltodict # tries to get cute and may return a single dict or a list of # them for node contents single_res = xml_importer.interval_block_data(single_xml_data) multiple_res = xml_importer.interval_block_data(multiple_xml_data) self.assertEqual(single_res, single_expected) self.assertEqual(multiple_res, multiple_expected)
def test_interval_block_data(self): """ Test of xml_importer.interval_block_data. """ interval_block_start = """ <IntervalBlock xmlns="http://naesb.org/espi"> <interval> <duration>31622400</duration> <start>1357027200</start> </interval> """ interval_block_end = """ </IntervalBlock> """ interval_reading_xml = """ <IntervalReading> <cost>190923</cost> <timePeriod> <duration>86400</duration> <start>1357027200</start> </timePeriod> <value>2083</value> </IntervalReading> """ single_ib_xml = ( interval_block_start + interval_reading_xml + interval_block_end ) multiple_ib_xml = ( interval_block_start + interval_reading_xml + interval_reading_xml + interval_block_end ) single_xml_data = xmltodict.parse(single_ib_xml)['IntervalBlock'] multiple_xml_data = xmltodict.parse(multiple_ib_xml)['IntervalBlock'] reading_expected = { 'cost': '190923', 'value': '2083', 'start_time': '1357027200', 'duration': '86400' } single_expected = { 'start_time': '1357027200', 'duration': '31622400', 'readings': [reading_expected] } multiple_expected = copy.deepcopy(single_expected) multiple_expected['readings'] = [reading_expected, reading_expected] # test with single and multiple IntervalReadings; xmltodict # tries to get cute and may return a single dict or a list of # them for node contents single_res = xml_importer.interval_block_data(single_xml_data) multiple_res = xml_importer.interval_block_data(multiple_xml_data) self.assertEqual(single_res, single_expected) self.assertEqual(multiple_res, multiple_expected)