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

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

    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

            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
            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

              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:

                  Summary Panel