2016-09-22 11:56:26 +01:00
|
|
|
import pytest
|
|
|
|
|
|
2016-09-27 13:44:29 +01:00
|
|
|
from app.models import (
|
|
|
|
|
ServiceWhitelist,
|
|
|
|
|
MOBILE_TYPE, EMAIL_TYPE)
|
2016-09-07 13:44:56 +01:00
|
|
|
|
|
|
|
|
|
2016-09-22 11:56:26 +01:00
|
|
|
@pytest.mark.parametrize('mobile_number', [
|
|
|
|
|
'07700 900678',
|
|
|
|
|
'+44 7700 900678'
|
|
|
|
|
])
|
|
|
|
|
def test_should_build_service_whitelist_from_mobile_number(mobile_number):
|
2016-09-27 13:44:29 +01:00
|
|
|
service_whitelist = ServiceWhitelist.from_string('service_id', MOBILE_TYPE, mobile_number)
|
2016-09-22 11:56:26 +01:00
|
|
|
|
2016-09-27 13:44:29 +01:00
|
|
|
assert service_whitelist.recipient == mobile_number
|
2016-09-22 11:56:26 +01:00
|
|
|
|
2016-09-22 17:18:52 +01:00
|
|
|
|
2016-09-22 11:56:26 +01:00
|
|
|
@pytest.mark.parametrize('email_address', [
|
|
|
|
|
'test@example.com'
|
|
|
|
|
])
|
|
|
|
|
def test_should_build_service_whitelist_from_email_address(email_address):
|
2016-09-27 13:44:29 +01:00
|
|
|
service_whitelist = ServiceWhitelist.from_string('service_id', EMAIL_TYPE, email_address)
|
2016-09-22 11:56:26 +01:00
|
|
|
|
2016-09-27 13:44:29 +01:00
|
|
|
assert service_whitelist.recipient == email_address
|
2016-09-22 11:56:26 +01:00
|
|
|
|
|
|
|
|
|
2016-09-27 13:44:29 +01:00
|
|
|
@pytest.mark.parametrize('contact, recipient_type', [
|
|
|
|
|
('', None),
|
|
|
|
|
('07700dsadsad', MOBILE_TYPE),
|
|
|
|
|
('gmail.com', EMAIL_TYPE)
|
2016-09-22 11:56:26 +01:00
|
|
|
])
|
2016-09-27 13:44:29 +01:00
|
|
|
def test_should_not_build_service_whitelist_from_invalid_contact(recipient_type, contact):
|
2016-09-22 11:56:26 +01:00
|
|
|
with pytest.raises(ValueError):
|
2016-09-27 13:44:29 +01:00
|
|
|
ServiceWhitelist.from_string('service_id', recipient_type, contact)
|