Skip to content

ioet/time-tracker-backend

Repository files navigation

time-tracker-api

This is the mono-repository for the backend services and their common codebase

Getting started

Follow the following instructions to get the project ready to use ASAP.

Requirements

Be sure you have installed in your system

Setup

  • Create and activate the environment,

    In Windows:

    python -m venv .venv
    .venv\Scripts\activate.bat
    

    In Unix based operative systems:

    virtualenv .venv
    source .venv/bin/activate
    
  • Install the requirements:

    python3 -m pip install -r requirements/<app>/<stage>.txt
    

    Where is one of the executable app namespace, e.g. time_tracker_api. The stage can be

    • dev: Used for working locally
    • prod: For anything deployed

    Remember to do it with Python 3.

  • Install the Microsoft ODBC Driver for SQL Server in your operative system. Then you have to check out what is the name of the SQL Driver installation. Check it out with:

vim /usr/local/etc/odbcinst.ini

It may display something like

[ODBC Driver 17 for SQL Server] 
Description=Microsoft ODBC Driver 17 for SQL Server 
Driver=/usr/local/lib/libmsodbcsql.17.dylib 
UsageCount=2

Then specify the driver name, in this case DBC Driver 17 for SQL Server in the DATABASE_URI, e.g.:

DATABASE_URI=mssql+pyodbc://<user>:<password>@time-tracker-srv.database.windows.net/<database>?driver\=ODBC Driver 17 for SQL Server

To troubleshoot issues regarding this part please check out:

How to use it

  • Set the env var FLASK_APP to time_tracker_api and start the app:

    In Windows

    set FLASK_APP=time_tracker_api
    flask run
    

    In Unix based operative systems:

    export FLASK_APP=time_tracker_api
    flask run
    
  • Open http://127.0.0.1:5000/ in a browser. You will find in the presented UI a link to the swagger.json with the definition of the api.

Development

Test

We are using Pytest for tests. The tests are located in the package tests and use the conventions for python test discovery.

Integration tests

The integrations tests verifies that all the components of the app are working well together. These are the default tests we should run:

python3 -m pytest -v --ignore=tests/commons/data_access_layer/azure/sql_repository_test.py

As you may have noticed we are ignoring the tests related with the repository.

System tests

In addition to the integration testing we might include tests to the data access layer in order to verify that the persisted data is being managed the right way, i.e. it actually works. We may classify the execution of all the existing tests as system testing:

python3 -m pytest -v

The database tests will be done in the table tests of the database specified by the variable DATABASE_URI. If this variable is not specified it will automatically connect to SQLite database in-memory. This will do, because we are using SQL Alchemy to be able connect to any SQL database maintaining the same codebase.

The option -v shows which tests failed or succeeded. Have into account that you can also debug each test (test_* files) with the help of an IDE like PyCharm.

Coverage

To check the coverage of the tests execute

 coverage run -m pytest -v

To get a report table

 coverage report

To get a full report in html

 coverage html

Then check in the htmlcov/index.html to see it.

If you want that previously collected coverage data is erased, you can execute:

coverage erase

CLI

There are available commands, aware of the API, that can be very helpful to you. You can check them out by running

python cli.py

If you want to run an specific command, e.g. gen_swagger_json, specify it as a param as well as its correspondent options.

python cli.py gen_swagger_json -f ~/Downloads/swagger.json

Run as docker container

  1. Build image
docker build -t time_tracker_api:local .
  1. Run app
docker run -p 5000:5000 time_tracker_api:local
  1. Visit 127.0.0.1:5000

Built with

License

Copyright 2020 ioet Inc. All Rights Reserved.

About

API to provide data to the time tracker project

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 37

Languages