Exemplo n.º 1
0
 def test_bill_parse_04(self):
     actual = pacific_power.parse_bill_pdf(
         self.data["pacific_power_test_03.pdf"], "78585187")
     expected = BillingDatum(
         start=date(2019, 5, 31),
         end=date(2019, 6, 30),
         statement=date(2019, 7, 18),
         cost=185.86,
         used=0.0,
         peak=5.0,
         items=None,
         attachments=None,
         utility_code="Schedule 28",
     )
     self.assertEqual(expected, actual)
Exemplo n.º 2
0
 def test_bill_parse_05(self):
     actual = pacific_power.parse_bill_pdf(
         self.data["pacific_power_test_04.pdf"], "13714552")
     expected = BillingDatum(
         start=date(2017, 2, 1),
         end=date(2017, 3, 1),
         statement=date(2017, 3, 9),
         cost=780622.38,
         used=8271000.0 + 6061000.0,
         peak=35767.0,
         items=None,
         attachments=None,
         utility_code="Schedule 748",
     )
     self.assertEqual(expected, actual)
Exemplo n.º 3
0
 def test_bill_parse_02(self):
     actual = pacific_power.parse_bill_pdf(
         self.data["pacific_power_test_01.pdf"], "66887643")
     expected = BillingDatum(
         start=date(2019, 6, 3),
         end=date(2019, 7, 2),
         statement=date(2019, 7, 10),
         cost=732.86,
         used=6972.0,
         peak=26.0,
         items=None,
         attachments=None,
         utility_code="Schedule 28",
     )
     self.assertEqual(expected, actual)
Exemplo n.º 4
0
 def test_bill_parse_01(self):
     actual = pacific_power.parse_bill_pdf(
         self.data["pacific_power_test_01.pdf"], "13714552")
     expected = BillingDatum(
         start=date(2019, 6, 1),
         end=date(2019, 7, 1),
         statement=date(2019, 7, 10),
         cost=850402.64,
         used=11300000 + 9143000,
         peak=29960,
         items=None,
         attachments=None,
         utility_code="Schedule 748",
     )
     self.assertEqual(expected, actual)
Exemplo n.º 5
0
 def test_bill_parse_07(self):
     actual = pacific_power.parse_bill_pdf(
         self.data["pacific_power_test_06.pdf"], "13714552")
     expected = BillingDatum(
         start=date(2017, 12, 1),
         end=date(2018, 1, 1),
         statement=date(2018, 1, 12),
         cost=914721.55,
         used=10616000.0 + 9113000.0,
         peak=27278.0,
         items=None,
         attachments=None,
         utility_code="Schedule 748",
     )
     self.assertEqual(expected, actual)
Exemplo n.º 6
0
 def test_bill_parse_06(self):
     actual = pacific_power.parse_bill_pdf(
         self.data["pacific_power_test_05.pdf"], "66887643")
     expected = BillingDatum(
         start=date(2017, 7, 3),
         end=date(2017, 8, 2),
         statement=date(2017, 8, 7),
         cost=222.02,
         used=1846,
         peak=11,
         items=None,
         attachments=None,
         utility_code="Schedule 23",
     )
     self.assertEqual(expected, actual)
Exemplo n.º 7
0
 def test_bill_parse_03(self):
     """If the statement date cannot be determined, default to the bill's end-date."""
     actual = pacific_power.parse_bill_pdf(
         self.data["pacific_power_test_02.pdf"], "78534175")
     expected = BillingDatum(
         start=date(2019, 2, 16),
         end=date(2019, 3, 15),
         statement=date(2019, 3, 15),
         cost=469.03,
         used=4471.0,
         peak=12.0,
         items=None,
         attachments=None,
         utility_code="Schedule 23",
     )
     self.assertEqual(expected, actual)
Exemplo n.º 8
0
 def test_bill_parse_08(self):
     """Verify utility code extraction from a multi-meter bill."""
     actual = pacific_power.parse_bill_pdf(
         self.data["pacific_power_test_07.pdf"], "38650731")
     expected = BillingDatum(
         start=date(2021, 1, 31),
         end=date(2021, 2, 28),
         statement=date(2021, 3, 12),
         cost=152127.79,
         used=21609000.0,
         peak=34904.0,
         items=None,
         attachments=None,
         utility_code="Schedule 848",
     )
     self.assertEqual(expected, actual)
    def _execute(self):
        if self.end_date - self.start_date < timedelta(days=MINIMUM_BILL_DAYS):
            log.info(
                f"Expanding date range to a minimum of {MINIMUM_BILL_DAYS} days."
            )
            self.start_date = self.end_date - timedelta(days=MINIMUM_BILL_DAYS)

        start_date = max(self.start_date,
                         (datetime.now() - relativedelta(years=10)).date())
        end_date = min(self.end_date, (datetime.now().date()))

        log.info("Final date range to search: %s - %s" %
                 (start_date, end_date))

        login_page = LoginPage(self._driver)
        home_page = login_page.login(self.username, self.password)
        self.screenshot("home_screen")
        log.info("Login successful.")

        bill_history_page = home_page.to_bill_history()
        self.screenshot("bill_history_page")
        log.info("Loaded bill history.")

        bill_history_page.select_account(self.account_number)
        self.screenshot("account_selected")
        log.info("Selected account.")

        bill_history_page.set_dates(start_date, end_date)
        self.screenshot("dates_selected")
        log.info("Selected dates.")

        raw_pdfs = bill_history_page.gather_data()

        log.info("PDF bills captured: %s" % len(raw_pdfs))
        log.info("Net bill pdf bytes captured: %s" %
                 (sum(len(x) for x in raw_pdfs)))

        ii = 0
        bill_data = []
        for b in raw_pdfs:
            ii += 1
            bill_datum = parse_bill_pdf(BytesIO(b), self.meter_number)

            if bill_datum is None:
                log.info("There was a problem parsing a bill PDF #%d." % ii)
                continue

            attachment_entry = None
            if config.enabled("S3_BILL_UPLOAD"):
                key = bill_upload.hash_bill_datum(self.meter_number,
                                                  bill_datum)
                attachment_entry = bill_upload.upload_bill_to_s3(
                    BytesIO(b),
                    key,
                    source="pacificpower.net",
                    statement=bill_datum.statement,
                    utility=self.utility,
                    utility_account_id=self.account_number,
                )

            if attachment_entry:
                bill_data.append(
                    bill_datum._replace(attachments=[attachment_entry]))
            else:
                bill_data.append(bill_datum)

        final_bills = adjust_bill_dates(bill_data)
        show_bill_summary(final_bills, "Final Bill Summary")
        return Results(bills=final_bills)