Use real letter_rates in tests

Added the letter_rate table to the list of tables which does not get
deleted after each test run and changed the tests to use the real letter
rates.

Also removed the letter rate DAO since this was only being used in
tests, so was no longer needed.
This commit is contained in:
Katie Smith
2018-07-10 11:31:18 +01:00
parent 8f211e00f5
commit c57f33a02d
9 changed files with 18 additions and 132 deletions

View File

@@ -18,7 +18,6 @@ from tests.app.db import (
create_template,
create_notification,
create_rate,
create_letter_rate
)
@@ -223,18 +222,16 @@ 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())
non_letter_rates, letter_rates = get_rates_for_billing()
assert len(non_letter_rates) == 3
assert len(letter_rates) == 1
assert len(letter_rates) == 10
def test_get_rate(notify_db_session):
create_rate(start_date=datetime.utcnow(), value=1.2, notification_type='email')
create_rate(start_date=datetime.utcnow(), value=2.2, notification_type='sms')
create_rate(start_date=datetime.utcnow(), value=3.3, notification_type='email')
create_letter_rate(start_date=datetime.utcnow(), rate=4.4)
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=datetime.utcnow())
@@ -245,7 +242,7 @@ def test_get_rate(notify_db_session):
date=datetime.utcnow())
assert rate == 2.2
assert letter_rate == Decimal('4.4')
assert letter_rate == Decimal('0.3')
def test_fetch_monthly_billing_for_year(notify_db_session):

View File

@@ -1,41 +0,0 @@
from datetime import datetime
from decimal import Decimal
from app.dao.letter_rate_dao import dao_create_letter_rate, get_letter_rates_for_daterange
from app.models import LetterRate
def test_dao_create_letter_rate(notify_db_session):
letter_rate = LetterRate(start_date=datetime(2017, 12, 1),
rate=0.33,
crown=True,
sheet_count=1,
post_class='second')
dao_create_letter_rate(letter_rate)
rates = LetterRate.query.all()
assert len(rates) == 1
def test_get_letter_rates_for_daterange(notify_db_session):
letter_rate = LetterRate(start_date=datetime(2017, 12, 1),
rate=0.33,
crown=True,
sheet_count=1,
post_class='second')
dao_create_letter_rate(letter_rate)
letter_rate = LetterRate(start_date=datetime(2016, 12, 1),
end_date=datetime(2017, 12, 1),
rate=0.30,
crown=True,
sheet_count=1,
post_class='second')
dao_create_letter_rate(letter_rate)
results = get_letter_rates_for_daterange(date=datetime(2017, 12, 2), crown=True, sheet_count=1, post_class='second')
assert len(results) == 1
assert results[0].rate == Decimal('0.33')

View File

@@ -18,7 +18,7 @@ from tests.app.db import (
create_service,
create_template,
create_monthly_billing_entry,
create_letter_rate)
)
FEB_2016_MONTH_START = datetime(2016, 2, 1)
FEB_2016_MONTH_END = datetime(2016, 2, 29, 23, 59, 59, 99999)
@@ -154,7 +154,6 @@ def test_add_monthly_billing_for_single_month_populates_correctly(
):
create_rate(start_date=JAN_2017_MONTH_START, value=0.0158, notification_type=SMS_TYPE)
letter_template = sample_letter_template(sample_template.service)
create_letter_rate(crown=False)
create_notification(
template=sample_template, created_at=JAN_2017_MONTH_START,
billable_units=1, rate_multiplier=2, status='delivered'
@@ -201,8 +200,8 @@ def test_add_monthly_billing_for_single_month_populates_correctly(
"billing_units": 1,
"rate_multiplier": 1,
"international": False,
"rate": 0.31,
"total_cost": 1 * 0.31
"rate": 0.33,
"total_cost": 1 * 0.33
})
@@ -286,7 +285,6 @@ def test_add_monthly_billing_with_multiple_rates_populate_correctly(
create_notification(template=sample_email_template, created_at=JAN_2017_MONTH_START, status='delivered')
create_notification(template=letter_template, created_at=JAN_2017_MONTH_START, status='delivered',
billable_units=1)
create_letter_rate(start_date=JAN_2017_MONTH_START, crown=False)
create_or_update_monthly_billing(service_id=sample_template.service_id, billing_month=JAN_2017_MONTH_START)
@@ -329,8 +327,8 @@ def test_add_monthly_billing_with_multiple_rates_populate_correctly(
"billing_units": 1,
"rate_multiplier": 1,
"international": False,
"rate": 0.31,
"total_cost": 0.31
"rate": 0.33,
"total_cost": 0.33
})

View File

@@ -14,7 +14,7 @@ from app.models import (
Rate,
SMS_TYPE,
)
from tests.app.db import create_notification, create_rate, create_letter_rate, create_template, create_service
from tests.app.db import create_notification, create_rate, create_template, create_service
def test_get_rates_for_daterange(notify_db, notify_db_session):
@@ -217,7 +217,6 @@ def test_get_monthly_billing_data_where_start_date_before_rate_returns_empty(
def test_billing_letter_data_per_month_query(
notify_db_session
):
create_letter_rate()
service = create_service()
template = create_template(service=service, template_type='letter')
create_notification(template=template, billable_units=1, created_at=datetime(2017, 2, 1, 13, 21),
@@ -232,5 +231,5 @@ def test_billing_letter_data_per_month_query(
end_date=datetime(2017, 2, 28))
assert len(results) == 1
assert results[0].rate == 0.31
assert results[0].rate == 0.3
assert results[0].billing_units == 3