Skip to content

Webgateway api2#4708

Merged
jburel merged 159 commits intoome:developfrom
will-moore:webgateway_api2
Nov 2, 2016
Merged

Webgateway api2#4708
jburel merged 159 commits intoome:developfrom
will-moore:webgateway_api2

Conversation

@will-moore
Copy link
Copy Markdown
Member

@will-moore will-moore commented Jun 14, 2016

This is a subset of webgateway api methods explored in #4572.

User guide for the API which covers all urls added in this PR can be found at https://github.com/will-moore/design/blob/webgateway_json_api/webgateway_json_api.md

I have also added an example test script at
https://github.com/will-moore/openmicroscopy/blob/webgateway_api2/examples/Training/python/Json_Api/Login.py
which can be used for testing this PR.

Browse API at http://10.0.51.145/web/api/

This PR uses omero-marshal which is included in the build.
We also add /version/ into the url to allow versioning, E.g.

/api/v1/m/projects/

The supported versions are specified in settings API_VERSIONS = ['0.1']
Details of our versioning strategy are to be decided.
This PR splits the querying and marshalling into api_query.py and api_marshal.py respectively.

New tests are under OmeroWeb/test/integration/test_api_*
I have ported some integration tests from test_tree.py, and turned them into Django session-based tests to test the actual json api, not just the underlying querying and marshalling. These tests also use omero-marshal.

TODO / discuss

  • OmeroWeb Tests
  • Filter by owner & group
  • Single project /webgateway/api/v1/m/projects/:id/
  • Test page, limit, normalize, childCount & callback query params in test_api_projects.py
  • Test Project creation, update and delete in test_api_projects.py
  • Test 404 in test_api_projects.py
  • Complete test_api_login.py with success and error handling as in gist
  • IF we're dropping Django 1.6, can use 1.7 Http imports in omeroweb/http See 440ce90
  • Make sure GET, PUT & POST return correct status codes See https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.5

Future TODOs:

  • Investigate CORS instead of jsonp().
  • Register OMERO.webapi user agent with QA
  • Split 'api' out of webgateway into separate app
  • Handle 'normalize' by unloading groups & experimenters?
  • Test cases for _internal and _raw flags in @jsonp decorator
  • Handle inactive user login. Currently users don't get logged in and can't tell why.
  • Need omeroweb.webadmin.webadmin_utils.upgradeCheck expanded to allow for configuration of the agent

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (C) 2019 University of Dundee & Open Microscopy Environment.
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.

that's a futuristic PR :)

@will-moore
Copy link
Copy Markdown
Member Author

@sbesson @chris-allan Travis is failing with

