Refactor the sms sender code to remove any unused methods.

Refactor tests/db/create_service() to behave more like the real world.
Created new create_service_with_inbound_number and create_service_with_defined_sms_sender() test/db methods.
This commit is contained in:
Rebecca Law
2017-11-07 14:26:18 +00:00
parent 430342b567
commit 0054361044
15 changed files with 224 additions and 379 deletions

View File

@@ -4,12 +4,9 @@ from app.dao.inbound_numbers_dao import (
dao_get_inbound_numbers,
dao_get_inbound_number_for_service,
dao_get_available_inbound_numbers,
dao_set_inbound_number_to_service,
dao_set_inbound_number_active_flag,
dao_allocate_number_for_service)
from app.dao.service_sms_sender_dao import insert_or_update_service_sms_sender
from app.dao.services_dao import dao_fetch_service_by_id
from app.errors import InvalidRequest, register_errors
dao_set_inbound_number_active_flag
)
from app.errors import register_errors
inbound_number_blueprint = Blueprint('inbound_number', __name__, url_prefix='/inbound-number')
register_errors(inbound_number_blueprint)
@@ -29,46 +26,12 @@ def get_inbound_number_for_service(service_id):
return jsonify(data=inbound_number.serialize() if inbound_number else {})
@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 inbound_number:
if not inbound_number.active:
dao_set_inbound_number_active_flag(service_id, active=True)
service = dao_fetch_service_by_id(service_id)
insert_or_update_service_sms_sender(service, inbound_number.number, inbound_number.id)
return jsonify(), 204
else:
return jsonify(), 200
available_numbers = dao_get_available_inbound_numbers()
if len(available_numbers) > 0:
dao_set_inbound_number_to_service(service_id, available_numbers[0])
service = dao_fetch_service_by_id(service_id)
insert_or_update_service_sms_sender(service, available_numbers[0].number, available_numbers[0].id)
return jsonify(), 204
else:
raise InvalidRequest('No available inbound numbers', status_code=400)
@inbound_number_blueprint.route('/service/<uuid:service_id>/off', methods=['POST'])
def post_set_inbound_number_off(service_id):
dao_set_inbound_number_active_flag(service_id, active=False)
return jsonify(), 204
@inbound_number_blueprint.route('<uuid:inbound_number_id>/service/<uuid:service_id>', methods=['POST'])
def allocate_inbound_number_to_service(inbound_number_id, service_id):
service = dao_fetch_service_by_id(service_id=service_id, only_active=True)
updated_inbound_number = dao_allocate_number_for_service(service_id=service_id, inbound_number_id=inbound_number_id)
insert_or_update_service_sms_sender(service=service,
sms_sender=updated_inbound_number.number,
inbound_number_id=inbound_number_id)
return jsonify(), 204
@inbound_number_blueprint.route('/available', methods=['GET'])
def get_available_inbound_numbers():
inbound_numbers = [i.serialize() for i in dao_get_available_inbound_numbers()]