dont let user update prov details version, and refactor tests

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
This commit is contained in:
Leo Hemsted
2016-12-19 16:53:23 +00:00
parent 9d1b1328af
commit 8bb0261c79
4 changed files with 114 additions and 134 deletions

View File

@@ -37,9 +37,10 @@ def update_provider_details(provider_details_id):
current_data.update(request.get_json())
update_dict = provider_details_schema.load(current_data).data
if "identifier" in request.get_json().keys():
invalid_keys = {'identifier', 'version'} & set(key for key in request.get_json().keys())
if invalid_keys:
message = "Not permitted to be updated"
errors = {'identifier': [message]}
errors = {key: [message] for key in invalid_keys}
raise InvalidRequest(errors, status_code=400)
dao_update_provider_details(update_dict)