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 TestIbiza(unittest.TestCase): def setUp(self): self.instance = Ibiza() self.date = get('2022-06-20').format('YYYY-MM-DD') def test_instance(self): self.assertIsInstance(self.instance, Ibiza) def test_get(self): response = self.instance.get(self.date) self.assertIsInstance(response, Response) self.assertIsNotNone(response.timestamp) self.assertEqual(response.demand, 115.6) self.assertEqual(response.carbon, 0.0) self.assertEqual(response.link['pe_ma'], 0.0) self.assertEqual(response.link['ma_me'], 0.0) self.assertEqual(86.9, response.link['ma_ib']) def test_get_all(self): responses = self.instance.get_all() self.assertIsNotNone(responses)
def setUp(self): self.instance = Ibiza() self.date = get('2022-06-20').format('YYYY-MM-DD')