mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-18 05:31:48 -05:00
Added a test that asking for a nonexistent provider_rate blows everything up. Also updated existing test to use a weirder number.
72 lines
2.3 KiB
Python
72 lines
2.3 KiB
Python
import pytest
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy.orm.exc import NoResultFound
|
|
from tests.app.conftest import sample_notification, sample_provider_rate
|
|
from app.models import (
|
|
ServiceWhitelist,
|
|
MOBILE_TYPE, EMAIL_TYPE)
|
|
|
|
|
|
@pytest.mark.parametrize('mobile_number', [
|
|
'07700 900678',
|
|
'+44 7700 900678'
|
|
])
|
|
def test_should_build_service_whitelist_from_mobile_number(mobile_number):
|
|
service_whitelist = ServiceWhitelist.from_string('service_id', MOBILE_TYPE, mobile_number)
|
|
|
|
assert service_whitelist.recipient == mobile_number
|
|
|
|
|
|
@pytest.mark.parametrize('email_address', [
|
|
'test@example.com'
|
|
])
|
|
def test_should_build_service_whitelist_from_email_address(email_address):
|
|
service_whitelist = ServiceWhitelist.from_string('service_id', EMAIL_TYPE, email_address)
|
|
|
|
assert service_whitelist.recipient == email_address
|
|
|
|
|
|
@pytest.mark.parametrize('contact, recipient_type', [
|
|
('', None),
|
|
('07700dsadsad', MOBILE_TYPE),
|
|
('gmail.com', EMAIL_TYPE)
|
|
])
|
|
def test_should_not_build_service_whitelist_from_invalid_contact(recipient_type, contact):
|
|
with pytest.raises(ValueError):
|
|
ServiceWhitelist.from_string('service_id', recipient_type, contact)
|
|
|
|
|
|
@pytest.mark.parametrize('provider, billable_units, expected_cost', [
|
|
('mmg', 1, 3.5),
|
|
('firetext', 2, 0.025),
|
|
('ses', 0, 0)
|
|
])
|
|
def test_calculate_cost_from_notification_billable_units(
|
|
notify_db, notify_db_session, provider, billable_units, expected_cost
|
|
):
|
|
provider_rates = [
|
|
('mmg', datetime(2016, 7, 1), 1.5),
|
|
('firetext', datetime(2016, 7, 1), 0.0125),
|
|
('mmg', datetime.utcnow(), 3.5),
|
|
]
|
|
for provider_identifier, valid_from, rate in provider_rates:
|
|
sample_provider_rate(
|
|
notify_db,
|
|
notify_db_session,
|
|
provider_identifier=provider_identifier,
|
|
valid_from=valid_from,
|
|
rate=rate
|
|
)
|
|
|
|
notification = sample_notification(notify_db, notify_db_session, billable_units=billable_units, sent_by=provider)
|
|
assert notification.cost() == expected_cost
|
|
|
|
|
|
def test_billable_units_without_provider_rates_entry_raises_exception(
|
|
notify_db, notify_db_session, sample_provider_rate
|
|
):
|
|
notification = sample_notification(notify_db, notify_db_session, sent_by='not_a_provider')
|
|
with pytest.raises(NoResultFound):
|
|
notification.cost()
|