Skip to content
Snippets Groups Projects
Select Git revision
15 results

toardb_fastapi

  • Clone with SSH
  • Clone with HTTPS
  • Migration of TOAR database from Django to FastAPI

    Thoughts around this project, especially which tests were taken (and which tests have still to be done):
    https://gitlab.version.fz-juelich.de/toar/toar-db/-/issues/33
    (or see code development at: https://gitlab.version.fz-juelich.de/toar/toar-db/-/tree/sabine_%2333_testfastAPI/fastAPIproject)
    This issue is structured with a table of contents and aims to clarify issues that were coming up.

    installation guide

    This repository holds a simple test database toardb_dump.sql (not yet fully filled with example data).
    Also some testing examples for the running application are provided within file production_tests.sh, as well as corresponding pytests.
    Running the tests and pytest are described after the installation guide (you need to do this first).

    installation and setup of database:
    Please follow exactly the instructions on page
    https://gitlab.version.fz-juelich.de/toar/toar-db/-/blob/master/INSTALL_POSTGIS.md
    (I unsuccessfully tried some shortcuts that did not work -- the above instructions do work!).
    After the above instructions execute the following command from shell:

    psql -U toaradmin -d toardb -h localhost -f toardb_dump.sql

    installation of toardb_fastapi:
    After cloning the repository (git clone https://gitlab.version.fz-juelich.de/toar/toardb_fastapi.git)
    it is recommended to create a virtual environment and install the requirements therein:

    python3 –m venv venv
    source venv/bin/activate
    pip install –r requirements.txt

    Running pytest

    After download and installation (see above) of toardb_fastapi you can check, if everything is working via

    pytest

    (due to an unknown error the database cannot be teared down correctly -- still under investigation (very last test will throw an error for teardown of database if run as ensemble, if every module is pytested stand-alone this error will not show up)).

    Running live tests

    After download and installation (see above) of toardb_fastapi you can check, if everything is working in the live system via the following:
    From the top directory of the project (toardb_fastapi) open two terminals.
    In the first terminal start the application via:

    source venv/bin/activate
    uvicorn toardb.toardb:app --reload

    In the second terminal start the live tests via:

    ./production_tests.sh

    database interface (REST API)

    (more examples can be found in file production_tests.sh)

    run as:

    uvicorn toardb.toardb:app --reload

    after having followed the above installation instructions.

    For example try:
    get all data of table data (you should NOT do this!):

    http://127.0.0.1:8000/data/  

    get 4 arbitrary rows of table data:

    http://127.0.0.1:8000/data/?limit=4  

    get all data of timeseries with id=2:

    http://127.0.0.1:8000/data/2

    upload a file to the table data of the TOAR database: (at the moment every data will be uploaded to timeseries with timeseries_id=2 -- hardwired)

    1. file in current directory:
    curl -X POST -H 'Content-Type: multipart/form-data; charset=utf-8; boundary=__X_PAW_BOUNDARY__' -F "file=@o3_CO002_2012_2017_v1-0.dat" "http://127.0.0.1:8000/data/"
    1. file with absolute path:
    curl -X POST -H 'Content-Type: multipart/form-data; charset=utf-8; boundary=__X_PAW_BOUNDARY__' -F "file=@/home/sschroeder/fastAPIproject/upload_tests/o3_CO002_2012_2017_v1-0.dat" "http://127.0.0.1:8000/data/"

    get variable information:

    curl "http://127.0.0.1:8000/variables/"
    curl "http://127.0.0.1:8000/variables/o3"

    get stationmeta_core information:

    curl "http://127.0.0.1:8000/stationmeta_core/"
    curl "http://127.0.0.1:8000/stationmeta_core/China11"