�[0K$ if [[ $BUILD == 'build-python' ]]; then pip install --user -r https://github.com/openmicroscopy/omero-marshal/tarball/master; fi
�[33mYou are using pip version 6.0.8, however version 8.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.�[0m
�[31mException:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/pip-6.0.8-py2.7.egg/pip/basecommand.py", line 232, in main
    status = self.run(options, args)
  File "/usr/local/lib/python2.7/dist-packages/pip-6.0.8-py2.7.egg/pip/commands/install.py", line 321, in run
    finder=finder, options=options, session=session):
  File "/usr/local/lib/python2.7/dist-packages/pip-6.0.8-py2.7.egg/pip/req/req_file.py", line 135, in parse_requirements
    isolated=options.isolated_mode if options else False,
  File "/usr/local/lib/python2.7/dist-packages/pip-6.0.8-py2.7.egg/pip/req/req_install.py", line 137, in from_line
    elif (os.path.isdir(path)
  File "/usr/lib/python2.7/genericpath.py", line 41, in isdir
    st = os.stat(s)
TypeError: must be encoded string without NULL bytes, not str

Any ideas what I'm doing wrong?

@knabar
Copy link
Copy Markdown
Member

knabar commented Jun 14, 2016

@will-moore You don't need the -r since it's not a requirements file

@atarkowska
Copy link
Copy Markdown
Member

atarkowska commented Jun 14, 2016

-r is for requirement file, I think you need to create a file first
or

pip install https://github.com/openmicroscopy/omero-marshal/tarball/master
Collecting https://github.com/openmicroscopy/omero-marshal/tarball/master
  Cache entry deserialization failed, entry ignored
  Downloading https://github.com/openmicroscopy/omero-marshal/tarball/master
  Requirement already satisfied (use --upgrade to upgrade): omero-marshal==0.3.0 from https://github.com/openmicroscopy/omero-marshal/tarball/master in /Users/ola/.local/lib/python2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): importlib>=1.0.1 in /usr/local/lib/python2.7/site-packages (from omero-marshal==0.3.0)

@will-moore
Copy link
Copy Markdown
Member Author

@aleksandra-tarkowska @knabar - thanks. pip install seems to be working (the build is failing elsewhere now)!

@atarkowska
Copy link
Copy Markdown
Member

atarkowska commented Jun 14, 2016

@will-moore could you create requirements file please as this PR broke devspace (because is green). And tomorrow web will fail on CI. Alternatively I would suggest to exclude and tomorrow I will help you with all builds?

@jburel
Copy link
Copy Markdown
Member

jburel commented Jun 14, 2016

excluding so it does not break tomorrow's build

@jburel
Copy link
Copy Markdown
Member

jburel commented Jun 14, 2016

Adding breaking too so it will be tested via breaking

@will-moore
Copy link
Copy Markdown
Member Author

@aleksandra-tarkowska Where do you want me to create a requirements file?
Is there an existing file I can add omero-marshal to, or will this be a new file with only omero-marshal?

This provides a single point to specifiy additional requirements that is consumed by
the other various requirements files.
This is now provided by OmeroWeb/requirements-common.txt
@will-moore
Copy link
Copy Markdown
Member Author

@aleksandra-tarkowska As discussed: added omero-marshal to OmeroWeb requirements files and removed it from .travis.yml

@atarkowska
Copy link
Copy Markdown
Member

atarkowska commented Jun 15, 2016

just chat with @will-moore I propose to create requirements folder OmeroWeb/requiremenst and reorganize these files (rename then to py(26|27)-(apache|nginx).txt). Adjusting ant to match what is currently in the documentation should be easy.

 <target name="copy-web-requirements" depends="init">
        <mkdir dir="${dist.dir}/share/web"/>
        <copy todir="${dist.dir}/share/web">
            <fileset dir="components/tools/OmeroWeb/requirements">
                <include name="requirements*.txt"/>
            </fileset>
            <globmapper from="*" to="requirements-*"/>
        </copy>
    </target>

I will handle that in a separate PR for better review

@will-moore
Copy link
Copy Markdown
Member Author

Working:

$ pip install -r requirements-py27-nginx.txt
Collecting https://github.com/openmicroscopy/omero-marshal/tarball/master (from -r requirements-common.txt (line 4))
  Downloading https://github.com/openmicroscopy/omero-marshal/tarball/master
     | 30kB 346kB/s
Requirement already satisfied (use --upgrade to upgrade): Django<1.9,>=1.8 in /usr/local/lib/python2.7/site-packages (from -r requirements-py27-nginx.txt (line 6))
Requirement already satisfied (use --upgrade to upgrade): gunicorn>=19.3 in /usr/local/lib/python2.7/site-packages (from -r requirements-py27-nginx.txt (line 7))
Collecting importlib>=1.0.1 (from omero-marshal==0.3.0->-r requirements-common.txt (line 4))
  Downloading importlib-1.0.3.tar.gz
Building wheels for collected packages: importlib
  Running setup.py bdist_wheel for importlib ... done
  Stored in directory: /Users/wmoore/Library/Caches/pip/wheels/2a/04/fb/873fc6754f3d84f4ad1ee05bd2e63bc52dc883fbe314c5801a
Successfully built importlib
Installing collected packages: importlib, omero-marshal
  Running setup.py install for omero-marshal ... done
Successfully installed importlib-1.0.3 omero-marshal-0.3.0

# To make django's method_decorator work, this is required until
# python/django sort out how argumented decorator wrapping should work
# https://github.com/openmicroscopy/openmicroscopy/pull/1820
def __getattr__(self, name):
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.

Fix from @dpwrussell went into Django upstream in 1.7. Do we still need this?

Might be time, not in this PR, to roll back the hack added in #1820 as well.

/cc @aleksandra-tarkowska, @joshmoore

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.

@chris-allan Seems we don't need this now since @dpwrussell's fix. I'll remove it.

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.

Provided that we have passing integration tests I'm happy for this to be merged.

Test run status to be confirmed by @sbesson.

@will-moore will-moore closed this Oct 26, 2016
@will-moore will-moore reopened this Oct 26, 2016
@snoopycrimecop
Copy link
Copy Markdown
Member

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

  • PR Open with #4630 will-moore 'Open with'
    • components/tools/OmeroWeb/omeroweb/webgateway/urls.py
    • components/tools/OmeroWeb/omeroweb/webgateway/views.py
  • Upstream changes
    • components/tools/OmeroWeb/omeroweb/webgateway/views.py

@will-moore will-moore mentioned this pull request Oct 27, 2016
@atarkowska
Copy link
Copy Markdown
Member

Where is follow up trello card for all the post merging issues?

@jburel
Copy link
Copy Markdown
Member

jburel commented Oct 27, 2016

@aleksandra-tarkowska: I have just created a card https://trello.com/c/IXaPj64B/212-web-api-round-2

@snoopycrimecop
Copy link
Copy Markdown
Member

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

  • Upstream changes
    • components/tools/OmeroWeb/omeroweb/webgateway/urls.py
    • components/tools/OmeroWeb/omeroweb/webgateway/views.py

@atarkowska
Copy link
Copy Markdown
Member

atarkowska commented Oct 28, 2016

OmeroWeb.test.integration.test_api_projects/TestProjects/test_project_update/ is broken

self = <test_api_projects.TestProjects object at 0x83d7510>
user1 = (<omero.clients.BaseClient object at 0x7839650>, object #0 (::omero::model::Experimenter)
{
    _id = object #1 (::omero::RLong...nnotationLinksLoaded = False
    _annotationLinksCountPerOwner = 
    {
    }
})

    def test_project_update(self, user1):
        conn = get_connection(user1)
        group = conn.getEventContext().groupId
        user_name = conn.getUser().getName()
        django_client = self.new_django_client(user_name, user_name)

        project = ProjectI()
        project.name = rstring('test_project_update')
        project.description = rstring('Test update')
        project = get_update_service(user1).saveAndReturnObject(project)

        # Update Project in 2 ways...
        version = settings.API_VERSIONS[-1]
        project_url = reverse('api_project', kwargs={'api_version': version,
                                                     'pid': project.id.val})
        save_url = reverse('api_save', kwargs={'api_version': version})
        # 1) Get Project, update and save back
        project_json = _get_response_json(django_client, project_url, {})
        assert project_json['Name'] == 'test_project_update'
        project_json['Name'] = 'new name'
        rsp = _csrf_put_json(django_client, save_url, project_json)
        assert rsp['@id'] == project.id.val
        assert rsp['Name'] == 'new name'    # Name has changed
        assert rsp['Description'] == 'Test update'  # No change

        # 2) Put from scratch (will delete empty fields, E.g. Description)
        save_url += '?group=' + str(group)
        payload = {'Name': 'updated name',
                   '@id': project.id.val}
        # Test error message if we don't pass @type:
        rsp = _csrf_put_json(django_client, save_url, payload, status_code=400)
        assert rsp['message'] == 'Need to specify @type attribute'
        # Add @type and try again
        payload['@type'] = project_json['@type']
        rsp = _csrf_put_json(django_client, save_url, payload)
        assert rsp['@id'] == project.id.val
        assert rsp['Name'] == 'updated name'
>       assert 'Description' not in rsp
E       assert 'Description' not in {'@id': 813, '@type': 'http://www.openmicroscopy.org/Schemas/OME/2016-06#Project', 'Description': '', 'Name': 'updated name', ...}

test/integration/test_api_projects.py:560: AssertionError
Standard Output

Vary: Cookie
Content-Type: application/json

{"omero:details": {"owner": {"UserName": "0ea9be08-1e0c-4236-92c8-86b0d0af0886", "FirstName": "0ea9be08-1e0c-4236-92c8-86b0d0af0886", "omero:details": {"@type": "TBD#Details", "permissions": {"canDelete": false, "perm": "rwra--", "canEdit": false, "canAnnotate": false, "canLink": true, "@type": "TBD#Permissions"}}, "@type": "http://www.openmicroscopy.org/Schemas/OME/2016-06#Experimenter", "LastName": "0ea9be08-1e0c-4236-92c8-86b0d0af0886", "@id": 2487, "Email": ""}, "group": {"omero:details": {"@type": "TBD#Details", "permissions": {"canDelete": false, "perm": "rwra--", "canEdit": false, "canAnnotate": false, "canLink": true, "@type": "TBD#Permissions"}}, "@id": 2221, "@type": "http://www.openmicroscopy.org/Schemas/OME/2016-06#ExperimenterGroup", "Name": "853a3fca-edfa-4a45-bf99-678dbe66897d"}, "@type": "TBD#Details", "permissions": {"canDelete": true, "perm": "rwra--", "canEdit": true, "canAnnotate": true, "canLink": true, "@type": "TBD#Permissions"}}, "Description": "Test update", "@id": 813, "@type": "http://www.openmicroscopy.org/Schemas/OME/2016-06#Project", "Name": "new name"}
Vary: Cookie
Content-Type: application/json

{"message": "Need to specify @type attribute"}
Vary: Cookie
Content-Type: application/json

{"omero:details": {"owner": {"UserName": "0ea9be08-1e0c-4236-92c8-86b0d0af0886", "FirstName": "0ea9be08-1e0c-4236-92c8-86b0d0af0886", "omero:details": {"@type": "TBD#Details", "permissions": {"canDelete": false, "perm": "rwra--", "canEdit": false, "canAnnotate": false, "canLink": true, "@type": "TBD#Permissions"}}, "@type": "http://www.openmicroscopy.org/Schemas/OME/2016-06#Experimenter", "LastName": "0ea9be08-1e0c-4236-92c8-86b0d0af0886", "@id": 2487, "Email": ""}, "group": {"omero:details": {"@type": "TBD#Details", "permissions": {"canDelete": false, "perm": "rwra--", "canEdit": false, "canAnnotate": false, "canLink": true, "@type": "TBD#Permissions"}}, "@id": 2221, "@type": "http://www.openmicroscopy.org/Schemas/OME/2016-06#ExperimenterGroup", "Name": "853a3fca-edfa-4a45-bf99-678dbe66897d"}, "@type": "TBD#Details", "permissions": {"canDelete": true, "perm": "rwra--", "canEdit": true, "canAnnotate": true, "canLink": true, "@type": "TBD#Permissions"}}, "Description": "", "@id": 813, "@type": "http://www.openmicroscopy.org/Schemas/OME/2016-06#Project", "Name": "updated name"}

@will-moore
Copy link
Copy Markdown
Member Author

@aleksandra-tarkowska If this test is failing on the devspace it's probably because it doesn't have the latest server since that test now requires #4829. See #4708 (review)

@atarkowska
Copy link
Copy Markdown
Member

atarkowska commented Oct 29, 2016

@will-moore, I am afraid the problem must be somewhere else. It was tested against last night merge build snoopycrimecop@c2f9b13.

@will-moore
Copy link
Copy Markdown
Member Author

Sorry, my mistake. The fix I need is actually from omero_marshal: ome/omero-marshal@e83f056
So I have just updated requirements to specify omero-marshal 0.4.1

Django>=1.8,<1.9
django-pipeline==1.3.20
git+git://github.com/openmicroscopy/omero-marshal.git@v0.4.0#egg=omero-marshal
git+git://github.com/openmicroscopy/omero-marshal.git@v0.4.1#egg=omero-marshal
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.

Any reason to use the Git form rather than omero-marshal==0.4.1 as above ?

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.

Not that I know of.

@will-moore
Copy link
Copy Markdown
Member Author

@atarkowska
Copy link
Copy Markdown
Member

indeed, tests are green

@jburel
Copy link
Copy Markdown
Member

jburel commented Nov 2, 2016

Thanks all. Merging

@jburel jburel merged commit 49109b0 into ome:develop Nov 2, 2016
@will-moore will-moore mentioned this pull request Nov 3, 2016
@atarkowska atarkowska mentioned this pull request Jan 16, 2017
@jburel jburel added this to the 5.3.0 milestone Mar 29, 2017
@will-moore will-moore deleted the webgateway_api2 branch February 18, 2019 04:12
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.

9 participants