further postage progress

This commit is contained in:
stvnrlly
2023-02-10 21:29:52 -05:00
parent ff3f2c06c0
commit 4a0e555696
6 changed files with 71 additions and 245 deletions

View File

@@ -36,7 +36,6 @@ get_template_by_id_response = {
"body": {"type": "string"},
"subject": {"type": ["string", "null"]},
"name": {"type": "string"},
"postage": {"type": "string", "format": "postage"}
},
"required": ["id", "type", "created_at", "updated_at", "version", "created_by", "body", "name"],
}
@@ -64,7 +63,6 @@ post_template_preview_response = {
"version": {"type": "integer"},
"body": {"type": "string"},
"subject": {"type": ["string", "null"]},
"postage": {"type": "string", "format": "postage"},
"html": {"type": ["string", "null"]},
},
"required": ["id", "type", "version", "body"],
@@ -80,5 +78,4 @@ def create_post_template_preview_response(template, template_object):
"body": template_object.content_with_placeholders_filled_in,
"html": getattr(template_object, 'html_body', None),
"subject": getattr(template_object, 'subject', None),
"postage": template.postage
}

View File

@@ -78,6 +78,15 @@ def upgrade():
op.drop_column('templates', 'postage')
op.drop_column('templates_history', 'postage')
op.drop_column('ft_billing', 'postage')
# op.drop_constraint('ft_billing_pkey', 'ft_billing', type_='primary')
# op.create_primary_key('ft_billing_pkey', 'ft_billing', ['bst_date',
# 'template_id',
# 'service_id',
# 'notification_type',
# 'provider',
# 'rate_multiplier',
# 'international',
# 'rate'])
# ### end Alembic commands ###
@@ -89,6 +98,17 @@ def downgrade():
op.add_column('notifications', sa.Column('postage', sa.VARCHAR(), autoincrement=False, nullable=True))
op.add_column('notification_history', sa.Column('postage', sa.VARCHAR(), autoincrement=False, nullable=True))
# op.drop_constraint('ft_billing_pkey', 'ft_billing', type_='primary')
# op.create_primary_key('ft_billing_pkey', 'ft_billing', ['bst_date',
# 'template_id',
# 'service_id',
# 'notification_type',
# 'provider',
# 'rate_multiplier',
# 'international',
# 'rate',
# 'postage'])
op.execute("DROP VIEW notifications_all_time_view;")
op.execute("""
CREATE VIEW notifications_all_time_view AS

View File

@@ -127,7 +127,6 @@ def test_get_yearly_usage_by_monthly_from_ft_billing(admin_request, notify_db_se
sms_template = create_template(service=service, template_type="sms")
email_template = create_template(service=service, template_type="email")
letter_template = create_template(service=service, template_type="letter")
for dt in (date(2016, 4, 28), date(2016, 11, 10), date(2017, 2, 26)):
create_ft_billing(local_date=dt, template=sms_template, rate=0.0162)
@@ -139,23 +138,13 @@ def test_get_yearly_usage_by_monthly_from_ft_billing(admin_request, notify_db_se
year=2016
)
assert len(json_response) == 6 # 3 billed months for SMS and letters
assert len(json_response) == 3 # 3 billed months for SMS
email_rows = [row for row in json_response if row['notification_type'] == 'email']
assert len(email_rows) == 0
letter_row = next(x for x in json_response if x['notification_type'] == 'letter')
sms_row = next(x for x in json_response if x['notification_type'] == 'sms')
assert letter_row["month"] == "April"
assert letter_row["notification_type"] == "letter"
assert letter_row["chargeable_units"] == 1
assert letter_row["notifications_sent"] == 1
assert letter_row["rate"] == 0.33
assert letter_row["cost"] == 0.33
assert letter_row["free_allowance_used"] == 0
assert letter_row["charged_units"] == 1
assert sms_row["month"] == "April"
assert sms_row["notification_type"] == "sms"
assert sms_row["chargeable_units"] == 1
@@ -195,7 +184,6 @@ def test_get_yearly_billing_usage_summary_from_ft_billing(admin_request, notify_
sms_template = create_template(service=service, template_type="sms")
email_template = create_template(service=service, template_type="email")
letter_template = create_template(service=service, template_type="letter")
for dt in (date(2016, 4, 28), date(2016, 11, 10), date(2017, 2, 26)):
create_ft_billing(local_date=dt, template=sms_template, rate=0.0162)
@@ -207,7 +195,7 @@ def test_get_yearly_billing_usage_summary_from_ft_billing(admin_request, notify_
year=2016
)
assert len(json_response) == 3
assert len(json_response) == 2
assert json_response[0]['notification_type'] == 'email'
assert json_response[0]['chargeable_units'] == 0
@@ -217,18 +205,10 @@ def test_get_yearly_billing_usage_summary_from_ft_billing(admin_request, notify_
assert json_response[0]['free_allowance_used'] == 0
assert json_response[0]['charged_units'] == 0
assert json_response[1]['notification_type'] == 'letter'
assert json_response[1]['notification_type'] == 'sms'
assert json_response[1]['chargeable_units'] == 3
assert json_response[1]['notifications_sent'] == 3
assert json_response[1]['rate'] == 0.33
assert json_response[1]['cost'] == 0.99
assert json_response[1]['free_allowance_used'] == 0
assert json_response[1]['charged_units'] == 3
assert json_response[2]['notification_type'] == 'sms'
assert json_response[2]['chargeable_units'] == 3
assert json_response[2]['notifications_sent'] == 3
assert json_response[2]['rate'] == 0.0162
assert json_response[2]['cost'] == 0.0324
assert json_response[2]['free_allowance_used'] == 1
assert json_response[2]['charged_units'] == 2
assert json_response[1]['rate'] == 0.0162
assert json_response[1]['cost'] == 0.0324
assert json_response[1]['free_allowance_used'] == 1
assert json_response[1]['charged_units'] == 2

View File

@@ -363,7 +363,7 @@ def test_fetch_monthly_billing_for_year(notify_db_session):
create_annual_billing(service_id=service.id, free_sms_fragment_limit=1, financial_year_start=2016)
results = fetch_monthly_billing_for_year(service.id, 2016)
assert len(results) == 9 # 3 billed months for each type
assert len(results) == 6 # 3 billed months for each type
assert str(results[0].month) == "2016-04-01"
assert results[0].notification_type == 'email'
@@ -375,26 +375,17 @@ def test_fetch_monthly_billing_for_year(notify_db_session):
assert results[0].charged_units == 0
assert str(results[1].month) == "2016-04-01"
assert results[1].notification_type == 'letter'
assert results[1].notification_type == 'sms'
assert results[1].notifications_sent == 2
assert results[1].chargeable_units == 2
assert results[1].rate == Decimal('0.30')
assert results[1].cost == Decimal('0.60')
assert results[1].free_allowance_used == 0
assert results[1].charged_units == 2
assert str(results[2].month) == "2016-04-01"
assert results[2].notification_type == 'sms'
assert results[2].notifications_sent == 2
assert results[2].chargeable_units == 2
assert results[2].rate == Decimal('0.162')
assert results[1].rate == Decimal('0.162')
# free allowance is 1
assert results[2].cost == Decimal('0.162')
assert results[2].free_allowance_used == 1
assert results[2].charged_units == 1
assert results[1].cost == Decimal('0.162')
assert results[1].free_allowance_used == 1
assert results[1].charged_units == 1
assert str(results[3].month) == "2017-02-01"
assert str(results[8].month) == "2017-03-01"
assert str(results[2].month) == "2017-02-01"
assert str(results[5].month) == "2017-03-01"
def test_fetch_monthly_billing_for_year_variable_rates(notify_db_session):
@@ -403,45 +394,27 @@ def test_fetch_monthly_billing_for_year_variable_rates(notify_db_session):
results = fetch_monthly_billing_for_year(service.id, 2018)
# Test data is only for the month of May
assert len(results) == 4
assert len(results) == 3
assert str(results[0].month) == "2018-05-01"
assert results[0].notification_type == 'letter'
assert results[0].notification_type == 'sms'
assert results[0].notifications_sent == 1
assert results[0].chargeable_units == 1
assert results[0].rate == Decimal('0.33')
assert results[0].cost == Decimal('0.33')
assert results[0].free_allowance_used == 0
assert results[0].charged_units == 1
assert results[0].chargeable_units == 4
assert results[0].rate == Decimal('0.015')
# 1 free units on the 17th
assert results[0].cost == Decimal('0.045')
assert results[0].free_allowance_used == 1
assert results[0].charged_units == 3
assert str(results[1].month) == "2018-05-01"
assert results[1].notification_type == 'letter'
assert results[1].notification_type == 'sms'
assert results[1].notifications_sent == 2
assert results[1].chargeable_units == 2
assert results[1].rate == Decimal('0.36')
assert results[1].cost == Decimal('0.72')
assert results[1].free_allowance_used == 0
assert results[1].charged_units == 2
assert str(results[2].month) == "2018-05-01"
assert results[2].notification_type == 'sms'
assert results[2].notifications_sent == 1
assert results[2].chargeable_units == 4
assert results[2].rate == Decimal('0.015')
# 1 free units on the 17th
assert results[2].cost == Decimal('0.045')
assert results[2].free_allowance_used == 1
assert results[2].charged_units == 3
assert str(results[3].month) == "2018-05-01"
assert results[3].notification_type == 'sms'
assert results[3].notifications_sent == 2
assert results[3].chargeable_units == 5
assert results[3].rate == Decimal('0.162')
assert results[1].chargeable_units == 5
assert results[1].rate == Decimal('0.162')
# 5 free units on the 16th
assert results[3].cost == Decimal('0')
assert results[3].free_allowance_used == 5
assert results[3].charged_units == 0
assert results[1].cost == Decimal('0')
assert results[1].free_allowance_used == 5
assert results[1].charged_units == 0
@freeze_time('2018-08-01 13:30:00')
@@ -469,7 +442,7 @@ def test_fetch_billing_totals_for_year(notify_db_session):
create_annual_billing(service_id=service.id, free_sms_fragment_limit=1000, financial_year_start=2016)
results = fetch_billing_totals_for_year(service_id=service.id, year=2016)
assert len(results) == 3
assert len(results) == 2
assert results[0].notification_type == 'email'
assert results[0].notifications_sent == 4
assert results[0].chargeable_units == 0
@@ -478,21 +451,13 @@ def test_fetch_billing_totals_for_year(notify_db_session):
assert results[0].free_allowance_used == 0
assert results[0].charged_units == 0
assert results[1].notification_type == 'letter'
assert results[1].notification_type == 'sms'
assert results[1].notifications_sent == 4
assert results[1].chargeable_units == 4
assert results[1].rate == Decimal('0.3')
assert results[1].cost == Decimal('1.2')
assert results[1].free_allowance_used == 0
assert results[1].charged_units == 4
assert results[2].notification_type == 'sms'
assert results[2].notifications_sent == 4
assert results[2].chargeable_units == 4
assert results[2].rate == Decimal('0.162')
assert results[2].cost == Decimal('0')
assert results[2].free_allowance_used == 4
assert results[2].charged_units == 0
assert results[1].rate == Decimal('0.162')
assert results[1].cost == Decimal('0')
assert results[1].free_allowance_used == 4
assert results[1].charged_units == 0
def test_fetch_billing_totals_for_year_uses_current_annual_billing(notify_db_session):
@@ -515,40 +480,25 @@ def test_fetch_billing_totals_for_year_variable_rates(notify_db_session):
create_annual_billing(service_id=service.id, free_sms_fragment_limit=6, financial_year_start=2018)
results = fetch_billing_totals_for_year(service_id=service.id, year=2018)
assert len(results) == 4
assert results[0].notification_type == 'letter'
assert len(results) == 3
assert results[0].notification_type == 'sms'
assert results[0].notifications_sent == 1
assert results[0].chargeable_units == 1
assert results[0].rate == Decimal('0.33')
assert results[0].cost == Decimal('0.33')
assert results[0].free_allowance_used == 0
assert results[0].charged_units == 1
assert results[1].notification_type == 'letter'
assert results[1].notifications_sent == 2
assert results[1].chargeable_units == 2
assert results[1].rate == Decimal('0.36')
assert results[1].cost == Decimal('0.72')
assert results[1].free_allowance_used == 0
assert results[1].charged_units == 2
assert results[2].notification_type == 'sms'
assert results[2].notifications_sent == 1
assert results[2].chargeable_units == 4
assert results[2].rate == Decimal('0.015')
assert results[0].chargeable_units == 4
assert results[0].rate == Decimal('0.015')
# 1 free unit on the 17th
assert results[2].cost == Decimal('0.045')
assert results[2].free_allowance_used == 1
assert results[2].charged_units == 3
assert results[0].cost == Decimal('0.045')
assert results[0].free_allowance_used == 1
assert results[0].charged_units == 3
assert results[3].notification_type == 'sms'
assert results[3].notifications_sent == 2
assert results[3].chargeable_units == 5
assert results[3].rate == Decimal('0.162')
assert results[1].notification_type == 'sms'
assert results[1].notifications_sent == 2
assert results[1].chargeable_units == 5
assert results[1].rate == Decimal('0.162')
# 5 free units on the 16th
assert results[3].cost == Decimal('0')
assert results[3].free_allowance_used == 5
assert results[3].charged_units == 0
assert results[1].cost == Decimal('0')
assert results[1].free_allowance_used == 5
assert results[1].charged_units == 0
def test_delete_billing_data(notify_db_session):
@@ -713,72 +663,6 @@ def test_fetch_sms_billing_for_all_services_without_an_organisation_appears(noti
assert [dict(result) for result in results] == expected_results
def test_fetch_letter_costs_and_totals_for_all_services(notify_db_session):
fixtures = set_up_usage_data(datetime(2019, 6, 1))
results = fetch_letter_costs_and_totals_for_all_services(datetime(2019, 6, 1), datetime(2019, 9, 30))
assert len(results) == 3
assert results[0] == (
fixtures["org_1"].name, fixtures["org_1"].id,
fixtures["service_1_sms_and_letter"].name, fixtures["service_1_sms_and_letter"].id,
8, Decimal('3.40')
)
assert results[1] == (
fixtures["org_for_service_with_letters"].name, fixtures["org_for_service_with_letters"].id,
fixtures["service_with_letters"].name, fixtures["service_with_letters"].id,
22, Decimal('14.00')
)
assert results[2] == (
None, None,
fixtures["service_with_letters_without_org"].name, fixtures["service_with_letters_without_org"].id,
18, Decimal('24.45')
)
def test_fetch_letter_line_items_for_all_service(notify_db_session):
fixtures = set_up_usage_data(datetime(2019, 6, 1))
results = fetch_letter_line_items_for_all_services(datetime(2019, 6, 1), datetime(2019, 9, 30))
assert len(results) == 7
assert results[0] == (
fixtures["org_1"].name, fixtures["org_1"].id,
fixtures["service_1_sms_and_letter"].name, fixtures["service_1_sms_and_letter"].id,
Decimal('0.45'), 'second', 6
)
assert results[1] == (
fixtures["org_1"].name, fixtures["org_1"].id,
fixtures["service_1_sms_and_letter"].name, fixtures["service_1_sms_and_letter"].id,
Decimal("0.35"), 'first', 2
)
assert results[2] == (
fixtures["org_for_service_with_letters"].name, fixtures["org_for_service_with_letters"].id,
fixtures["service_with_letters"].name, fixtures["service_with_letters"].id,
Decimal("0.65"), 'second', 20
)
assert results[3] == (
fixtures["org_for_service_with_letters"].name, fixtures["org_for_service_with_letters"].id,
fixtures["service_with_letters"].name, fixtures["service_with_letters"].id,
Decimal("0.50"), 'first', 2
)
assert results[4] == (
None, None,
fixtures["service_with_letters_without_org"].name, fixtures["service_with_letters_without_org"].id,
Decimal("0.35"), 'second', 2
)
assert results[5] == (
None, None,
fixtures["service_with_letters_without_org"].name, fixtures["service_with_letters_without_org"].id,
Decimal("0.50"), 'first', 1
)
assert results[6] == (
None, None,
fixtures["service_with_letters_without_org"].name, fixtures["service_with_letters_without_org"].id,
Decimal("1.55"), 'international', 15
)
@freeze_time('2019-06-01 13:30')
def test_fetch_usage_year_for_organisation(notify_db_session):
fixtures = set_up_usage_data(datetime(2019, 5, 1))

View File

@@ -190,23 +190,6 @@ def test_notification_subject_fills_in_placeholders(sample_service, template_typ
assert notification.subject == 'hello'
def test_letter_notification_serializes_with_address(client, sample_letter_notification):
sample_letter_notification.personalisation = {
'address_line_1': 'foo',
'address_line_3': 'bar',
'address_line_5': None,
'postcode': 'SW1 1AA'
}
res = sample_letter_notification.serialize()
assert res['line_1'] == 'foo'
assert res['line_2'] is None
assert res['line_3'] == 'bar'
assert res['line_4'] is None
assert res['line_5'] is None
assert res['line_6'] is None
assert res['postcode'] == 'SW1 1AA'
def test_notification_serializes_created_by_name_with_no_created_by_id(client, sample_notification):
res = sample_notification.serialize()
assert res['created_by_name'] is None
@@ -228,11 +211,6 @@ def test_email_notification_serializes_with_subject(client, sample_email_templat
assert res['subject'] == 'Email Subject'
def test_letter_notification_serializes_with_subject(client, sample_letter_template):
res = sample_letter_template.serialize_for_v2()
assert res['subject'] == 'Template subject'
def test_notification_references_template_history(client, sample_template):
noti = create_notification(sample_template)
sample_template.version = 3
@@ -279,42 +257,11 @@ def test_service_get_default_reply_to_email_address(sample_service):
assert sample_service.get_default_reply_to_email_address() == 'default@email.com'
def test_service_get_default_contact_letter(sample_service):
create_letter_contact(service=sample_service, contact_block='London,\nNW1A 1AA')
assert sample_service.get_default_letter_contact() == 'London,\nNW1A 1AA'
def test_service_get_default_sms_sender(notify_db_session):
service = create_service()
assert service.get_default_sms_sender() == 'testing'
def test_letter_notification_serializes_correctly(client, sample_letter_notification):
sample_letter_notification.personalisation = {
'addressline1': 'test',
'addressline2': 'London',
'postcode': 'N1',
}
json = sample_letter_notification.serialize()
assert json['line_1'] == 'test'
assert json['line_2'] == 'London'
assert json['postcode'] == 'N1'
def test_letter_notification_postcode_can_be_null_for_precompiled_letters(client, sample_letter_notification):
sample_letter_notification.personalisation = {
'address_line_1': 'test',
'address_line_2': 'London',
}
json = sample_letter_notification.serialize()
assert json['line_1'] == 'test'
assert json['line_2'] == 'London'
assert json['postcode'] is None
def test_template_folder_is_parent(sample_service):
x = None
folders = []

View File

@@ -96,10 +96,8 @@ def test_valid_post_template_returns_200(
assert resp_json['id'] == str(template.id)
if tmp_type in {EMAIL_TYPE, LETTER_TYPE}:
assert expected_subject in resp_json['subject']
if tmp_type == EMAIL_TYPE:
assert expected_subject in resp_json['subject']
assert resp_json['html'] == expected_html
else:
assert resp_json['html'] is None