diff --git a/pyiso/ercot.py b/pyiso/ercot.py index 24f177d..26c9a88 100644 --- a/pyiso/ercot.py +++ b/pyiso/ercot.py @@ -28,12 +28,17 @@ def _request_report(self, report_type): report_list_soup = BeautifulSoup(report_list_contents) # find the endpoint to download + report_endpoint = None for elt in report_list_soup.find_all('tr'): label = elt.find(class_='labelOptional_ind') if label: - if label.string[-3:] == 'csv': + if 'csv' in label.string: report_endpoint = self.base_report_url + elt.a.attrs['href'] break + + # test endpoint found + if not report_endpoint: + raise ValueError('ERCOT: No report available for %s, soup:\n%s' % (report_type, report_list_soup)) # read report from zip r = requests.get(report_endpoint) diff --git a/tests/test_genmix.py b/tests/test_genmix.py index 85fc47f..83d3452 100644 --- a/tests/test_genmix.py +++ b/tests/test_genmix.py @@ -6,7 +6,7 @@ import logging -class TestGenMix(TestCase): +class TestBaseGenMix(TestCase): def setUp(self): # set up expected values from base client bc = BaseClient() @@ -47,7 +47,9 @@ def _run_test(self, ba_name, **kwargs): # return return data - + + +class TestISONEGenMix(TestBaseGenMix): def test_isne_latest(self): # basic test data = self._run_test('ISONE', latest=True) @@ -65,6 +67,8 @@ def test_isne_date_range(self): timestamps = [d['timestamp'] for d in data] self.assertGreater(len(set(timestamps)), 1) + +class TestMISOGenMix(TestBaseGenMix): def test_miso_latest(self): # basic test data = self._run_test('MISO', latest=True) @@ -73,6 +77,8 @@ def test_miso_latest(self): timestamps = [d['timestamp'] for d in data] self.assertEqual(len(set(timestamps)), 1) + +class TestSPPGenMix(TestBaseGenMix): def test_spp_latest_hr(self): # basic test data = self._run_test('SPP', latest=True, market=self.MARKET_CHOICES.hourly) @@ -128,6 +134,8 @@ def test_spp_yesterday_5min(self): self.assertEqual(dp['market'], self.MARKET_CHOICES.fivemin) self.assertEqual(dp['freq'], self.FREQUENCY_CHOICES.fivemin) + +class TestBPAGenMix(TestBaseGenMix): def test_bpa_latest(self): # basic test data = self._run_test('BPA', latest=True, market=self.MARKET_CHOICES.fivemin) @@ -161,6 +169,8 @@ def test_bpa_date_range_farpast(self): timestamps = [d['timestamp'] for d in data] self.assertGreater(len(set(timestamps)), 1) + +class TestCAISOGenMix(TestBaseGenMix): def test_caiso_date_range(self): # basic test today = datetime.today().replace(tzinfo=pytz.utc) @@ -222,6 +232,8 @@ def test_caiso_latest(self): for expfuel in expected_fuels: self.assertIn(expfuel, fuels) + +class TestERCOTGenMix(TestBaseGenMix): def test_ercot_latest(self): # before min 32, will not have wind data if datetime.now().minute >= 32: @@ -247,7 +259,18 @@ def test_ercot_latest(self): c = client_factory('ERCOT') data = c.get_generation(latest=True) self.assertEqual(len(data), 0) + + def test_request_report(self): + # get data + c = client_factory('ERCOT') + result = c._request_report('gen_hrly') + + # should be a list containing 1 dict + self.assertEqual(len(result), 1) + self.assertIn('SE_MW', result[0].keys()) + +class TestPJMGenMix(TestBaseGenMix): def test_pjm_latest(self): # basic test data = self._run_test('PJM', latest=True)