mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 09:51:11 -05:00
Refatored tests and fixtures for inbound_number
This commit is contained in:
@@ -39,7 +39,14 @@ from app.dao.invited_user_dao import save_invited_user
|
|||||||
from app.dao.provider_rates_dao import create_provider_rates
|
from app.dao.provider_rates_dao import create_provider_rates
|
||||||
from app.clients.sms.firetext import FiretextClient
|
from app.clients.sms.firetext import FiretextClient
|
||||||
from tests import create_authorization_header
|
from tests import create_authorization_header
|
||||||
from tests.app.db import create_user, create_template, create_notification, create_api_key, create_inbound_number
|
from tests.app.db import (
|
||||||
|
create_user,
|
||||||
|
create_template,
|
||||||
|
create_notification,
|
||||||
|
create_service,
|
||||||
|
create_api_key,
|
||||||
|
create_inbound_number
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.yield_fixture
|
@pytest.yield_fixture
|
||||||
@@ -985,9 +992,10 @@ def sample_provider_rate(notify_db, notify_db_session, valid_from=None, rate=Non
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def sample_inbound_numbers(notify_db, notify_db_session, sample_service):
|
def sample_inbound_numbers(notify_db, notify_db_session, sample_service):
|
||||||
|
service = create_service(service_name='sample service 2')
|
||||||
inbound_numbers = []
|
inbound_numbers = []
|
||||||
inbound_numbers.append(create_inbound_number(number='1', provider='mmg'))
|
inbound_numbers.append(create_inbound_number(number='1', provider='mmg'))
|
||||||
inbound_numbers.append(create_inbound_number(number='2', provider='mmg', active=False))
|
inbound_numbers.append(create_inbound_number(number='2', provider='mmg', active=False, service_id=service.id))
|
||||||
inbound_numbers.append(create_inbound_number(number='3', provider='firetext', service_id=sample_service.id))
|
inbound_numbers.append(create_inbound_number(number='3', provider='firetext', service_id=sample_service.id))
|
||||||
return inbound_numbers
|
return inbound_numbers
|
||||||
|
|
||||||
@@ -1043,8 +1051,11 @@ def admin_request(client):
|
|||||||
data=json.dumps(_data),
|
data=json.dumps(_data),
|
||||||
headers=[('Content-Type', 'application/json'), create_authorization_header()]
|
headers=[('Content-Type', 'application/json'), create_authorization_header()]
|
||||||
)
|
)
|
||||||
|
if resp.get_data(as_text=True):
|
||||||
json_resp = json.loads(resp.get_data(as_text=True))
|
json_resp = json.loads(resp.get_data(as_text=True))
|
||||||
assert resp.status_code == _expected_status, json_resp
|
else:
|
||||||
|
json_resp = None
|
||||||
|
assert resp.status_code == _expected_status
|
||||||
return json_resp
|
return json_resp
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@@ -5,11 +5,12 @@ from app.dao.inbound_numbers_dao import (
|
|||||||
dao_get_inbound_numbers,
|
dao_get_inbound_numbers,
|
||||||
dao_get_available_inbound_numbers,
|
dao_get_available_inbound_numbers,
|
||||||
dao_get_inbound_number_for_service,
|
dao_get_inbound_number_for_service,
|
||||||
dao_set_inbound_number_to_service
|
dao_set_inbound_number_to_service,
|
||||||
|
dao_set_inbound_number_active_flag_for_service
|
||||||
)
|
)
|
||||||
from app.models import InboundNumber
|
from app.models import InboundNumber
|
||||||
|
|
||||||
from tests.app.db import create_service
|
from tests.app.db import create_service, create_inbound_number
|
||||||
|
|
||||||
|
|
||||||
def test_get_inbound_numbers(notify_db, notify_db_session, sample_inbound_numbers):
|
def test_get_inbound_numbers(notify_db, notify_db_session, sample_inbound_numbers):
|
||||||
@@ -26,7 +27,7 @@ def test_get_available_inbound_numbers(notify_db, notify_db_session, sample_inbo
|
|||||||
assert res[0] == sample_inbound_numbers[0]
|
assert res[0] == sample_inbound_numbers[0]
|
||||||
|
|
||||||
|
|
||||||
def test_allocate_inbound_number_to_service(notify_db, notify_db_session, sample_inbound_numbers):
|
def test_set_service_id_on_inbound_number(notify_db, notify_db_session, sample_inbound_numbers):
|
||||||
service = create_service(service_name='test service')
|
service = create_service(service_name='test service')
|
||||||
numbers = dao_get_available_inbound_numbers()
|
numbers = dao_get_available_inbound_numbers()
|
||||||
|
|
||||||
@@ -38,9 +39,34 @@ def test_allocate_inbound_number_to_service(notify_db, notify_db_session, sample
|
|||||||
assert res[0].service_id == service.id
|
assert res[0].service_id == service.id
|
||||||
|
|
||||||
|
|
||||||
def test_allocating_a_service_twice_will_raise_an_error(notify_db, notify_db_session, sample_inbound_numbers):
|
def test_after_setting_service_id_that_inbound_number_is_unavailable(
|
||||||
from tests.app.db import create_inbound_number
|
notify_db, notify_db_session, sample_inbound_numbers):
|
||||||
create_inbound_number(number='4', provider='mmg')
|
service = create_service(service_name='test service')
|
||||||
|
numbers = dao_get_available_inbound_numbers()
|
||||||
|
|
||||||
|
assert len(numbers) == 1
|
||||||
|
|
||||||
|
dao_set_inbound_number_to_service(service.id, numbers[0])
|
||||||
|
|
||||||
|
res = dao_get_available_inbound_numbers()
|
||||||
|
|
||||||
|
assert len(res) == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_inbound_number_for_service(notify_db, notify_db_session, sample_inbound_numbers):
|
||||||
|
service = create_service(service_name='test service')
|
||||||
|
inbound_number = create_inbound_number(number='4')
|
||||||
|
|
||||||
|
dao_set_inbound_number_to_service(service.id, inbound_number)
|
||||||
|
|
||||||
|
res = dao_get_inbound_number_for_service(service.id)
|
||||||
|
|
||||||
|
assert res.service_id == service.id
|
||||||
|
|
||||||
|
|
||||||
|
def test_setting_a_service_twice_will_raise_an_error(notify_db, notify_db_session):
|
||||||
|
create_inbound_number(number='1')
|
||||||
|
create_inbound_number(number='2')
|
||||||
service = create_service(service_name='test service')
|
service = create_service(service_name='test service')
|
||||||
numbers = dao_get_available_inbound_numbers()
|
numbers = dao_get_available_inbound_numbers()
|
||||||
|
|
||||||
@@ -49,15 +75,19 @@ def test_allocating_a_service_twice_will_raise_an_error(notify_db, notify_db_ses
|
|||||||
with pytest.raises(IntegrityError) as e:
|
with pytest.raises(IntegrityError) as e:
|
||||||
dao_set_inbound_number_to_service(service.id, numbers[1])
|
dao_set_inbound_number_to_service(service.id, numbers[1])
|
||||||
|
|
||||||
res = InboundNumber.query.filter(InboundNumber.service_id == service.id).all()
|
res = dao_get_inbound_number_for_service(service.id)
|
||||||
|
|
||||||
assert len(res) == 1
|
assert res.service_id == service.id
|
||||||
assert res[0].service_id == service.id
|
|
||||||
assert 'duplicate key value violates unique constraint' in str(e.value)
|
assert 'duplicate key value violates unique constraint' in str(e.value)
|
||||||
|
|
||||||
|
|
||||||
def test_get_inbound_number_for_service(notify_db, notify_db_session, sample_inbound_numbers, sample_service):
|
@pytest.mark.parametrize("active", [True, False])
|
||||||
res = dao_get_inbound_number_for_service(sample_service.id)
|
def test_set_inbound_number_active_flag(notify_db, notify_db_session, sample_service, active):
|
||||||
|
inbound_number = create_inbound_number(number='1')
|
||||||
|
dao_set_inbound_number_to_service(sample_service.id, inbound_number)
|
||||||
|
|
||||||
assert len(res) == 1
|
dao_set_inbound_number_active_flag_for_service(sample_service.id, active=active)
|
||||||
assert res[0].service_id == sample_service.id
|
|
||||||
|
inbound_number = dao_get_inbound_number_for_service(sample_service.id)
|
||||||
|
|
||||||
|
assert inbound_number.active is active
|
||||||
|
|||||||
Reference in New Issue
Block a user