Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PUT /executions/{executionIdentifier} #36

Merged
merged 7 commits into from
Mar 12, 2018
Merged

Conversation

louis-ver
Copy link
Owner

No description provided.

@louis-ver louis-ver self-assigned this Mar 11, 2018
@louis-ver louis-ver requested a review from simon-dube March 11, 2018 19:02
@coveralls
Copy link

coveralls commented Mar 11, 2018

Coverage Status

Coverage increased (+0.2%) to 94.93% when pulling 987b517 on put-execution into 52c7db5 on get-execution.

Copy link
Collaborator

@simon-dube simon-dube left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job. Just a few details to change.

return func(model=body, *args, **kwargs)
else:
return ErrorCodeAndMessageMarshaller(
INVALID_MODEL_PROVIDED), 400

model, errors = schema.load(body)
if (errors):
model, errors = schema.load(body, partial=partial)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How that's really nice!

@get_db_session
@unmarshal_request(ExecutionSchema(), partial=True)
@marshal_response()
def put(self, model, execution_identifier, user, db_session):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please replace put with PATCH. We will also change this in the OpenAPI 3.0 descriptor to reflect the changes discussed with @glatard. I tested it and patch works with flask-restful.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to do this before the change was approved in https://github.com/fli-iam/CARMIN. The issue has been created (CARMIN-org#86), but I don't know of a pull request that was merged. @glatard should we wait before a PR is merged before implementing it as PATCH?

name: str,
pipeline_identifier: str,
input_values: object,
name: str = None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first I didn't want to allow none for these values as they are illegal and should never be None, but as we always do the transfer via the Schema and it performs the validation this is ok. I will change my call to this constructor in the POST.

Copy link
Owner Author

@louis-ver louis-ver Mar 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was my opinion as well. I don't think it causes any issues, and remains safe.

response = test_config.test_client.put(
'/executions/{}'.format(execution_id),
headers={"apiKey": standard_user().api_key},
data=json.dumps(PATCH_VALID_EXECUTION))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For uniformity, we should use json_request_data utils function. I just realized it isn't used in Executions either. It does the same thing, except it was placed under a standard utils function. However, do you feel like it may be a bit overkill to have such utils function? I did it back when I wrote our first unit tests to insure uniformity, but rethinking about it, as there isn't any fancy parameter used for the moment, we could simply call json.dumps. What are you thoughts on that @louis-ver?

Copy link
Owner Author

@louis-ver louis-ver Mar 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the need for the json_request_data function. It is less explicit and does not really provide an advantage.

However, I think that load_json_data is useful, since the actual json function is a little verbose and not really helpful.


I say we remove json_request_data, but keep load_json_data

"apiKey": standard_user().api_key
})
execution = load_json_data(response)
assert execution["name"] == PATCH_VALID_EXECUTION2["name"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure the change took place in the DB. You can find an example in test_register_already_existing_user_folder (register_test.py). This will insure that the DB changes really took place.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced the GET request with a DB query instead. Didn't know how to do that. Thanks for the head's up!

"apiKey": standard_user().api_key
})
execution = load_json_data(response)
assert execution["timeout"] == PATCH_VALID_EXECUTION3["timeout"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure the change took place in the DB. You can find an example in test_register_already_existing_user_folder (register_test.py). This will insure that the DB changes really took place.

'/executions/{}'.format(execution_id),
headers={"apiKey": standard_user().api_key},
data=json.dumps(PATCH_INVALID_PARAMETER))
assert response.status_code == 400
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This 400 is caused by an exception in the DB right? I that case I believe you should add a try catch as done with register, and return a proper ErrorCodeAndMessage.

Copy link
Owner Author

@louis-ver louis-ver Mar 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the 400 is caused in the unmarshaling of the request, inside the @unmarshal_request decorator. The model is invalid, since timeout should be an integer.

Copy link
Collaborator

@simon-dube simon-dube left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to merge

@simon-dube simon-dube merged commit bd5133d into get-execution Mar 12, 2018
@simon-dube simon-dube deleted the put-execution branch March 12, 2018 15:41
louis-ver added a commit that referenced this pull request Mar 12, 2018
* GET /execution/{executionIdentifier}

* PUT /executions/{executionIdentifier} (#36)

* PUT /executions/{executionIdentifier}

* Add tests for PUT /executions/

* Fix bug in execution change logic

* Add more checking to test results

* Refactor for less db calls

* Query DB instead of issuing GET request

* Removing non required params

* Add execution_id to EXECUTION_NOT_FOUND error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants