mirror of
https://github.com/GSA/notifications-api.git
synced 2026-04-14 06:09:41 -04:00
Added get provider by id
This commit is contained in:
@@ -91,9 +91,7 @@ def init_app(app):
|
||||
url_for('notifications.process_ses_response'),
|
||||
url_for('notifications.process_firetext_response'),
|
||||
url_for('notifications.process_mmg_response'),
|
||||
url_for('status.show_delivery_status'),
|
||||
url_for('provider_details.get_providers'),
|
||||
"/provider-details/41ade136-33bc-4151-be23-a04084cde50b"
|
||||
url_for('status.show_delivery_status')
|
||||
]
|
||||
if request.path not in no_auth_req:
|
||||
from app.authentication import auth
|
||||
|
||||
@@ -5,7 +5,7 @@ from app import db
|
||||
|
||||
|
||||
def get_provider_details():
|
||||
return ProviderDetails.query.order_by(asc(ProviderDetails.priority)).all()
|
||||
return ProviderDetails.query.order_by(asc(ProviderDetails.priority), asc(ProviderDetails.notification_type)).all()
|
||||
|
||||
|
||||
def get_provider_details_by_id(provider_details_id):
|
||||
|
||||
@@ -4,6 +4,7 @@ from app.schemas import provider_details_schema
|
||||
from app.dao.provider_details_dao import (
|
||||
get_provider_details,
|
||||
get_provider_details_by_id,
|
||||
get_provider_details_by_id,
|
||||
dao_update_provider_details
|
||||
)
|
||||
|
||||
@@ -16,6 +17,12 @@ def get_providers():
|
||||
return jsonify(provider_details=data)
|
||||
|
||||
|
||||
@provider_details.route('/<uuid:provider_details_id>', methods=['GET'])
|
||||
def get_provider_by_id(provider_details_id):
|
||||
data, errors = provider_details_schema.dump(get_provider_details_by_id(provider_details_id))
|
||||
return jsonify(provider_details=data)
|
||||
|
||||
|
||||
@provider_details.route('/<uuid:provider_details_id>', methods=['POST'])
|
||||
def update_provider_details(provider_details_id):
|
||||
fetched_provider_details = get_provider_details_by_id(provider_details_id)
|
||||
@@ -25,5 +32,11 @@ def update_provider_details(provider_details_id):
|
||||
update_dict, errors = provider_details_schema.load(current_data)
|
||||
if errors:
|
||||
return jsonify(result="error", message=errors), 400
|
||||
|
||||
if "identifier" in request.get_json().keys():
|
||||
return jsonify(message={
|
||||
"identifier": ["Not permitted to be updated"]
|
||||
}, result='error'), 400
|
||||
|
||||
dao_update_provider_details(update_dict)
|
||||
return jsonify(data=provider_details_schema.dump(fetched_provider_details).data), 200
|
||||
return jsonify(provider_details=provider_details_schema.dump(fetched_provider_details).data), 200
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
from flask import json
|
||||
from tests import create_authorization_header
|
||||
|
||||
|
||||
def test_get_provider_details_in_type_and_identifier_order(notify_db, notify_db_session, notify_api):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
auth_header = create_authorization_header()
|
||||
response = client.get(
|
||||
'/provider-details',
|
||||
headers=[auth_header]
|
||||
)
|
||||
assert response.status_code == 200
|
||||
json_resp = json.loads(response.get_data(as_text=True))['provider_details']
|
||||
assert len(json_resp) == 3
|
||||
|
||||
assert json_resp[0]['identifier'] == 'ses'
|
||||
assert json_resp[1]['identifier'] == 'mmg'
|
||||
assert json_resp[2]['identifier'] == 'firetext'
|
||||
|
||||
|
||||
def test_get_provider_details_by_id(notify_db, notify_db_session, notify_api):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
auth_header = create_authorization_header()
|
||||
response = client.get(
|
||||
'/provider-details',
|
||||
headers=[auth_header]
|
||||
)
|
||||
json_resp = json.loads(response.get_data(as_text=True))['provider_details']
|
||||
|
||||
provider_resp = client.get(
|
||||
'/provider-details/{}'.format(json_resp[0]['id']),
|
||||
headers=[auth_header]
|
||||
)
|
||||
|
||||
provider = json.loads(provider_resp.get_data(as_text=True))['provider_details']
|
||||
assert provider['identifier'] == json_resp[0]['identifier']
|
||||
|
||||
|
||||
def test_get_provider_details_contains_correct_fields(notify_db, notify_db_session, notify_api):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
auth_header = create_authorization_header()
|
||||
response = client.get(
|
||||
'/provider-details',
|
||||
headers=[auth_header]
|
||||
)
|
||||
json_resp = json.loads(response.get_data(as_text=True))['provider_details']
|
||||
allowed_keys = {"id", "display_name", "identifier", "priority", 'notification_type', "active"}
|
||||
assert \
|
||||
allowed_keys == \
|
||||
set(json_resp[0].keys())
|
||||
|
||||
|
||||
def test_should_be_able_to_update_priority(notify_db, notify_db_session, notify_api):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
auth_header = create_authorization_header()
|
||||
response = client.get(
|
||||
'/provider-details',
|
||||
headers=[auth_header]
|
||||
)
|
||||
fetch_resp = json.loads(response.get_data(as_text=True))['provider_details']
|
||||
|
||||
provider_id = fetch_resp[2]['id']
|
||||
|
||||
update_resp = client.post(
|
||||
'/provider-details/{}'.format(provider_id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header],
|
||||
data=json.dumps({
|
||||
'priority': 10
|
||||
})
|
||||
)
|
||||
assert update_resp.status_code == 200
|
||||
update_json = json.loads(update_resp.get_data(as_text=True))['provider_details']
|
||||
assert update_json['identifier'] == 'firetext'
|
||||
assert update_json['priority'] == 10
|
||||
|
||||
|
||||
def test_should_be_able_to_update_status(notify_db, notify_db_session, notify_api):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
auth_header = create_authorization_header()
|
||||
response = client.get(
|
||||
'/provider-details',
|
||||
headers=[auth_header]
|
||||
)
|
||||
fetch_resp = json.loads(response.get_data(as_text=True))['provider_details']
|
||||
|
||||
provider_id = fetch_resp[2]['id']
|
||||
|
||||
update_resp_1 = client.post(
|
||||
'/provider-details/{}'.format(provider_id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header],
|
||||
data=json.dumps({
|
||||
'active': False
|
||||
})
|
||||
)
|
||||
assert update_resp_1.status_code == 200
|
||||
update_resp_1 = json.loads(update_resp_1.get_data(as_text=True))['provider_details']
|
||||
assert update_resp_1['identifier'] == 'firetext'
|
||||
assert not update_resp_1['active']
|
||||
|
||||
update_resp_2 = client.post(
|
||||
'/provider-details/{}'.format(provider_id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header],
|
||||
data=json.dumps({
|
||||
'active': True
|
||||
})
|
||||
)
|
||||
assert update_resp_2.status_code == 200
|
||||
update_resp_2 = json.loads(update_resp_2.get_data(as_text=True))['provider_details']
|
||||
assert update_resp_2['identifier'] == 'firetext'
|
||||
assert update_resp_2['active']
|
||||
|
||||
|
||||
def test_should_not_be_able_to_update_identifier(notify_db, notify_db_session, notify_api):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
auth_header = create_authorization_header()
|
||||
response = client.get(
|
||||
'/provider-details',
|
||||
headers=[auth_header]
|
||||
)
|
||||
fetch_resp = json.loads(response.get_data(as_text=True))['provider_details']
|
||||
|
||||
provider_id = fetch_resp[2]['id']
|
||||
|
||||
update_resp = client.post(
|
||||
'/provider-details/{}'.format(provider_id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header],
|
||||
data=json.dumps({
|
||||
'identifier': "new"
|
||||
})
|
||||
)
|
||||
assert update_resp.status_code == 400
|
||||
update_resp = json.loads(update_resp.get_data(as_text=True))
|
||||
assert update_resp['message']['identifier'][0] == 'Not permitted to be updated'
|
||||
assert update_resp['result'] == 'error'
|
||||
|
||||
Reference in New Issue
Block a user