Updated Notification model to use Float(asdecimal=False) for rate_mutliplier.

Added test with multiple rows for a month.
This commit is contained in:
Rebecca Law
2017-04-28 10:10:49 +01:00
committed by Ken Tsang
parent 1a64509186
commit 3b41478a0a
4 changed files with 33 additions and 5 deletions
+1 -1
View File
@@ -670,7 +670,7 @@ class Notification(db.Model):
international = db.Column(db.Boolean, nullable=False, default=False) international = db.Column(db.Boolean, nullable=False, default=False)
phone_prefix = db.Column(db.String, nullable=True) phone_prefix = db.Column(db.String, nullable=True)
rate_multiplier = db.Column(db.Float(), nullable=True) rate_multiplier = db.Column(db.Float(asdecimal=False), nullable=True)
@property @property
def personalisation(self): def personalisation(self):
+4 -2
View File
@@ -444,7 +444,8 @@ def sample_notification(
api_key_id=None, api_key_id=None,
key_type=KEY_TYPE_NORMAL, key_type=KEY_TYPE_NORMAL,
sent_by=None, sent_by=None,
client_reference=None client_reference=None,
rate_multiplier=1.0
): ):
if created_at is None: if created_at is None:
created_at = datetime.utcnow() created_at = datetime.utcnow()
@@ -481,7 +482,8 @@ def sample_notification(
'key_type': key_type, 'key_type': key_type,
'sent_by': sent_by, 'sent_by': sent_by,
'updated_at': created_at if status in NOTIFICATION_STATUS_TYPES_COMPLETED else None, 'updated_at': created_at if status in NOTIFICATION_STATUS_TYPES_COMPLETED else None,
'client_reference': client_reference 'client_reference': client_reference,
'rate_multiplier': rate_multiplier
} }
if job_row_number is not None: if job_row_number is not None:
data['job_row_number'] = job_row_number data['job_row_number'] = job_row_number
@@ -160,6 +160,13 @@ def test_get_monthly_billing_data_with_multiple_rates(notify_db, notify_db_sessi
assert results[3] == ('June', 4, 1, False, 'sms', 1.75) assert results[3] == ('June', 4, 1, False, 'sms', 1.75)
def test_get_monthly_billing_data_with_no_notifications_for_year(notify_db, notify_db_session, sample_template,
sample_email_template):
set_up_rate(notify_db, datetime(2016, 4, 1), 1.40)
results = get_monthly_billing_data(sample_template.service_id, 2016)
assert len(results) == 0
def set_up_rate(notify_db, start_date, value): def set_up_rate(notify_db, start_date, value):
rate = Rate(id=uuid.uuid4(), valid_from=start_date, rate=value, notification_type='sms') rate = Rate(id=uuid.uuid4(), valid_from=start_date, rate=value, notification_type='sms')
notify_db.session.add(rate) notify_db.session.add(rate)
+21 -2
View File
@@ -1554,6 +1554,9 @@ def test_get_monthly_billing_usage(client, notify_db, notify_db_session):
notification = create_sample_notification(notify_db, notify_db_session, created_at=datetime(2016, 6, 5), notification = create_sample_notification(notify_db, notify_db_session, created_at=datetime(2016, 6, 5),
sent_at=datetime(2016, 6, 5), sent_at=datetime(2016, 6, 5),
status='sending') status='sending')
create_sample_notification(notify_db, notify_db_session, created_at=datetime(2016, 6, 5),
sent_at=datetime(2016, 6, 5),
status='sending', rate_multiplier=2)
create_sample_notification(notify_db, notify_db_session, created_at=datetime(2016, 7, 5), create_sample_notification(notify_db, notify_db_session, created_at=datetime(2016, 7, 5),
sent_at=datetime(2016, 7, 5), sent_at=datetime(2016, 7, 5),
status='sending') status='sending')
@@ -1563,14 +1566,19 @@ def test_get_monthly_billing_usage(client, notify_db, notify_db_session):
) )
assert response.status_code == 200 assert response.status_code == 200
actual = json.loads(response.get_data(as_text=True)) actual = json.loads(response.get_data(as_text=True))
assert len(actual) == 2 assert len(actual) == 3
print(actual)
assert actual == [{'month': 'June', assert actual == [{'month': 'June',
'international': False, 'international': False,
'rate_multiplier': 1, 'rate_multiplier': 1,
'notification_type': 'sms', 'notification_type': 'sms',
'rate': 1.58, 'rate': 1.58,
'billing_units': 1}, 'billing_units': 1},
{'month': 'June',
'international': False,
'rate_multiplier': 2,
'notification_type': 'sms',
'rate': 1.58,
'billing_units': 1},
{'month': 'July', {'month': 'July',
'international': False, 'international': False,
'rate_multiplier': 1, 'rate_multiplier': 1,
@@ -1588,3 +1596,14 @@ def test_get_monthly_billing_usage_returns_400_if_missing_year(client, sample_se
assert json.loads(response.get_data(as_text=True)) == { assert json.loads(response.get_data(as_text=True)) == {
'message': 'No valid year provided', 'result': 'error' 'message': 'No valid year provided', 'result': 'error'
} }
def test_get_monthly_billing_usage_returns_empty_list_if_no_notifications(client, notify_db, sample_service):
rate = Rate(id=uuid.uuid4(), valid_from=datetime(2016, 3, 31, 23, 00), rate=1.58, notification_type='sms')
notify_db.session.add(rate)
response = client.get(
'/service/{}/monthly-usage?year=2016'.format(sample_service.id),
headers=[create_authorization_header()]
)
assert response.status_code == 200
assert json.loads(response.get_data(as_text=True)) == []