def test_parse_charge_row_keyerror(self):
     """Test that parse_charge_row raises a KeyError when a field is missing"""
     charge_row = {
         "PK": 1,
         "ChargeActualName": "test_charge_name",
         "UsageUnit": "kW",
         "ChargeUnitsUsed": Decimal(200),
         "ChargeRatePerUnit": Decimal(10),
         # Exclude this field: "ChargeAmount": Decimal(100.00)
         "ThirdPartyProvider": "test_provider",
         "IntervalStart": date(2000, 2, 1),
         "IntervalEnd": date(2000, 3, 1),
     }
     with self.assertRaises(KeyError):
         UrjanetPyMySqlDataSource.parse_charge_row(charge_row)
 def test_parse_charge_row_nil_pk(self):
     """Test that parse_charge_row raises a ValueError when the primary key field is missing"""
     charge_row = {
         "PK": None,
         "ChargeActualName": "test_charge_name",
         "ChargeAmount": Decimal(100.00),
         "UsageUnit": "kW",
         "ChargeUnitsUsed": Decimal(200),
         "ChargeRatePerUnit": Decimal(10),
         "ThirdPartyProvider": "test_provider",
         "IsAdjustmentCharge": 0,
         "IntervalStart": date(2000, 2, 1),
         "IntervalEnd": date(2000, 3, 1),
     }
     with self.assertRaises(ValueError):
         UrjanetPyMySqlDataSource.parse_charge_row(charge_row)
 def test_parse_charge_row_valueerror(self):
     """Test that parse_charge_row raises a ValueError when a field has an invalid value"""
     charge_row = {
         "PK": 1,
         "ChargeActualName": "test_charge_name",
         "ChargeAmount": "not_a_decimal",  # ValueError here
         "UsageUnit": "kW",
         "ChargeUnitsUsed": Decimal(200),
         "ChargeRatePerUnit": Decimal(10),
         "ThirdPartyProvider": "test_provider",
         "IsAdjustmentCharge": 0,
         "IntervalStart": date(2000, 2, 1),
         "IntervalEnd": date(2000, 3, 1),
         "ChargeId": None,
     }
     with self.assertRaises(ValueError):
         UrjanetPyMySqlDataSource.parse_charge_row(charge_row)
Exemple #4
0
 def load_meter_charges(self, account_pk: int,
                        meter_pk: int) -> List[Charge]:
     """Fetch all charge info for a given meter"""
     query = """
         SELECT *
         FROM xmlcharge
         WHERE AccountFK=%s AND MeterFK=%s
     """
     result_set = self.fetch_all(query, account_pk, meter_pk)
     return [
         UrjanetPyMySqlDataSource.parse_charge_row(row)
         for row in result_set
     ]
 def test_parse_charge_row_no_provider(self):
     """Ensure that parse_charge_row works when ThirdPartyProvider is None"""
     charge_row = {
         "PK": 1,
         "ChargeActualName": "test_charge_name",
         "ChargeAmount": Decimal(100.00),
         "UsageUnit": "kW",
         "ChargeUnitsUsed": Decimal(200),
         "ChargeRatePerUnit": Decimal(10),
         "ThirdPartyProvider": None,
         "IsAdjustmentCharge": 0,
         "IntervalStart": date(2000, 2, 1),
         "IntervalEnd": date(2000, 3, 1),
         "ChargeId": None,
     }
     result = UrjanetPyMySqlDataSource.parse_charge_row(charge_row)
     for field in charge_row:
         self.assertEqual(getattr(result, field), charge_row[field])
 def test_parse_charge_row(self):
     """Test the basic functionality of the parse_charge_row function."""
     charge_row = {
         "PK": 1,
         "ChargeActualName": "test_charge_name",
         "ChargeAmount": Decimal(100),
         "UsageUnit": "kW",
         "ChargeUnitsUsed": Decimal(200),
         "ChargeRatePerUnit": Decimal(10),
         "ThirdPartyProvider": "test_provider",
         "IsAdjustmentCharge": 0,
         "IntervalStart": date(2000, 2, 1),
         "IntervalEnd": date(2000, 3, 1),
         "ChargeId": None,
         "__EXTRA1": "EXTRA1",  # It's okay to have extra fields
         "__EXTRA2": "EXTRA2",
     }
     result = UrjanetPyMySqlDataSource.parse_charge_row(charge_row)
     for field in charge_row:
         if field.startswith("__EXTRA"):
             with self.assertRaises(AttributeError):
                 getattr(result, field)
         else:
             self.assertEqual(getattr(result, field), charge_row[field])
Exemple #7
0
    def load_meter_charges(self, account_pk: int,
                           meter_pk: int) -> List[Charge]:
        """Fetch all charge info for a given meter

        In FPL the taxes for a bill are not stored at the 'Meter' level in Urjanet.
        Instead they are associated with the account only. This means that in order to pull
        the data properly we have to make a couple of assumptions.

        1. There can not be multiple bills in one statement, as we'd have no idea how to associate
           taxes with the right bill (the Meter in urjanet parlance is required to do that and
           in this case that is NULL)
        2. There can not be more than one meter associated with the statement. This is hard to detect
           so we're ignoring it for now.
        """
        query = """
            SELECT *
            FROM Charge
            WHERE AccountFK=%s
        """
        result_set = self.fetch_all(query, account_pk)
        return [
            UrjanetPyMySqlDataSource.parse_charge_row(row)
            for row in result_set
        ]