def fetch_island_data(zone_key, session): if zone_key == "ES-IB-FO": formentera_data = Formentera(session, verify=False).get_all() if not formentera_data: raise ParserException(zone_key, "Formentera doesn't respond") else: return formentera_data elif zone_key == "ES-IB-IZ": ibiza_data = Ibiza(session, verify=False).get_all() if not ibiza_data: raise ParserException(zone_key, "Party is over, Ibiza doesn't respond") else: return ibiza_data elif zone_key == "ES-IB-MA": mallorca_data = Mallorca(session, verify=False).get_all() if not mallorca_data: raise ParserException(zone_key, "Mallorca doesn't respond") else: return mallorca_data elif zone_key == "ES-IB-ME": menorca_data = Menorca(session, verify=False).get_all() if not menorca_data: raise ParserException(zone_key, "Menorca doesn't respond") else: return menorca_data elif zone_key == "ES-IB": balearic_islands = BalearicIslands(session, verify=False).get_all() if not balearic_islands: raise ParserException(zone_key, "Balearic Islands doesn't respond") else: return balearic_islands else: raise ParserException( zone_key, "Can't read this country code {0}".format(zone_key))
class TestMenorca(unittest.TestCase): def setUp(self): self.instance = Menorca() self.date = get('2022-06-19').format('YYYY-MM-DD') def test_instance(self): self.assertIsInstance(self.instance, Menorca) def test_get(self): response = self.instance.get(self.date) self.assertIsInstance(response, Response) self.assertIsNotNone(response.timestamp) self.assertEqual(response.demand, 50.8) self.assertEqual(response.carbon, 0.0) self.assertEqual(response.link['pe_ma'], 0.0) self.assertEqual(response.link['ma_me'], 15.4) self.assertEqual(response.link['ma_ib'], 0.0) def test_get_all(self): responses = self.instance.get_all() self.assertIsNotNone(responses)
def setUp(self): self.instance = Menorca() self.date = get('2022-06-19').format('YYYY-MM-DD')