mirror of
https://github.com/GSA/notifications-api.git
synced 2026-05-29 18:38:26 -04:00
Refactored endpoints
This commit is contained in:
@@ -22,7 +22,6 @@ def dao_get_inbound_number(inbound_number_id):
|
||||
@transactional
|
||||
def dao_set_inbound_number_to_service(service_id, inbound_number):
|
||||
inbound_number.service_id = service_id
|
||||
|
||||
db.session.add(inbound_number)
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ from flask import Blueprint, jsonify, request
|
||||
|
||||
from app.dao.inbound_numbers_dao import (
|
||||
dao_get_inbound_numbers,
|
||||
dao_get_inbound_number,
|
||||
dao_get_inbound_number_for_service,
|
||||
dao_get_available_inbound_numbers,
|
||||
dao_set_inbound_number_to_service,
|
||||
@@ -22,8 +23,15 @@ def get_inbound_numbers():
|
||||
return jsonify(data=inbound_numbers)
|
||||
|
||||
|
||||
@inbound_number_blueprint.route('/<uuid:service_id>', methods=['POST'])
|
||||
def post_allocate_or_reactivate_inbound_number(service_id):
|
||||
@inbound_number_blueprint.route('/available', methods=['GET'])
|
||||
def get_inbound_numbers_available():
|
||||
inbound_numbers = [i.serialize() for i in dao_get_available_inbound_numbers()]
|
||||
|
||||
return jsonify(data=inbound_numbers)
|
||||
|
||||
|
||||
@inbound_number_blueprint.route('/service/<uuid:service_id>', methods=['POST'])
|
||||
def post_allocate_inbound_number(service_id):
|
||||
inbound_number = dao_get_inbound_number_for_service(service_id)
|
||||
|
||||
if not inbound_number:
|
||||
@@ -39,7 +47,25 @@ def post_allocate_or_reactivate_inbound_number(service_id):
|
||||
return '', 204
|
||||
|
||||
|
||||
@inbound_number_blueprint.route('/<uuid:service_id>/off', methods=['POST'])
|
||||
def post_deactivate_inbound_number(service_id):
|
||||
dao_set_inbound_number_active_flag(service_id, active=False)
|
||||
@inbound_number_blueprint.route('/<uuid:inbound_number_id>/service/<uuid:service_id>', methods=['POST'])
|
||||
def post_set_inbound_number_for_service(inbound_number_id, service_id):
|
||||
try:
|
||||
dao_set_inbound_number_to_service(service_id, inbound_number_id)
|
||||
except TypeError as e:
|
||||
if str(e) == 'UUID objects are immutable':
|
||||
return '', 409
|
||||
else:
|
||||
raise e
|
||||
return '', 204
|
||||
|
||||
|
||||
@inbound_number_blueprint.route('/service/<uuid:inbound_number_id>/on', methods=['POST'])
|
||||
def post_set_inbound_number_on(inbound_number_id):
|
||||
dao_set_inbound_number_active_flag(inbound_number_id, active=True)
|
||||
return '', 204
|
||||
|
||||
|
||||
@inbound_number_blueprint.route('/<uuid:inbound_number_id>/off', methods=['POST'])
|
||||
def post_set_inbound_number_off(inbound_number_id):
|
||||
dao_set_inbound_number_active_flag(inbound_number_id, active=False)
|
||||
return '', 204
|
||||
|
||||
@@ -4,6 +4,7 @@ import json
|
||||
from app.models import InboundNumber
|
||||
from app.dao.inbound_numbers_dao import (
|
||||
dao_get_inbound_numbers,
|
||||
dao_get_inbound_number,
|
||||
dao_get_available_inbound_numbers,
|
||||
dao_get_inbound_number_for_service,
|
||||
dao_set_inbound_number_to_service
|
||||
@@ -22,7 +23,7 @@ def test_rest_get_inbound_numbers(admin_request, sample_inbound_numbers):
|
||||
def test_rest_allocate_inbound_number(admin_request, notify_db_session, sample_inbound_numbers):
|
||||
service = create_service(service_name='test service')
|
||||
admin_request.post(
|
||||
'inbound_number.post_allocate_or_reactivate_inbound_number',
|
||||
'inbound_number.post_allocate_inbound_number',
|
||||
_expected_status=204,
|
||||
service_id=service.id
|
||||
)
|
||||
@@ -36,35 +37,64 @@ def test_rest_allocate_inbound_number_when_no_inbound_available_returns_409(
|
||||
service_2 = create_service(service_name='test service 2')
|
||||
|
||||
admin_request.post(
|
||||
'inbound_number.post_allocate_or_reactivate_inbound_number',
|
||||
'inbound_number.post_allocate_inbound_number',
|
||||
_expected_status=409,
|
||||
service_id=service_2.id
|
||||
)
|
||||
|
||||
|
||||
def test_rest_deactivate_inbound_number_for_service(admin_request, notify_db_session, sample_inbound_numbers):
|
||||
service = create_service(service_name='test service 1')
|
||||
create_inbound_number(number='4', provider='mmg', active=True, service_id=service.id)
|
||||
def test_rest_set_service_to_several_inbound_numbers_returns_409(
|
||||
admin_request, notify_db_session, sample_service):
|
||||
service_1 = create_service(service_name='test service 1')
|
||||
create_inbound_number(number='4', provider='mmg', active=False, service_id=sample_service.id)
|
||||
inbound_number = create_inbound_number(number='5', provider='mmg', active=True, service_id=service_1.id)
|
||||
service_2 = create_service(service_name='test service 2')
|
||||
|
||||
admin_request.post(
|
||||
'inbound_number.post_deactivate_inbound_number',
|
||||
_expected_status=204,
|
||||
service_id=service.id
|
||||
'inbound_number.post_set_inbound_number_for_service',
|
||||
_expected_status=409,
|
||||
inbound_number_id=inbound_number.id,
|
||||
service_id=service_2.id
|
||||
)
|
||||
|
||||
inbound_number_deactivated = dao_get_inbound_number_for_service(service.id)
|
||||
assert not inbound_number_deactivated.active
|
||||
|
||||
|
||||
def test_rest_reactivate_inbound_number_for_service(admin_request, notify_db_session, sample_inbound_numbers):
|
||||
service = create_service(service_name='test service 1')
|
||||
create_inbound_number(number='4', provider='mmg', active=False, service_id=service.id)
|
||||
def test_rest_set_number_to_several_services_returns_409(
|
||||
admin_request, notify_db_session, sample_service):
|
||||
service_1 = create_service(service_name='test service 1')
|
||||
inbound_number = create_inbound_number(number='4', provider='mmg', active=False, service_id=sample_service.id)
|
||||
service_2 = create_service(service_name='test service 2')
|
||||
|
||||
admin_request.post(
|
||||
'inbound_number.post_allocate_or_reactivate_inbound_number',
|
||||
_expected_status=204,
|
||||
service_id=service.id
|
||||
'inbound_number.post_set_inbound_number_for_service',
|
||||
_expected_status=409,
|
||||
inbound_number_id=inbound_number.id,
|
||||
service_id=service_2.id
|
||||
)
|
||||
|
||||
inbound_number_reactivated = dao_get_inbound_number_for_service(service.id)
|
||||
assert inbound_number_reactivated.active
|
||||
|
||||
def test_rest_set_inbound_number_active_flag_off(admin_request, notify_db_session):
|
||||
service = create_service(service_name='test service 1')
|
||||
inbound_number = create_inbound_number(number='1', provider='mmg', active=True, service_id=service.id)
|
||||
|
||||
admin_request.post(
|
||||
'inbound_number.post_set_inbound_number_off',
|
||||
_expected_status=204,
|
||||
inbound_number_id=inbound_number.id
|
||||
)
|
||||
|
||||
inbound_number_off = dao_get_inbound_number(inbound_number.id)
|
||||
assert not inbound_number_off.active
|
||||
|
||||
|
||||
def test_rest_set_inbound_number_active_flag_on(admin_request, notify_db_session):
|
||||
service = create_service(service_name='test service 1')
|
||||
inbound_number = create_inbound_number(number='1', provider='mmg', active=True, service_id=service.id)
|
||||
|
||||
admin_request.post(
|
||||
'inbound_number.post_set_inbound_number_on',
|
||||
_expected_status=204,
|
||||
inbound_number_id=inbound_number.id
|
||||
)
|
||||
|
||||
inbound_number_on = dao_get_inbound_number(inbound_number.id)
|
||||
assert inbound_number_on.active
|
||||
|
||||
Reference in New Issue
Block a user