From ddfc72253729123abcb16b64095dadca0ce8d9ad Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Wed, 25 Sep 2019 16:33:53 +0100 Subject: [PATCH 1/2] letter rates go up by 5p as of 1st october 2019 --- .../versions/0306_letter_rates_price_rise.py | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 migrations/versions/0306_letter_rates_price_rise.py diff --git a/migrations/versions/0306_letter_rates_price_rise.py b/migrations/versions/0306_letter_rates_price_rise.py new file mode 100644 index 000000000..892b0b7c3 --- /dev/null +++ b/migrations/versions/0306_letter_rates_price_rise.py @@ -0,0 +1,70 @@ +""" +All prices going up 5p + +1 sheet (double-sided) increases from 30p to 35p (plus VAT) +2 sheets (double-sided) increases from 35p to 40p (plus VAT) +3 sheets (double-sided) increases from 40p to 45p (plus VAT) +4 sheets (double-sided) increases from 45p to 50p (plus VAT) +5 sheets (double-sided) increases from 50p to 55p (plus VAT) +First class letters: + +1 sheet (double-sided) increases from 56p to 61p (plus VAT) +2 sheets (double-sided) increases from 61p to 66p (plus VAT) +3 sheets (double-sided) increases from 66p to 71p (plus VAT) +4 sheets (double-sided) increases from 71p to 76p (plus VAT) +5 sheets (double-sided) increases from 76p to 81p (plus VAT) + +Revision ID: 0306_letter_rates_price_rise +Revises: 0305_add_gp_org_type +Create Date: 2019-09-25 15:43:09.388251 + +""" +import itertools +import uuid +from datetime import datetime + +from alembic import op +from sqlalchemy.sql import text + +from app.models import LetterRate + + +revision = '0306_letter_rates_price_rise' +down_revision = '0305_add_gp_org_type' + + +CHANGEOVER_DATE = datetime(2019, 9, 30, 23, 0) + + +def upgrade(): + # all old rates are going in the bin + conn = op.get_bind() + conn.execute(text("UPDATE letter_rates SET end_date = :start WHERE end_date IS NULL"), start=CHANGEOVER_DATE) + + base_prices = { + 'second': 30, + 'first': 56, + } + op.bulk_insert(LetterRate.__table__, [ + { + 'id': uuid.uuid4(), + 'start_date': CHANGEOVER_DATE, + 'end_date': None, + 'sheet_count': sheet_count, + 'rate': (base_prices[post_class] + (5 * sheet_count)) / 100.0, + 'crown': crown, + 'post_class': post_class, + } + for sheet_count, crown, post_class in itertools.product( + range(1, 6), + [True, False], + ['first', 'second'] + ) + ]) + + +def downgrade(): + # Make sure you've thought about billing implications etc before downgrading! + conn = op.get_bind() + conn.execute(text("DELETE FROM letter_rates WHERE start_date = :start"), start=CHANGEOVER_DATE) + conn.execute(text("UPDATE letter_rates SET end_date = NULL WHERE end_date = :start"), start=CHANGEOVER_DATE) From d4c2a2b284f4487797fb1491b522eaca66a0f332 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Thu, 26 Sep 2019 11:54:22 +0100 Subject: [PATCH 2/2] fix failing test it failed after 5:30pm. pin the time to 4am, when the task actually runs --- .../test_notification_dao_delete_notifications.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/app/dao/notification_dao/test_notification_dao_delete_notifications.py b/tests/app/dao/notification_dao/test_notification_dao_delete_notifications.py index a1b80c750..8856defc8 100644 --- a/tests/app/dao/notification_dao/test_notification_dao_delete_notifications.py +++ b/tests/app/dao/notification_dao/test_notification_dao_delete_notifications.py @@ -132,6 +132,7 @@ def test_delete_notifications_for_days_of_retention(sample_service, notification mock_get_s3.assert_not_called() +@freeze_time('2019-09-01 04:30') def test_delete_notifications_deletes_letters_from_s3(sample_letter_template, mocker): mock_get_s3 = mocker.patch("app.dao.notifications_dao.get_s3_bucket_objects") eight_days_ago = datetime.utcnow() - timedelta(days=8)