def setUp(self): self.session = Session() first_request = Response(1504603773) first_request.link['pe_ma'] = 50 second_request = Response(1504603842) second_request.link['pe_ma'] = 50 self.mocked_responses = [first_request, second_request]
def test_fetch_consumption_el_hierro(self, el_hierro, gran_canaria, gomera, lanza_fuerte, palma, tene): el_hierro.return_value = [ Response(self.morning, 10.0), Response(self.afternoon, 5.6), Response(self.evening, 12.0) ] gran_canaria.return_value = [] gomera.return_value = [] lanza_fuerte.return_value = [] palma.return_value = [] tene.return_value = [] data = ES_CN.fetch_consumption('ES-CN-HI', self.session) self.assertIsNotNone(data) self.assertIs(len(data), 3) for consumption in data: self.assertEqual(consumption['countryCode'], 'ES-CN-HI') self.assertEqual(consumption['source'], 'demanda.ree.es') self.assertIsNotNone(consumption['datetime']) self.assertTrue(consumption['datetime'] == self.morning or consumption['datetime'] == self.afternoon or consumption['datetime'] == self.evening) if self.morning == consumption['datetime']: self.assertEqual(consumption['consumption'], 10.0) elif self.afternoon == consumption['datetime']: self.assertEqual(consumption['consumption'], 5.6) elif self.evening == consumption['datetime']: self.assertEqual(consumption['consumption'], 12.0)
def test_fetch_consumption(self, el_hierro, gran_canaria, gomera, lanza_fuerte, palma, tene): el_hierro.return_value = [] gran_canaria.return_value = [] gomera.return_value = [] lanza_fuerte.return_value = [ Response(self.morning, 64.4), Response(self.afternoon, 200.1), Response(self.evening, 54.4) ] palma.return_value = [] tene.return_value = [] data = ES_CN.fetch_consumption('ES-CN-FVLZ', self.session) self.assertIsNotNone(data) self.assertIs(len(data), 3) for consumption in data: self.assertEqual(consumption['zoneKey'], 'ES-CN-FVLZ') self.assertEqual(consumption['source'], 'demanda.ree.es') self.assertIsNotNone(consumption['datetime']) self.assertTrue(consumption['datetime'] == self.morning or consumption['datetime'] == self.afternoon or consumption['datetime'] == self.evening) if self.morning == consumption['datetime']: self.assertEqual(consumption['consumption'], 64.4) elif self.afternoon == consumption['datetime']: self.assertEqual(consumption['consumption'], 200.1) elif self.evening == consumption['datetime']: self.assertEqual(consumption['consumption'], 54.4)
def test_fetch_production(self, el_hierro, gran_canaria, gomera, lanza_fuerte, palma, tene): self.empty_production = get(1514673600).datetime el_hierro.return_value = [] gran_canaria.return_value = [] gomera.return_value = [] lanza_fuerte.return_value = [ Response(self.morning, 25.0, 1.5, 2.0, 0.5, 2.5, 2.5, 0.4, 5.0), Response(self.afternoon, 200.1, 182.0, 12.2, 3.1, 0.0, 0.0, 5.3, 0.0), Response(self.evening, 28.0, 1.5, 2.0, 0.5, 2.5, 2.5, 0.4, 5.0), Response(self.empty_production, 12.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) ] palma.return_value = [] tene.return_value = [] data = ES_CN.fetch_production('ES-CN-FVLZ', self.session) self.assertIsNotNone(data) self.assertIs(len(data), 3) for production in data: self.assertEqual(production['countryCode'], 'ES-CN-FVLZ') self.assertEqual(production['source'], 'demanda.ree.es') self.assertIsNotNone(production['datetime']) self.assertIsNotNone(production['production']) self.assertIsNotNone(production['storage']) self.assertTrue(production['datetime'] == self.morning or production['datetime'] == self.afternoon or production['datetime'] == self.evening) if self.morning == production['datetime']: self.assertEqual(production['production']['gas'], 4.5) self.assertEqual(production['production']['oil'], 4.0) self.assertEqual(production['production']['hydro'], 5.0) self.assertEqual(production['production']['solar'], 0.4) self.assertEqual(production['production']['wind'], 0.5) self.assertEqual(production['storage']['hydro'], 0.0) elif self.afternoon == production['datetime']: self.assertEqual(production['production']['gas'], 12.2) self.assertEqual(production['production']['oil'], 182.0) self.assertEqual(production['production']['hydro'], 0.0) self.assertEqual(production['production']['solar'], 5.3) self.assertEqual(production['production']['wind'], 3.1) self.assertEqual(production['storage']['hydro'], 0.0) elif self.evening == production['datetime']: self.assertEqual(production['production']['gas'], 4.5) self.assertEqual(production['production']['oil'], 4.0) self.assertEqual(production['production']['hydro'], 5.0) self.assertEqual(production['production']['solar'], 0.4) self.assertEqual(production['production']['wind'], 0.5) self.assertEqual(production['storage']['hydro'], 0.0)
def test_fetch_production_el_hierro(self, el_hierro, gran_canaria, gomera, lanza_fuerte, palma, tene): self.empty_production = get(1514673600).datetime el_hierro.return_value = [ Response(self.morning, 10.0, 1.5, 2.0, 0.5, 2.5, 2.5, 0.4, 5.0), Response(self.afternoon, 5.6, 1.7, 0.0, 1.6, 0.0, 0.0, 0.0, 2.4), Response(self.evening, 12.0, 2.0, 2.0, 0.5, 2.5, 2.5, 0.0, 3.0), Response(self.empty_production, 12.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) ] gran_canaria.return_value = [] gomera.return_value = [] lanza_fuerte.return_value = [] palma.return_value = [] tene.return_value = [] data = ES_CN.fetch_production('ES-CN-HI', self.session) self.assertIsNotNone(data) self.assertIs(len(data), 3) for production in data: self.assertEqual(production['zoneKey'], 'ES-CN-HI') self.assertEqual(production['source'], 'demanda.ree.es') self.assertIsNotNone(production['datetime']) self.assertIsNotNone(production['production']) self.assertIsNotNone(production['storage']) self.assertTrue(production['datetime'] == self.morning or production['datetime'] == self.afternoon or production['datetime'] == self.evening) if self.morning == production['datetime']: self.assertEqual(production['production']['gas'], 4.5) self.assertEqual(production['production']['oil'], 4.0) self.assertEqual(production['production']['hydro'], 0.0) self.assertEqual(production['production']['solar'], 0.4) self.assertEqual(production['production']['wind'], 0.5) self.assertEqual(production['storage']['hydro'], -5.0) elif self.afternoon == production['datetime']: self.assertEqual(production['production']['gas'], 0.0) self.assertEqual(production['production']['oil'], 1.7) self.assertEqual(production['production']['hydro'], 0.0) self.assertEqual(production['production']['solar'], 0.0) self.assertEqual(production['production']['wind'], 1.6) self.assertEqual(production['storage']['hydro'], -2.4) elif self.evening == production['datetime']: self.assertEqual(production['production']['gas'], 4.5) self.assertEqual(production['production']['oil'], 4.5) self.assertEqual(production['production']['hydro'], 0.0) self.assertEqual(production['production']['solar'], 0.0) self.assertEqual(production['production']['wind'], 0.5) self.assertEqual(production['storage']['hydro'], -3.0)
def setUp(self): self.session = Session() response = Response(1504603773) response.demand = 1000.0 response.hydraulic = 50.0 self.mocked_response = response
def test_fetch_production(self, el_hierro, gran_canaria, gomera, lanza_fuerte, palma, tene): self.empty_production = get(1514673600).datetime el_hierro.return_value = [ Response(self.morning, 10.0, 1.5, 2.0, 0.5, 2.5, 2.5, 0.4, 5.0), Response(self.afternoon, 5.6, 1.7, 0.0, 1.6, 0.0, 0.0, 0.0, 2.4), Response(self.evening, 12.0, 2.0, 2.0, 0.5, 2.5, 2.5, 0.0, 3.0), Response(self.empty_production, 12.0, 2.0, 2.0, 0.5, 2.5, 2.5, 0.0, 3.0) ] gran_canaria.return_value = [ Response(self.morning, 15.0, 1.5, 2.0, 0.5, 2.5, 2.5, 0.4, 5.0), Response(self.afternoon, 443.6, 34.7, 0.0, 33.3, 172.4, 184.5, 17.5, 0.0), Response(self.evening, 18.0, 1.5, 2.0, 0.5, 2.5, 2.5, 0.4, 5.0), Response(self.empty_production, 12.0, 2.0, 2.0, 0.5, 2.5, 2.5, 0.0, 3.0) ] gomera.return_value = [ Response(self.morning, 5.0, 1.5, 2.0, 0.5, 2.5, 2.5, 0.4, 5.0), Response(self.afternoon, 9.3, 9.3, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), Response(self.evening, 8.0, 1.5, 2.0, 0.5, 2.5, 2.5, 0.4, 5.0), Response(self.empty_production, 12.0, 2.0, 2.0, 0.5, 2.5, 2.5, 0.0, 3.0) ] lanza_fuerte.return_value = [ Response(self.morning, 25.0, 1.5, 2.0, 0.5, 2.5, 2.5, 0.4, 5.0), Response(self.afternoon, 200.1, 182.0, 12.2, 3.1, 0.0, 0.0, 5.3, 0.0), Response(self.evening, 28.0, 1.5, 2.0, 0.5, 2.5, 2.5, 0.4, 5.0), Response(self.empty_production, 12.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) ] palma.return_value = [ Response(self.morning, 30.0, 1.5, 2.0, 0.5, 2.5, 2.5, 0.4, 5.0), Response(self.afternoon, 34.7, 30.2, 0.0, 3.3, 0.0, 0.0, 2.1, 0.0), Response(self.evening, 32.0, 1.5, 2.0, 0.5, 2.5, 2.5, 0.4, 5.0), Response(self.empty_production, 12.0, 2.0, 2.0, 0.5, 2.5, 2.5, 0.0, 3.0) ] tene.return_value = [ Response(self.morning, 20.0, 1.5, 2.0, 0.5, 2.5, 2.5, 0.4, 5.0), Response(self.afternoon, 452.6, 34.9, 0.0, 28.2, 143.8, 179.2, 66.3, 0.0), Response(self.evening, 22.0, 1.5, 2.0, 0.5, 2.5, 2.5, 0.4, 5.0), Response(self.empty_production, 12.0, 2.0, 2.0, 0.5, 2.5, 2.5, 0.0, 3.0) ] data = ES_CN.fetch_production('ES-CN', self.session) self.assertIsNotNone(data) self.assertIs(len(data), 3) for production in data: self.assertEqual(production['countryCode'], 'ES-CN') self.assertEqual(production['source'], 'demanda.ree.es') self.assertIsNotNone(production['datetime']) self.assertIsNotNone(production['production']) self.assertIsNotNone(production['storage']) self.assertTrue(production['datetime'] == self.morning or production['datetime'] == self.afternoon or production['datetime'] == self.evening) if self.morning == production['datetime']: self.assertEqual(production['production']['gas'], 27.0) self.assertEqual(production['production']['oil'], 24.0) self.assertEqual(production['production']['hydro'], 25.0) self.assertEqual(production['production']['solar'], 2.4) self.assertEqual(production['production']['wind'], 3.0) self.assertEqual(production['storage']['hydro'], -5.0) elif self.afternoon == production['datetime']: self.assertEqual(production['production']['gas'], 328.4) self.assertEqual(production['production']['oil'], 656.5) self.assertEqual(production['production']['hydro'], 0.0) self.assertEqual(production['production']['solar'], 91.2) self.assertEqual(production['production']['wind'], 69.5) self.assertEqual(production['storage']['hydro'], -2.4) elif self.evening == production['datetime']: self.assertEqual(production['production']['gas'], 27.0) self.assertEqual(production['production']['oil'], 24.5) self.assertEqual(production['production']['hydro'], 25.0) self.assertEqual(production['production']['solar'], 2.0) self.assertEqual(production['production']['wind'], 3.0) self.assertEqual(production['storage']['hydro'], -3.0)
def test_fetch_consumption(self, el_hierro, gran_canaria, gomera, lanza_fuerte, palma, tene): el_hierro.return_value = [ Response(self.morning, 10.0), Response(self.afternoon, 5.6), Response(self.evening, 12.0) ] gran_canaria.return_value = [ Response(self.morning, 15.0), Response(self.afternoon, 443.6), Response(self.evening, 18.0) ] gomera.return_value = [ Response(self.morning, 5.0), Response(self.afternoon, 9.3), Response(self.evening, 8.0) ] lanza_fuerte.return_value = [ Response(self.morning, 25.0), Response(self.afternoon, 200.1), Response(self.evening, 28.0) ] palma.return_value = [ Response(self.morning, 30.0), Response(self.afternoon, 34.7), Response(self.evening, 32.0) ] tene.return_value = [ Response(self.morning, 20.0), Response(self.afternoon, 452.6), Response(self.evening, 22.0) ] data = ES_CN.fetch_consumption('ES-CN', self.session) self.assertIsNotNone(data) self.assertIs(len(data), 3) for consumption in data: self.assertEqual(consumption['countryCode'], 'ES-CN') self.assertEqual(consumption['source'], 'demanda.ree.es') self.assertIsNotNone(consumption['datetime']) self.assertTrue(consumption['datetime'] == self.morning or consumption['datetime'] == self.afternoon or consumption['datetime'] == self.evening) if self.morning == consumption['datetime']: self.assertEqual(consumption['consumption'], 105.0) elif self.afternoon == consumption['datetime']: self.assertEqual(consumption['consumption'], 1145.9) elif self.evening == consumption['datetime']: self.assertEqual(consumption['consumption'], 120.0)