mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-19 05:58:53 -04:00
remove post_class and letterrate model
This commit is contained in:
@@ -26,7 +26,6 @@ from app.models import (
|
||||
Notification,
|
||||
)
|
||||
from tests.app.db import (
|
||||
create_letter_rate,
|
||||
create_notification,
|
||||
create_notification_history,
|
||||
create_rate,
|
||||
@@ -36,11 +35,9 @@ from tests.app.db import (
|
||||
|
||||
|
||||
def mocker_get_rate(
|
||||
non_letter_rates, letter_rates, notification_type, local_date, crown=None, rate_multiplier=None, post_class="second"
|
||||
non_letter_rates, notification_type, local_date, crown=None, rate_multiplier=None
|
||||
):
|
||||
if notification_type == LETTER_TYPE:
|
||||
return Decimal(2.1)
|
||||
elif notification_type == SMS_TYPE:
|
||||
if notification_type == SMS_TYPE:
|
||||
return Decimal(1.33)
|
||||
elif notification_type == EMAIL_TYPE:
|
||||
return Decimal(0)
|
||||
@@ -324,38 +321,16 @@ def test_create_nightly_billing_for_day_null_sent_by_sms(
|
||||
assert record.provider == 'unknown'
|
||||
|
||||
|
||||
def test_get_rate_for_letter_latest(notify_db_session):
|
||||
# letter rates should be passed into the get_rate function as a tuple of start_date, crown, sheet_count,
|
||||
# rate and post_class
|
||||
new = create_letter_rate(datetime(2017, 12, 1), crown=True, sheet_count=1, rate=0.33, post_class='second')
|
||||
old = create_letter_rate(datetime(2016, 12, 1), crown=True, sheet_count=1, rate=0.30, post_class='second')
|
||||
letter_rates = [new, old]
|
||||
|
||||
rate = get_rate([], letter_rates, LETTER_TYPE, date(2018, 1, 1), True, 1)
|
||||
assert rate == Decimal('0.33')
|
||||
|
||||
|
||||
def test_get_rate_for_letter_latest_if_crown_is_none(notify_db_session):
|
||||
# letter rates should be passed into the get_rate function as a tuple of start_date, crown, sheet_count,
|
||||
# rate and post_class
|
||||
crown = create_letter_rate(datetime(2017, 12, 1), crown=True, sheet_count=1, rate=0.33, post_class='second')
|
||||
non_crown = create_letter_rate(datetime(2017, 12, 1), crown=False, sheet_count=1, rate=0.35, post_class='second')
|
||||
letter_rates = [crown, non_crown]
|
||||
|
||||
rate = get_rate([], letter_rates, LETTER_TYPE, date(2018, 1, 1), crown=None, letter_page_count=1)
|
||||
assert rate == Decimal('0.33')
|
||||
|
||||
|
||||
def test_get_rate_for_sms_and_email(notify_db_session):
|
||||
non_letter_rates = [
|
||||
create_rate(datetime(2017, 12, 1), 0.15, SMS_TYPE),
|
||||
create_rate(datetime(2017, 12, 1), 0, EMAIL_TYPE)
|
||||
]
|
||||
|
||||
rate = get_rate(non_letter_rates, [], SMS_TYPE, date(2018, 1, 1))
|
||||
rate = get_rate(non_letter_rates, SMS_TYPE, date(2018, 1, 1))
|
||||
assert rate == Decimal(0.15)
|
||||
|
||||
rate = get_rate(non_letter_rates, [], EMAIL_TYPE, date(2018, 1, 1))
|
||||
rate = get_rate(non_letter_rates, EMAIL_TYPE, date(2018, 1, 1))
|
||||
assert rate == Decimal(0)
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ from app.models import NOTIFICATION_STATUS_TYPES, FactBilling
|
||||
from tests.app.db import (
|
||||
create_annual_billing,
|
||||
create_ft_billing,
|
||||
create_letter_rate,
|
||||
create_notification,
|
||||
create_notification_history,
|
||||
create_organisation,
|
||||
@@ -288,14 +287,9 @@ def test_get_rates_for_billing(notify_db_session):
|
||||
create_rate(start_date=datetime.utcnow(), value=12, notification_type='email')
|
||||
create_rate(start_date=datetime.utcnow(), value=22, notification_type='sms')
|
||||
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()
|
||||
rates = get_rates_for_billing()
|
||||
|
||||
assert len(non_letter_rates) == 3
|
||||
assert len(letter_rates) == 4
|
||||
assert len(rates) == 2
|
||||
|
||||
|
||||
@freeze_time('2017-06-01 12:00')
|
||||
@@ -303,57 +297,21 @@ def test_get_rate(notify_db_session):
|
||||
create_rate(start_date=datetime(2017, 5, 30, 23, 0), value=1.2, notification_type='email')
|
||||
create_rate(start_date=datetime(2017, 5, 30, 23, 0), value=2.2, notification_type='sms')
|
||||
create_rate(start_date=datetime(2017, 5, 30, 23, 0), value=3.3, notification_type='email')
|
||||
create_letter_rate(start_date=datetime(2017, 5, 30, 23, 0), rate=0.66, post_class='first')
|
||||
create_letter_rate(start_date=datetime(2017, 5, 30, 23, 0), rate=0.3, post_class='second')
|
||||
|
||||
non_letter_rates, letter_rates = get_rates_for_billing()
|
||||
rate = get_rate(non_letter_rates=non_letter_rates, letter_rates=letter_rates, notification_type='sms',
|
||||
date=date(2017, 6, 1))
|
||||
letter_rate = get_rate(non_letter_rates=non_letter_rates, letter_rates=letter_rates,
|
||||
notification_type='letter',
|
||||
crown=True,
|
||||
letter_page_count=1,
|
||||
date=date(2017, 6, 1))
|
||||
rates = get_rates_for_billing()
|
||||
rate = get_rate(rates, notification_type='sms', date=date(2017, 6, 1))
|
||||
|
||||
assert rate == 2.2
|
||||
assert letter_rate == Decimal('0.3')
|
||||
|
||||
|
||||
@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)
|
||||
assert rate == Decimal(expected_rate)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("date,expected_rate", [(datetime(2018, 9, 30), '0.33'), (datetime(2018, 10, 1), '0.35')])
|
||||
@pytest.mark.parametrize("date,expected_rate", [(datetime(2018, 9, 30), 1.2), (datetime(2018, 10, 1), 2.2)])
|
||||
def test_get_rate_chooses_right_rate_depending_on_date(notify_db_session, date, expected_rate):
|
||||
create_letter_rate(start_date=datetime(2016, 1, 1, 0, 0), sheet_count=2, rate=0.33, post_class='second')
|
||||
create_letter_rate(start_date=datetime(2018, 9, 30, 23, 0), sheet_count=2, rate=0.35, post_class='second')
|
||||
create_rate(start_date=datetime(2016, 1, 1, 0, 0), value=1.2, notification_type='sms')
|
||||
create_rate(start_date=datetime(2018, 9, 30, 23, 0), value=2.2, notification_type='sms')
|
||||
|
||||
non_letter_rates, letter_rates = get_rates_for_billing()
|
||||
rate = get_rate(non_letter_rates, letter_rates, "letter", date, True, 2, "second")
|
||||
assert rate == Decimal(expected_rate)
|
||||
|
||||
|
||||
def test_get_rate_for_letters_when_page_count_is_zero(notify_db_session):
|
||||
non_letter_rates, letter_rates = get_rates_for_billing()
|
||||
letter_rate = get_rate(non_letter_rates=non_letter_rates, letter_rates=letter_rates,
|
||||
notification_type='letter',
|
||||
crown=True,
|
||||
letter_page_count=0,
|
||||
date=datetime.utcnow())
|
||||
assert letter_rate == 0
|
||||
rates = get_rates_for_billing()
|
||||
rate = get_rate(rates, "sms", date, True)
|
||||
assert rate == expected_rate
|
||||
|
||||
|
||||
def test_fetch_monthly_billing_for_year(notify_db_session):
|
||||
@@ -709,7 +667,6 @@ def test_fetch_usage_year_for_organisation(notify_db_session):
|
||||
|
||||
|
||||
def test_fetch_usage_year_for_organisation_populates_ft_billing_for_today(notify_db_session):
|
||||
create_letter_rate(start_date=datetime.utcnow() - timedelta(days=1))
|
||||
create_rate(start_date=datetime.utcnow() - timedelta(days=1), value=0.65, notification_type='sms')
|
||||
new_org = create_organisation(name='New organisation')
|
||||
service = create_service()
|
||||
|
||||
@@ -45,7 +45,6 @@ from app.models import (
|
||||
InvitedOrganisationUser,
|
||||
InvitedUser,
|
||||
Job,
|
||||
LetterRate,
|
||||
Notification,
|
||||
NotificationHistory,
|
||||
Organisation,
|
||||
@@ -506,23 +505,6 @@ def create_rate(start_date, value, notification_type):
|
||||
return rate
|
||||
|
||||
|
||||
def create_letter_rate(start_date=None, end_date=None, crown=True, sheet_count=1, rate=0.33, post_class='second'):
|
||||
if start_date is None:
|
||||
start_date = datetime(2016, 1, 1)
|
||||
rate = LetterRate(
|
||||
id=uuid.uuid4(),
|
||||
start_date=start_date,
|
||||
end_date=end_date,
|
||||
crown=crown,
|
||||
sheet_count=sheet_count,
|
||||
rate=rate,
|
||||
post_class=post_class
|
||||
)
|
||||
db.session.add(rate)
|
||||
db.session.commit()
|
||||
return rate
|
||||
|
||||
|
||||
def create_api_key(service, key_type=KEY_TYPE_NORMAL, key_name=None):
|
||||
id_ = uuid.uuid4()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user