mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-14 09:12:06 -05:00
the provider details tests were previously very stateful - they would update a value, and then because provider_details is a "static" table that is not wiped by the notify_db_session fixture, the tests were forced to make a second update that reverted that change. if the test fails for whatever reason, the provider_details table ends up permanently modified, playing havoc on tests further down the line. this commit adds the fixture `restore_provider_details` to conftest. this fixture stores a copy of the contents of ProviderDetails and ProviderDetailsHistory tables outside of the session, runs the test, and then clears the table and puts those old values in this means that the tests have been cleaned up so that they do not do operations twice in reverse. they've also been cleaned up generally, including fixture optimisations and such
48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
from flask import Blueprint, jsonify, request
|
|
|
|
from app.schemas import provider_details_schema
|
|
|
|
from app.dao.provider_details_dao import (
|
|
get_provider_details,
|
|
get_provider_details_by_id,
|
|
dao_update_provider_details
|
|
)
|
|
|
|
from app.errors import (
|
|
register_errors,
|
|
InvalidRequest
|
|
)
|
|
|
|
provider_details = Blueprint('provider_details', __name__)
|
|
register_errors(provider_details)
|
|
|
|
|
|
@provider_details.route('', methods=['GET'])
|
|
def get_providers():
|
|
data = provider_details_schema.dump(get_provider_details(), many=True).data
|
|
return jsonify(provider_details=data)
|
|
|
|
|
|
@provider_details.route('/<uuid:provider_details_id>', methods=['GET'])
|
|
def get_provider_by_id(provider_details_id):
|
|
data = provider_details_schema.dump(get_provider_details_by_id(provider_details_id)).data
|
|
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)
|
|
|
|
current_data = dict(provider_details_schema.dump(fetched_provider_details).data.items())
|
|
current_data.update(request.get_json())
|
|
update_dict = provider_details_schema.load(current_data).data
|
|
|
|
invalid_keys = {'identifier', 'version'} & set(key for key in request.get_json().keys())
|
|
if invalid_keys:
|
|
message = "Not permitted to be updated"
|
|
errors = {key: [message] for key in invalid_keys}
|
|
raise InvalidRequest(errors, status_code=400)
|
|
|
|
dao_update_provider_details(update_dict)
|
|
return jsonify(provider_details=provider_details_schema.dump(fetched_provider_details).data), 200
|