示例#1
0
def test_calculate_bill_exceptions(mocker, bill_date, member_id, account_id,
                                   expected_error):
    mocker.patch('load_readings.get_readings',
                 return_value=TEST_METER_READING_DATA)
    with pytest.raises(expected_error):
        calculate_bill(member_id=member_id,
                       account_id=account_id,
                       bill_date=bill_date)
示例#2
0
 def test_calculate_bill_for_august_2017(self):
     amount, kwh = calculate_bill(member_id='member-123',
                                  account_id='ALL',
                                  bill_date='2017-08-31')
     self.assertEqual(amount, 27.57)
     self.assertEqual(kwh, 167)
     pass
示例#3
0
 def test_compute_bill_for_two_months(self, get_readings):
     cumulative = 250
     days = 31
     get_readings.return_value = {
         "member-123": [{
             "account-abc": [{
                 "electricity": [{
                     "cumulative": 101,
                     "readingDate": "2017-07-31T00:00:00.000Z",
                     "unit": "kWh"
                 }, {
                     "cumulative": 351,
                     "readingDate": "2017-08-31T00:00:00.000Z",
                     "unit": "kWh"
                 }]
             }]
         }]
     }
     amount, kwh = bill_member.calculate_bill(member_id='member-123',
                                              account_id='electricity',
                                              bill_date='2017-08-31')
     expected_amount = TariffComputer().metric('electricity').compute(
         cumulative, days)
     self.assert_that(bill_content={
         int(amount): int(expected_amount),
         int(round(kwh)): cumulative
     })
示例#4
0
 def test_retrieve_bill_given_no_upper_bound_reading(self, get_readings):
     get_readings.return_value = {
         "member-123": [{
             "account-abc": [{
                 "electricity": [{
                     "cumulative": 101,
                     "readingDate": "2017-07-05T00:00:00.000Z",
                     "unit": "kWh"
                 }, {
                     "cumulative": 351,
                     "readingDate": "2017-08-16T00:00:00.000Z",
                     "unit": "kWh"
                 }]
             }]
         }]
     }
     amount, kwh = bill_member.calculate_bill(member_id='member-123',
                                              account_id='electricity',
                                              bill_date='2017-08-31')
     expected_amount = TariffComputer().metric('electricity').compute(
         95.23, 31)
     self.assert_that(bill_content={
         int(amount): int(expected_amount),
         int(kwh): int(95.23)
     })
    def test_one_account_wit_electricity(self):
        r = {
            'm': [
                {
                    'a': [{
                        'electricity': [{
                            'cumulative': 17759,
                            'readingDate': '2017-04-30T00:00:00.000Z',
                            'unit': 'kWh'
                        }, {
                            'cumulative': 18002,
                            'readingDate': '2017-05-31T00:00:00.000Z',
                            'unit': 'kWh'
                        }]
                    }]
                },
            ]
        }

        amount, kwh = bill_member.calculate_bill(member_id='m',
                                                 account_id='ALL',
                                                 bill_date='2017-05-31',
                                                 readings=r)

        self.assertEqual(amount,
                         36.65)  #round(31*24.56 + (18002-17759)*11.949)/100
        self.assertEqual(kwh, 243)
示例#6
0
 def test_between_years(self, get_readings):
     get_readings.return_value = {
         "member-123": [{
             "account-abc": [{
                 "electricity": [{
                     "cumulative": 19150,
                     "readingDate": "2017-11-04T00:00:00.000Z",
                     "unit": "kWh"
                 }, {
                     "cumulative": 19517,
                     "readingDate": "2017-12-31T00:00:00.000Z",
                     "unit": "kWh"
                 }, {
                     "cumulative": 19757,
                     "readingDate": "2018-01-23T00:00:00.000Z",
                     "unit": "kWh"
                 }]
             }]
         }]
     }
     amount, kwh = bill_member.calculate_bill(member_id='member-123',
                                              account_id='electricity',
                                              bill_date='2018-01-31')
     expected_amount = TariffComputer().metric('electricity').compute(
         240, 31)
     self.assert_that(bill_content={
         int(amount): int(expected_amount),
         int(kwh): int(240)
     })
示例#7
0
 def test_invalid_account_id(self):
     amount, kwh = calculate_bill(member_id='member-999',
                                  account_id='ALL',
                                  bill_date='2018-04-30')
     self.assertEqual(amount, 0.0)
     self.assertEqual(kwh, 0)
     pass
