Skip to content

ua-snap/data-api

Repository files navigation

Data API for SNAP@IARC

Installing

Install Micromamba via brew:

brew install micromamba

Create a new mamba environment like so:

micromamba env create -f environment.yml

This creates a Mamba environment called api-env which you can activate with:

micromamba activate api-env

Running application

Set flask application environment variables:

export FLASK_APP=application.py
export FLASK_DEBUG=True

Review environment variables found in config.py, and reset them for development if necessary (e.g., export API_GS_BASE_URL=https://gs-dev.earthmaps.io/geoserver/).

Start the application via your mamba environment:

flask run

Query API endpoints

Example Permafrost Query:

Example Fire Query:

Example Precipitation Query:

Creating and updating Production API + Varnish Cache

To create a new ElasticBeanstalk API instance, do the following:

git checkout production
git pull
eb init <-- Choose us-west-2 and data-api-production for application
eb create --it r7g.large --single

To update the current API instance, do the following:

git checkout production
git pull
eb deploy

Explicit instructions for creating and updating the API can be found here:

Test Suite

Running Tests

Run pytest or pytest -v from the root directory of this repository.

The test client is created from the same Flask "app" object that a local development instance uses (see conftest.py). Basically everything is the same, except there is no actual network socket opened. Stuff that is inbound to the API happens in-memory (no server or port), but the outbound stuff (requests to Rasdaman and Geoserver) still creates normal HTTP requests.

Adding Tests

Area Query JSON Integrity Blueprint

  • test name must be prefixed with test_
  • match the name to the routing, exactly
    • e.g. test_alfresco_flammability_area maps to /alfresco/flammability/area
  • assert the expected HTTP status code
  • assert the response from the local client maps to the reference JSON
    • add reference JSON via curl
    • curl -sS https://earthmaps.io/taspr/area/19010208 -o tests/taspr_area_19010208.json
    • ensure the reference JSON file name maps exactly to the route

Test Guidance

  • Keep it simple
  • Favor integration-scope over unit-scope
  • Ask: is this test useful?
  • Consider testing overhead (e.g., the largest polygons could be annoying test cases because of their lengthy durations)
  • Don't add tests to just add tests, 100% coverage not realistically the goal
  • Let the test suite evolve organically: fiddling with a tricky bit of code and want to be able to move with more confidence? Good signal to add a test
  • Consider adding conjugate, non-happy path tests, e.g., does /route/area/null*$(!*) yield the expected status code?

About

SNAP data API

Resources

License

Stars

Watchers

Forks

Contributors 8

Languages