Skip to content

Api save whitelist#5059

Merged
jburel merged 21 commits intoome:developfrom
will-moore:api_save_whitelist
Feb 20, 2017
Merged

Api save whitelist#5059
jburel merged 21 commits intoome:developfrom
will-moore:api_save_whitelist

Conversation

@will-moore
Copy link
Copy Markdown
Member

@will-moore will-moore commented Jan 26, 2017

What this PR does

Restricts Save (PUT or POST) to a "whitelist" of supported object types.

In the SaveView class that handles PUT and POST, we use a whitelist of supported types Project, Dataset, Screen.
In the ObjectView subclasses that handle DELETE of various objects we use a CAN_DELETE attribute that is True is the base class and False in subclasses where Delete is NOT supported Plate, Image, Well.

Testing this PR

  • Existing tests confirm that we can create, update & delete Project, Dataset & Screen. (Plate removed from this test).
  • Added tests that checks Image, Plate & other types cannot be created, updated or deleted.

Related reading

Discussed at web meeting on 2017-01-24

Copy link
Copy Markdown
Member

@chris-allan chris-allan left a comment

Choose a reason for hiding this comment

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

We should add some test cases to ensure that the PUT and POST restrictions are accurate.

POST to create a new Object and PUT to replace existing one.
"""

can_put = ['Project', 'Dataset', 'Screen']
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As these are constants, let's uppercase them.

@jburel jburel added the develop label Jan 26, 2017
@will-moore will-moore closed this Jan 29, 2017
@will-moore will-moore reopened this Jan 29, 2017
@snoopycrimecop
Copy link
Copy Markdown
Member

Conflicting PR. Removed from build OMERO-DEV-merge-push#577. See the console output for more details.
Possible conflicts:

  • PR Api wells #5047 will-moore 'Api wells'
    • components/tools/OmeroWeb/test/integration/test_api_images.py
  • PR Api child count #5058 will-moore 'Api child count'
    • components/tools/OmeroWeb/test/integration/test_api_images.py

@will-moore will-moore closed this Jan 31, 2017
@will-moore will-moore reopened this Jan 31, 2017
@will-moore will-moore closed this Jan 31, 2017
@will-moore will-moore reopened this Jan 31, 2017
@snoopycrimecop
Copy link
Copy Markdown
Member

Conflicting PR. Removed from build OMERO-DEV-merge-push#579. See the console output for more details.
Possible conflicts:

  • PR Api wells #5047 will-moore 'Api wells'
    • components/tools/OmeroWeb/test/integration/test_api_images.py
  • PR Api child count #5058 will-moore 'Api child count'
    • components/tools/OmeroWeb/test/integration/test_api_images.py

@snoopycrimecop
Copy link
Copy Markdown
Member

Conflicting PR. Removed from build OMERO-DEV-merge-push#580. See the console output for more details.
Possible conflicts:

  • PR Api wells #5047 will-moore 'Api wells'
    • components/tools/OmeroWeb/test/integration/test_api_images.py
  • PR Api child count #5058 will-moore 'Api child count'
    • components/tools/OmeroWeb/test/integration/test_api_images.py

@snoopycrimecop snoopycrimecop mentioned this pull request Feb 2, 2017
@snoopycrimecop
Copy link
Copy Markdown
Member

Conflicting PR. Removed from build OMERO-DEV-merge-push#581. See the console output for more details.
Possible conflicts:

  • PR Api wells #5047 will-moore 'Api wells'
    • components/tools/OmeroWeb/test/integration/test_api_images.py
  • PR Api child count #5058 will-moore 'Api child count'
    • components/tools/OmeroWeb/test/integration/test_api_images.py

@will-moore will-moore closed this Feb 14, 2017
@will-moore will-moore reopened this Feb 14, 2017
from django.http import JsonResponse
from functools import update_wrapper
from api_exceptions import NotFoundError, BadRequestError, CreatedObject
from api_exceptions import NotFoundError, BadRequestError, CreatedObject, \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

one per line and alphabetical order

@@ -75,7 +76,7 @@ def handle_error(self, ex, trace):
# But we try to handle all 'expected' errors appropriately
# TODO: handle omero.ConcurrencyException
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Will you do that in another PR? i.e. TODO

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes. Hard to see that we need to support ConcurrencyException since we are doing very simple get/set queries now and no stateful services.

from omeroweb.connector import Server
from omeroweb.api.api_exceptions import BadRequestError, NotFoundError, \
CreatedObject
CreatedObject, MethodNotSupportedError
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same

@pytest.mark.parametrize("dtype", ['Plate', 'Image', 'Well',
'Channel', 'foo'])
def test_crud_unsupported(self, user1, dtype):
"""Test create, update & delete are rejected for unsupported types."""
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you should split the test and not have post/put/delete tests in the same one

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@jburel I split the test in 102c6c9

@will-moore
Copy link
Copy Markdown
Member Author

Need to fix failing ```test_api_errors.py```` tests in https://ci.openmicroscopy.org/view/Failing/job/OMERO-DEV-breaking-integration-Python27/164/testReport/
Haven't had time today, so will close this until I fix tests (tomorrow).

@will-moore will-moore closed this Feb 15, 2017
@will-moore will-moore reopened this Feb 16, 2017
Single test for PUT, POST & DELETE is spilt into separate tests for each method.
To try and reduce code duplication, PUT and POST are covered by parametrizing method
in a single test.
@will-moore
Copy link
Copy Markdown
Member Author

@jburel After those last commits, this is going to conflict with #5058, so we'll need to get that merged ASAP. I still have 3 further api PRs waiting after this one.
@chris-allan You still have "requested changes" on this PR, which I think are addressed with the added tests?

@snoopycrimecop
Copy link
Copy Markdown
Member

Conflicting PR. Removed from build OMERO-DEV-merge-push#592. See the console output for more details.
Possible conflicts:

  • PR Api child count #5058 will-moore 'Api child count'
    • components/tools/OmeroWeb/test/integration/test_api_errors.py

Copy link
Copy Markdown
Member

@chris-allan chris-allan left a comment

Choose a reason for hiding this comment

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

Looks great aside from the exception feedback above.


status = 405

def __init__(self, message, stacktrace=None):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not seeing any use of the stacktrace keyword argument in the implementation. Is it your intention to use it for something? If so, what? If you want to have a unified constructor prototype that is similar to the other exceptions you have above then I would suggest making a class hierarchy so you are not having to implement, and document, this every time.

@will-moore
Copy link
Copy Markdown
Member Author

@chris-allan Thanks. Fixed in eb18edc

@jburel
Copy link
Copy Markdown
Member

jburel commented Feb 17, 2017

Exception code fixed.
Tests split and passing
I will merge on Monday am if everything is green

@jburel jburel merged commit a74790c into ome:develop Feb 20, 2017
@jburel jburel added this to the 5.3.0 milestone Mar 29, 2017
@will-moore will-moore deleted the api_save_whitelist branch February 18, 2019 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants