mirror of
https://github.com/GSA/notifications-api.git
synced 2026-05-27 09:28:03 -04:00
Migration to add international letter rates
New rows giving the prices of letters with a post_class of `europe` and `rest-of-world` have been added to the `letter_rates` table. All rates are currently the same for international letters.
This commit is contained in:
54
migrations/versions/0324_int_letter_rates.py
Normal file
54
migrations/versions/0324_int_letter_rates.py
Normal file
@@ -0,0 +1,54 @@
|
||||
"""
|
||||
|
||||
Revision ID: 0324_int_letter_rates
|
||||
Revises: 0323_broadcast_message
|
||||
Create Date: 2020-07-08 12:20:20.700128
|
||||
|
||||
"""
|
||||
import itertools
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
from alembic import op
|
||||
from sqlalchemy.sql import text
|
||||
|
||||
from app.models import LetterRate
|
||||
|
||||
|
||||
revision = '0324_int_letter_rates'
|
||||
down_revision = '0323_broadcast_message'
|
||||
|
||||
base_rate = 76
|
||||
start_date = datetime(2020, 7, 1, 0, 0)
|
||||
|
||||
|
||||
def upgrade():
|
||||
"""
|
||||
Insert these letter rates for a post_class of both `europe` and `rest-of-world`:
|
||||
1 sheet - £0.84
|
||||
2 sheets - £0.92
|
||||
3 sheets - £1.00
|
||||
4 sheets - £1.08
|
||||
5 sheets - £1.16
|
||||
"""
|
||||
op.bulk_insert(LetterRate.__table__, [
|
||||
{
|
||||
'id': uuid.uuid4(),
|
||||
'start_date': start_date,
|
||||
'end_date': None,
|
||||
'sheet_count': sheet_count,
|
||||
'rate': (base_rate + (8 * sheet_count)) / 100.0,
|
||||
'crown': crown,
|
||||
'post_class': post_class,
|
||||
}
|
||||
for sheet_count, crown, post_class in itertools.product(
|
||||
range(1, 6),
|
||||
[True, False],
|
||||
['europe', 'rest-of-world']
|
||||
)
|
||||
])
|
||||
|
||||
|
||||
def downgrade():
|
||||
conn = op.get_bind()
|
||||
conn.execute(text("DELETE FROM letter_rates WHERE start_date = :start"), start=start_date)
|
||||
@@ -243,6 +243,22 @@ def test_create_nightly_billing_for_day_different_letter_postage(
|
||||
billable_units=2,
|
||||
postage='second'
|
||||
)
|
||||
create_notification(
|
||||
created_at=yesterday,
|
||||
template=sample_letter_template,
|
||||
status='delivered',
|
||||
sent_by='dvla',
|
||||
billable_units=1,
|
||||
postage='europe'
|
||||
)
|
||||
create_notification(
|
||||
created_at=yesterday,
|
||||
template=sample_letter_template,
|
||||
status='delivered',
|
||||
sent_by='dvla',
|
||||
billable_units=3,
|
||||
postage='rest-of-world'
|
||||
)
|
||||
|
||||
records = FactBilling.query.all()
|
||||
assert len(records) == 0
|
||||
@@ -251,18 +267,31 @@ def test_create_nightly_billing_for_day_different_letter_postage(
|
||||
create_nightly_billing_for_day(yesterday_str)
|
||||
|
||||
records = FactBilling.query.order_by('postage').all()
|
||||
assert len(records) == 2
|
||||
assert len(records) == 4
|
||||
|
||||
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[0].postage == 'europe'
|
||||
assert records[0].notifications_sent == 1
|
||||
assert records[0].billable_units == 1
|
||||
|
||||
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
|
||||
assert records[1].postage == 'first'
|
||||
assert records[1].notifications_sent == 2
|
||||
assert records[1].billable_units == 4
|
||||
|
||||
assert records[2].notification_type == LETTER_TYPE
|
||||
assert records[2].bst_date == datetime.date(yesterday)
|
||||
assert records[2].postage == 'rest-of-world'
|
||||
assert records[2].notifications_sent == 1
|
||||
assert records[2].billable_units == 3
|
||||
|
||||
assert records[3].notification_type == LETTER_TYPE
|
||||
assert records[3].bst_date == datetime.date(yesterday)
|
||||
assert records[3].postage == 'second'
|
||||
assert records[3].notifications_sent == 1
|
||||
assert records[3].billable_units == 2
|
||||
|
||||
|
||||
def test_create_nightly_billing_for_day_letter(
|
||||
|
||||
@@ -326,10 +326,12 @@ def test_get_rates_for_billing(notify_db_session):
|
||||
create_rate(start_date=datetime.utcnow(), value=33, notification_type='email')
|
||||
create_letter_rate(start_date=datetime.utcnow(), rate=0.66, post_class='first')
|
||||
create_letter_rate(start_date=datetime.utcnow(), rate=0.33, post_class='second')
|
||||
create_letter_rate(start_date=datetime.utcnow(), rate=0.84, post_class='europe')
|
||||
create_letter_rate(start_date=datetime.utcnow(), rate=0.84, post_class='rest-of-world')
|
||||
non_letter_rates, letter_rates = get_rates_for_billing()
|
||||
|
||||
assert len(non_letter_rates) == 3
|
||||
assert len(letter_rates) == 2
|
||||
assert len(letter_rates) == 4
|
||||
|
||||
|
||||
@freeze_time('2017-06-01 12:00')
|
||||
@@ -353,10 +355,17 @@ def test_get_rate(notify_db_session):
|
||||
assert letter_rate == Decimal('0.3')
|
||||
|
||||
|
||||
@pytest.mark.parametrize("letter_post_class,expected_rate", [("first", "0.61"), ("second", "0.35")])
|
||||
@pytest.mark.parametrize("letter_post_class,expected_rate", [
|
||||
("first", "0.61"),
|
||||
("second", "0.35"),
|
||||
("europe", "0.92"),
|
||||
("rest-of-world", "1.05"),
|
||||
])
|
||||
def test_get_rate_filters_letters_by_post_class(notify_db_session, letter_post_class, expected_rate):
|
||||
create_letter_rate(start_date=datetime(2017, 5, 30, 23, 0), sheet_count=2, rate=0.61, post_class='first')
|
||||
create_letter_rate(start_date=datetime(2017, 5, 30, 23, 0), sheet_count=2, rate=0.35, post_class='second')
|
||||
create_letter_rate(start_date=datetime(2017, 5, 30, 23, 0), sheet_count=2, rate=0.92, post_class='europe')
|
||||
create_letter_rate(start_date=datetime(2017, 5, 30, 23, 0), sheet_count=2, rate=1.05, post_class='rest-of-world')
|
||||
|
||||
non_letter_rates, letter_rates = get_rates_for_billing()
|
||||
rate = get_rate(non_letter_rates, letter_rates, "letter", datetime(2018, 10, 1), True, 2, letter_post_class)
|
||||
|
||||
Reference in New Issue
Block a user