mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-05 10:42:41 -05:00
Updated Notification model to use Float(asdecimal=False) for rate_mutliplier.
Added test with multiple rows for a month.
This commit is contained in:
@@ -670,7 +670,7 @@ class Notification(db.Model):
|
||||
|
||||
international = db.Column(db.Boolean, nullable=False, default=False)
|
||||
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
|
||||
def personalisation(self):
|
||||
|
||||
@@ -444,7 +444,8 @@ def sample_notification(
|
||||
api_key_id=None,
|
||||
key_type=KEY_TYPE_NORMAL,
|
||||
sent_by=None,
|
||||
client_reference=None
|
||||
client_reference=None,
|
||||
rate_multiplier=1.0
|
||||
):
|
||||
if created_at is None:
|
||||
created_at = datetime.utcnow()
|
||||
@@ -481,7 +482,8 @@ def sample_notification(
|
||||
'key_type': key_type,
|
||||
'sent_by': sent_by,
|
||||
'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:
|
||||
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)
|
||||
|
||||
|
||||
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):
|
||||
rate = Rate(id=uuid.uuid4(), valid_from=start_date, rate=value, notification_type='sms')
|
||||
notify_db.session.add(rate)
|
||||
|
||||
@@ -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),
|
||||
sent_at=datetime(2016, 6, 5),
|
||||
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),
|
||||
sent_at=datetime(2016, 7, 5),
|
||||
status='sending')
|
||||
@@ -1563,14 +1566,19 @@ def test_get_monthly_billing_usage(client, notify_db, notify_db_session):
|
||||
)
|
||||
assert response.status_code == 200
|
||||
actual = json.loads(response.get_data(as_text=True))
|
||||
assert len(actual) == 2
|
||||
print(actual)
|
||||
assert len(actual) == 3
|
||||
assert actual == [{'month': 'June',
|
||||
'international': False,
|
||||
'rate_multiplier': 1,
|
||||
'notification_type': 'sms',
|
||||
'rate': 1.58,
|
||||
'billing_units': 1},
|
||||
{'month': 'June',
|
||||
'international': False,
|
||||
'rate_multiplier': 2,
|
||||
'notification_type': 'sms',
|
||||
'rate': 1.58,
|
||||
'billing_units': 1},
|
||||
{'month': 'July',
|
||||
'international': False,
|
||||
'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)) == {
|
||||
'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)) == []
|
||||
|
||||
Reference in New Issue
Block a user