def test_nem_charges(self): """Test that the PG&E transformer can accurately detect NEM charges""" hits = ["Total NEM Charges Before Taxes", "total nem charges before taxes"] transformer = PacificGasElectricTransformer() for hit in hits: charge = test_util.default_charge(ChargeActualName=hit) self.assertTrue(transformer.is_nem_charge(charge))
def test_adjustment_charges(self): """Test that the PG&E transformer can accurately detect correction charges""" hits = [ "01/05/2017 - 02/03/2017 26,400.000000 kWh", "01/06/2017 - 02/03/2017 1,976.000000 Therms", "01/18/2018 - 02/15/2018 53,055.720000 kWh", "04/29/2015 - 04/30/2015 7,012.000000 kWh", "10/18/2018 - 11/18/2018 78,840.000000 kWh", ] transformer = PacificGasElectricTransformer() for hit in hits: charge = test_util.default_charge(ChargeActualName=hit) self.assertTrue(transformer.is_correction_charge(charge))
def pge_fixture_test( self, input_name, expected_name, start_date=None, end_date=None ): self.fixture_test( transformer=PacificGasElectricTransformer(), input_path=os.path.join(DATA_DIR, input_name), expected_path=os.path.join(DATA_DIR, expected_name), start_date=start_date, end_date=end_date, )
def test_basic_scraper_run_no_attachments(self): """Ensure that we can run the base Urjanet scraper with simple inputs, without attachments disabled""" datasource = test_util.FixtureDataSource( os.path.join(DATA_DIR, "simple_fixture_input.json")) transformer = PacificGasElectricTransformer() config = BaseUrjanetConfiguration(datasource, transformer, "pge", False) scraper = BaseUrjanetScraper(None, None, config) self.assertEqual("Urjanet Scraper: pge", scraper.name) result = scraper._execute() self.assertEqual(expected, result.bills)
def test_urjanet_data_range_for_partial_scrapers(self): datasource = test_util.FixtureDataSource( os.path.join(DATA_DIR, "simple_fixture_input.json")) transformer = PacificGasElectricTransformer() config = BaseUrjanetConfiguration( datasource, transformer, "pge", False, partial_type=PartialBillProviderType.GENERATION_ONLY, ) date_range = DateRange(date(2020, 1, 1), date(2020, 6, 1)) scraper = BaseUrjanetScraper(None, date_range, config) result = scraper._execute() self.assertEqual( expected, result.generation_bills, "partial urjanet scrapers return whatever partial bills we find, regardless of scraped range.", )
def test_basic_scraper_run_with_multiple_attachments(self, mock_call): """Ensure that the Urjanet scraper gracefully handles a bill upload with multiple source links""" # Mock out the library that uploads to S3, returning 'test_key' as the destination s3 entity mock_call.return_value = "test_key" datasource = test_util.FixtureDataSource( os.path.join(DATA_DIR, "multi_source_link_input.json")) transformer = PacificGasElectricTransformer() config = BaseUrjanetConfiguration(datasource, transformer, "pge", True) scraper = BaseUrjanetScraper(None, None, config) result = scraper._execute() self.assertEqual(len(result.bills), 1) bill = result.bills[0] attachments = bill.attachments self.assertEqual(len(attachments), 2) for attachment in attachments: # The name of the attachment S3 key should match our mock self.assertEqual(attachment.key, "test_key") self.assertEqual(attachment.kind, "bill") self.assertEqual(attachment.format, "PDF")
def datafeed( account: SnapmeterAccount, meter: Meter, datasource: MeterDataSource, params: dict, task_id: Optional[str] = None, ) -> Status: utility_service = meter.utility_service return run_urjanet_datafeed( account, meter, datasource, params, PacificGasElectricDatasource( utility_service.utility, utility_service.utility_account_id, utility_service.service_id, utility_service.gen_utility, utility_service.gen_utility_account_id, ), PacificGasElectricTransformer(), task_id=task_id, )
def test_basic_scraper_run_with_attachments(self, mock_call): """Ensure that we can run the base Urjanet scraper with simple inputs, with attachments enabled""" # Mock out the library that uploads to S3, returning 'test_key' as the destination s3 entity mock_call.return_value = "test_key" datasource = test_util.FixtureDataSource( os.path.join(DATA_DIR, "simple_fixture_input.json")) transformer = PacificGasElectricTransformer() config = BaseUrjanetConfiguration(datasource, transformer, "pge", True) scraper = BaseUrjanetScraper(None, None, config) result = scraper._execute() self.assertEqual(len(result.bills), 1) bill = result.bills[0] # Note: the attachments are currently represented as a json-encoded list, hence the json.loads attachments = bill.attachments self.assertEqual(len(attachments), 1) attachment = attachments[0] # The name of the attachment S3 key should match our mock self.assertEqual(attachment.key, "test_key") self.assertEqual(attachment.kind, "bill") self.assertEqual(attachment.format, "PDF")
def make_transformer(self): return PacificGasElectricTransformer()