Uploaded image for project: 'Data Management'
  1. Data Management
  2. DM-9741

Implement a minimal viable REST API in Flask with a test client

    XMLWordPrintable

    Details

    • Type: Story
    • Status: Done
    • Resolution: Done
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      As part of the migration of the SQuaSH API to Flask we need an mvp project with the packages and extensions defined in DM-12191 including a test client to exercise the API.

        Attachments

          Issue Links

            Activity

            No builds found.
            jhoblitt Joshua Hoblitt created issue -
            jhoblitt Joshua Hoblitt made changes -
            Field Original Value New Value
            Epic Link DM-9651 [ 30702 ]
            jhoblitt Joshua Hoblitt made changes -
            Link This issue is triggered by DM-9726 [ DM-9726 ]
            afausti Angelo Fausti made changes -
            Epic Link DM-9651 [ 30702 ] DM-5504 [ 23337 ]
            afausti Angelo Fausti made changes -
            Epic Link DM-5504 [ 23337 ] DM-10181 [ 31811 ]
            afausti Angelo Fausti made changes -
            Assignee Angelo Fausti [ afausti ]
            afausti Angelo Fausti made changes -
            Summary API acceptance test suite Implement unit tests and improve test coverage for the squash-api
            afausti Angelo Fausti made changes -
            Summary Implement unit tests and improve test coverage for the squash-api Implement unit tests and improve test coverage for the SQuaSH REST API
            afausti Angelo Fausti made changes -
            Description We need a squash API acceptance test suite that can be run against a live squash instance that exercises the the entire REST API. It should use "real world" fixture data include the large (>50MiB) HSC measurement data set. We need a squash API acceptance test suite that can be run against a live squash instance that exercises the the entire REST API. It should use for example "real world" fixture data include the large (>50MiB) HSC measurement data set.

            There are interesting options like {{django-nose}} package see
            afausti Angelo Fausti made changes -
            Link This issue is blocked by DM-12191 [ DM-12191 ]
            afausti Angelo Fausti made changes -
            Story Points 4.2
            Description We need a squash API acceptance test suite that can be run against a live squash instance that exercises the the entire REST API. It should use for example "real world" fixture data include the large (>50MiB) HSC measurement data set.

            There are interesting options like {{django-nose}} package see
            We need a squash API acceptance test suite that can be run against a live squash instance that exercises the the entire REST API. It should use for example "real world" fixture data include the large (>50MiB) HSC measurement data set.

            There are interesting options like {{django-nose}} package see for instance:
            https://www.safaribooksonline.com/library/view/building-restful-python/9781788620154/video8_1.html
            afausti Angelo Fausti made changes -
            Summary Implement unit tests and improve test coverage for the SQuaSH REST API Implement tests for the SQuaSH REST API
            afausti Angelo Fausti made changes -
            Description We need a squash API acceptance test suite that can be run against a live squash instance that exercises the the entire REST API. It should use for example "real world" fixture data include the large (>50MiB) HSC measurement data set.

            There are interesting options like {{django-nose}} package see for instance:
            https://www.safaribooksonline.com/library/view/building-restful-python/9781788620154/video8_1.html
            We need a squash API acceptance test suite that can be run against a live squash instance that exercises the the entire REST API. It should use for example "real world" fixture data include the large (>50MiB) HSC measurement data set.

            Since we are migrating the SQuaSH API to Flask I am looking at other options like Postman and Newman to implement and execute tests.
            Show
            afausti Angelo Fausti added a comment - - edited These are the main resources I'm using for implementing the REST API in Flask: REST APIs with Flask and Python: https://www.safaribooksonline.com/library/view/rest-apis-with/9781788621526/ Developing RESTful APIs with Python and Flask: https://auth0.com/blog/developing-restful-apis-with-python-and-flask/ Building RESTful Python Web Services: https://www.safaribooksonline.com/library/view/building-restful-python/9781786462251/ch06s06.html https://www.safaribooksonline.com/library/view/building-web-apis/9781491912393/video190365.html https://www.safaribooksonline.com/library/view/building-web-apis/9781491912393/video190366.html
            afausti Angelo Fausti made changes -
            Status To Do [ 10001 ] In Progress [ 3 ]
            afausti Angelo Fausti made changes -
            Description We need a squash API acceptance test suite that can be run against a live squash instance that exercises the the entire REST API. It should use for example "real world" fixture data include the large (>50MiB) HSC measurement data set.

            Since we are migrating the SQuaSH API to Flask I am looking at other options like Postman and Newman to implement and execute tests.
            Since we are migrating the SQuaSH API to Flask I am looking at other options like Postman and Newman to implement and execute tests.
            afausti Angelo Fausti made changes -
            Summary Implement tests for the SQuaSH REST API Implement a minimal viable REST API in Flask with a test client
            afausti Angelo Fausti made changes -
            Description Since we are migrating the SQuaSH API to Flask I am looking at other options like Postman and Newman to implement and execute tests. As part of the migration of the SQuaSH API to Flask we need an mvp project with the packages and extensions defined in DM-12191 including a test client to exercise the API.
            afausti Angelo Fausti made changes -
            Story Points 4.2 7
            Hide
            afausti Angelo Fausti added a comment - - edited
            • Implemented a very simple model with user, metrics and measurements tables unsing flask-sqlalchemy
            • Implemented the corresponding API resources using flask-restful with get, post, update and delete methods when applicable
            • Implemented token authentication using flask-jwt
            • Implemented a test client that instantiate the app with the testing configuration, create an empty database, add a test user, get the authentication token, execute the tests and tear down the testing setup
            • Testing the JSON data type on MySQL 5.7 by adding a data field in the measurements model

            Test client output example:

            $ coverage run --source=app test.py
            test_measurement (tests.tests.TestAPI) ... ok
            test_metric (tests.tests.TestAPI) ... ok
            test_user (tests.tests.TestAPI) ... ok
             
            ----------------------------------------------------------------------
            Ran 3 tests in 1.025s
             
            OK
            Name                           Stmts   Miss Branch BrPart  Cover
            ----------------------------------------------------------------
            app/__init__.py                   22      0      0      0   100%
            app/auth.py                        8      0      2      1    90%
            app/config.py                     19      0      0      0   100%
            app/db.py                          2      0      0      0   100%
            app/models.py                     68      1      4      1    97%
            app/resources/__init__.py          0      0      0      0   100%
            app/resources/measurement.py      37      4      8      2    82%
            app/resources/metric.py           26      5      8      3    76%
            app/resources/user.py             29      5      8      1    78%
            ----------------------------------------------------------------
            TOTAL                            211     15     30      8    89%
            Coverage.py warning: No data was collected. (no-data-collected)
            

            Show
            afausti Angelo Fausti added a comment - - edited Implemented a very simple model with user, metrics and measurements tables unsing flask-sqlalchemy Implemented the corresponding API resources using flask-restful with get, post, update and delete methods when applicable Implemented token authentication using flask-jwt Implemented a test client that instantiate the app with the testing configuration, create an empty database, add a test user, get the authentication token, execute the tests and tear down the testing setup Testing the JSON data type on MySQL 5.7 by adding a data field in the measurements model Test client output example: $ coverage run --source=app test.py test_measurement (tests.tests.TestAPI) ... ok test_metric (tests.tests.TestAPI) ... ok test_user (tests.tests.TestAPI) ... ok   ---------------------------------------------------------------------- Ran 3 tests in 1.025s   OK Name Stmts Miss Branch BrPart Cover ---------------------------------------------------------------- app/__init__.py 22 0 0 0 100% app/auth.py 8 0 2 1 90% app/config.py 19 0 0 0 100% app/db.py 2 0 0 0 100% app/models.py 68 1 4 1 97% app/resources/__init__.py 0 0 0 0 100% app/resources/measurement.py 37 4 8 2 82% app/resources/metric.py 26 5 8 3 76% app/resources/user.py 29 5 8 1 78% ---------------------------------------------------------------- TOTAL 211 15 30 8 89% Coverage.py warning: No data was collected. (no-data-collected)
            Hide
            afausti Angelo Fausti added a comment -


            Merged this initial implementation https://github.com/lsst-sqre/squash-rest-api/pull/1

            Show
            afausti Angelo Fausti added a comment - Merged this initial implementation https://github.com/lsst-sqre/squash-rest-api/pull/1
            afausti Angelo Fausti made changes -
            Resolution Done [ 10000 ]
            Status In Progress [ 3 ] Done [ 10002 ]
            afausti Angelo Fausti made changes -
            Link This issue blocks DM-12964 [ DM-12964 ]
            afausti Angelo Fausti made changes -
            Link This issue blocks DM-12601 [ DM-12601 ]
            afausti Angelo Fausti made changes -
            Epic Link DM-10181 [ 31811 ] DM-12787 [ 36405 ]

              People

              Assignee:
              afausti Angelo Fausti
              Reporter:
              jhoblitt Joshua Hoblitt
              Watchers:
              Angelo Fausti, Frossie Economou, Jonathan Sick, Joshua Hoblitt
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Jenkins

                  No builds found.