The API of the TSheets killer app.
Follow the following instructions to get the project ready to use ASAP.
Be sure you have installed in your system
- Python version 3 in your path. It will install automatically pip as well.
- A virtual environment, namely venv.
-
Create and activate the environment,
In Windows:
python -m venv .venv .venv\Scripts\activate.batIn Unix based operative systems:
virtualenv .venv source .venv/bin/activate -
Install the requirements:
python3 -m pip install -r requirements/<stage>.txtThe
stagecan bedevorprod. 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.iniIt 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=2Then 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:
- Install the Microsoft ODBC driver for SQL Server (macOS).
- Github issue odbcinst: SQLRemoveDriver failed with Unable to find component name.
- Stack overflow solution to Can't open lib 'ODBC Driver 13 for SQL Server'? Sym linking issue?.
-
Set the env var
FLASK_APPtotime_tracker_apiand start the app:In Windows
set FLASK_APP=time_tracker_api flask runIn 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.
We are using Pytest](https://docs.pytest.org/en/latest/index.html) for tests. The tests are located in the package
tests and use the conventions for python test discovery.
To run the tests just execute:
python3 -m pytest -vThe 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.
To check the coverage of the tests execute
coverage run -m pytest -vTo get a report table
coverage reportTo get a full report in html
coverage htmlThen check in the htmlcov/index.html to see it
If you want that previously collected coverage data is erased, you can execute:
coverage erase
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
- Python version 3 as backend programming language. Strong typing for the win.
- Flask as the micro framework of choice.
- Flask RestPlus for building Restful APIs with Swagger.
- Pytest for tests
- Coverage for coverage
- Swagger for documentation and standardization, taking into account the API import restrictions and known issues in Azure.
Copyright 2020 ioet Inc. All Rights Reserved.