mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 15:31:15 -05:00
Update ft_billing with real postage data
* Changed update_fact_billing DAO function to update the table with the real data for postage instead of hard-coding in 'second'. * Added a test for the create nightly billing task to test that rows with different postage are being inserted correctly.
This commit is contained in:
@@ -237,7 +237,7 @@ def update_fact_billing(data, process_day):
|
||||
process_day,
|
||||
data.crown,
|
||||
data.letter_page_count,
|
||||
"second")
|
||||
data.postage)
|
||||
billing_record = create_billing_record(data, rate, process_day)
|
||||
table = FactBilling.__table__
|
||||
'''
|
||||
|
||||
@@ -177,6 +177,52 @@ def test_create_nightly_billing_different_sent_by(
|
||||
assert record.rate_multiplier == 1.0
|
||||
|
||||
|
||||
def test_create_nightly_billing_different_letter_postage(
|
||||
notify_db_session,
|
||||
sample_letter_template,
|
||||
mocker):
|
||||
yesterday = datetime.now() - timedelta(days=1)
|
||||
mocker.patch('app.dao.fact_billing_dao.get_rate', side_effect=mocker_get_rate)
|
||||
|
||||
for i in range(2):
|
||||
create_notification(
|
||||
created_at=yesterday,
|
||||
template=sample_letter_template,
|
||||
status='delivered',
|
||||
sent_by='dvla',
|
||||
billable_units=2,
|
||||
postage='first'
|
||||
)
|
||||
create_notification(
|
||||
created_at=yesterday,
|
||||
template=sample_letter_template,
|
||||
status='delivered',
|
||||
sent_by='dvla',
|
||||
billable_units=2,
|
||||
postage='second'
|
||||
)
|
||||
|
||||
records = FactBilling.query.all()
|
||||
assert len(records) == 0
|
||||
# Celery expects the arguments to be a string or primitive type.
|
||||
yesterday_str = datetime.strftime(yesterday, "%Y-%m-%d")
|
||||
create_nightly_billing(yesterday_str)
|
||||
|
||||
records = FactBilling.query.order_by('postage').all()
|
||||
assert len(records) == 2
|
||||
assert records[0].notification_type == LETTER_TYPE
|
||||
assert records[0].bst_date == datetime.date(yesterday)
|
||||
assert records[0].postage == 'first'
|
||||
assert records[0].notifications_sent == 2
|
||||
assert records[0].billable_units == 4
|
||||
|
||||
assert records[1].notification_type == LETTER_TYPE
|
||||
assert records[1].bst_date == datetime.date(yesterday)
|
||||
assert records[1].postage == 'second'
|
||||
assert records[1].notifications_sent == 1
|
||||
assert records[1].billable_units == 2
|
||||
|
||||
|
||||
def test_create_nightly_billing_letter(
|
||||
sample_service,
|
||||
sample_letter_template,
|
||||
|
||||
Reference in New Issue
Block a user