示例#8
0
 def test_calculate_bill_for_march_2017(self):
     amount, kwh = calculate_bill(member_id='member-1234',
                                  account_id='ALL',
                                  bill_date='2017-03-31')
     self.assertEqual(amount, 0.0)
     self.assertEqual(kwh, 0)
     pass
示例#9
0
def test_calculate_bill_for_month(mocker, bill_date, member_id, account_id,
                                  expected_result):
    mocker.patch('load_readings.get_readings',
                 return_value=TEST_METER_READING_DATA)
    amount, kwh = calculate_bill(member_id=member_id,
                                 account_id=account_id,
                                 bill_date=bill_date)
    assert amount == expected_result[0]
    assert kwh == expected_result[1]
示例#10
0
 def test_compute_bill_for_no_readings(self, get_readings):
     get_readings.return_value = {
         "member-123": [{
             "account-abc": [{
                 "electricity": []
             }]
         }]
     }
     amount, kwh = bill_member.calculate_bill(member_id='member-123',
                                              account_id='electricity',
                                              bill_date='2017-08-31')
     expected_amount = TariffComputer().metric('electricity').compute(0, 0)
     self.assert_that(bill_content={amount: expected_amount, kwh: 0})
示例#11
0
 def test_calculate_bill_for_september_2017(self):
     amount, kwh = calculate_bill(member_id='member-123',
                                  account_id='ALL',
                                  bill_date='2017-09-30')
     self.assertEqual(amount, 9.86)
     self.assertEqual(kwh, 62)
示例#12
0
 def test_calculate_bill_for_august(self):
     amount, kwh = calculate_bill('member-123', '2017-08-31')
     self.assertEqual(amount, 27.56843)
     self.assertEqual(kwh, 167)
示例#13
0
 def test_calculate_bill_load_readings(self, mock_get_readings):
     with self.assertRaises(Exception) as context:
         _, _ = calculate_bill('member-123', '2017-08-31')
     assert mock_get_readings.called
 def test_calculate_bill_for_invalid_account_for_unknown_month(self):
     amount, kwh = calculate_bill(member_id='member-123',
                                  account_id='account-abcd',
                                  bill_date='2022-12-31')
     self.assertEqual(amount, 0)
     self.assertEqual(kwh, 0)
 def test_calculate_bill_for_invalid_account_first_month(self):
     amount, kwh = calculate_bill(member_id='member-123',
                                  account_id='account-abcd',
                                  bill_date='2017-03-28')
     self.assertEqual(amount, 0)
     self.assertEqual(kwh, 0)
 def test_calculate_bill_for_account_abc_first_month(self):
     amount, kwh = calculate_bill(member_id='member-123',
                                  account_id='ALL',
                                  bill_date='2017-03-28')
     self.assertEqual(amount, 2107.51)
     self.assertEqual(kwh, 17580)
 def test_calculate_bill_for_ALL_unknown_month(self):
     amount, kwh = calculate_bill(member_id='member-123',
                                  account_id='ALL',
                                  bill_date='2022-12-31')
     self.assertEqual(amount, 7.61)
     self.assertEqual(kwh, 0)
示例#18
0
 def test_calculate_bill_for_october_2017(self):
     amount, kwh = calculate_bill(member_id='member-123',
                                  account_id='ALL',
                                  bill_date='2017-10-10')
     self.assertEqual(amount, 38.19)
     self.assertEqual(kwh, 223)
示例#19
0
 def test_calculate_bill_for_august(self):
     amount, kwh = bill_member.calculate_bill(member_id='member-123',
                                              account_id='ALL',
                                              bill_date='2017-08-31')
     self.assertEqual(int(amount), int(27.57))
     self.assertEqual(round(kwh), 167)
 def test_no_member_data(self):
     with self.assertRaises(bill_member.MemberNotFound):
         bill_member.calculate_bill(member_id='joe-lycett',
                                    account_id='ALL',
                                    bill_date='2017-08-31')
示例#21
0
 def test_calculate_bill_for_april_2018(self):
     amount, kwh = calculate_bill(member_id='member-123',
                                  account_id='ALL',
                                  bill_date='2018-04-30')
     self.assertEqual(amount, 50.01)
     self.assertEqual(kwh, 324)