Skip to content

Commit 55b66ea

Browse files
authored
Merge pull request #22 from ioet/feature/Add-test-and-cov#17
Fixes #17 Add tests and coverage support
2 parents fdae56a + 6318162 commit 55b66ea

File tree

12 files changed

+132
-11
lines changed

12 files changed

+132
-11
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
__pycache__/
44
*.py[cod]
55
*$py.class
6+
*.egg-info/
7+
htmlcov/
8+
.tox/
9+
.coverage
10+
.coverage.*
611

712
# scrapy
813
.scrapy

README.md

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# time-tracker-api
22

3+
The API of the TSheets killer app.
4+
35
## Getting started
4-
Follow the following instructions to get the project ready to use ASAP:
6+
Follow the following instructions to get the project ready to use ASAP.
57

68
### Requirements
79
Be sure you have installed in your system
@@ -10,7 +12,7 @@ Be sure you have installed in your system
1012
automatically [pip](https://pip.pypa.io/en/stable/) as well.
1113
- A virtual environment, namely [venv](https://docs.python.org/3/library/venv.html).
1214

13-
## Setup
15+
### Setup
1416

1517
- Create and activate the environment,
1618

@@ -26,13 +28,16 @@ automatically [pip](https://pip.pypa.io/en/stable/) as well.
2628
virtualenv .venv
2729
source .venv/bin/activate
2830
```
31+
2932
- Install the requirements:
3033
```
31-
python3 -m pip install -r requirements/prod.txt
34+
python3 -m pip install -r requirements/<stage>.txt
3235
```
36+
37+
The `stage` can be `dev` or `prod`.
3338
Remember to do it with Python 3.
3439
35-
## How to use it
40+
### How to use it
3641
- Set the env var `FLASK_APP` to `time_tracker_api` and start the app:
3742
3843
In Windows
@@ -50,7 +55,47 @@ automatically [pip](https://pip.pypa.io/en/stable/) as well.
5055
a link to the swagger.json with the definition of the api.
5156
5257
53-
## CLI
58+
## Development
59+
60+
### Test
61+
We are using Pytest](https://docs.pytest.org/en/latest/index.html) for tests. The tests are located in the package
62+
`tests` and use the [conventions for python test discovery](https://docs.pytest.org/en/latest/goodpractices.html#test-discovery).
63+
64+
To run the tests just execute:
65+
66+
```
67+
python3 -m pytest -v
68+
```
69+
70+
The option `-v` shows which tests failed or succeeded. Have into account that you can also debug each test
71+
(test_* files) with the help of an IDE like PyCharm.
72+
73+
#### Coverage
74+
To check the coverage of the tests execute
75+
76+
```bash
77+
coverage run -m pytest -v
78+
```
79+
80+
To get a report table
81+
82+
```bash
83+
coverage report
84+
```
85+
86+
To get a full report in html
87+
```bash
88+
coverage html
89+
```
90+
Then check in the [htmlcov/index.html](./htmlcov/index.html) to see it
91+
92+
If you want that previously collected coverage data is erased, you can execute:
93+
94+
```
95+
coverage erase
96+
```
97+
98+
### CLI
5499

55100
There are available commands, aware of the API, that can be very helpful to you. You
56101
can check them out by running
@@ -64,4 +109,20 @@ as well as its correspondent options.
64109

65110
```
66111
python cli.py gen_swagger_json -f ~/Downloads/swagger.json
67-
```
112+
```
113+
114+
## Built with
115+
- [Python version 3](https://www.python.org/download/releases/3.0/) as backend programming language. Strong typing for
116+
the win.
117+
- [Flask](http://flask.pocoo.org/) as the micro framework of choice.
118+
- [Flask RestPlus](https://flask-restplus.readthedocs.io/en/stable/) for building Restful APIs with Swagger.
119+
- [Pytest](https://docs.pytest.org/en/latest/index.html) for tests
120+
- [Coverage](https://coverage.readthedocs.io/en/coverage-4.5.4/) for coverage
121+
- [Swagger](https://swagger.io/) for documentation and standardization, taking into account the
122+
[API import restrictions and known issues](https://docs.microsoft.com/en-us/azure/api-management/api-management-api-import-restrictions)
123+
in Azure.
124+
125+
126+
## License
127+
128+
Copyright 2020 ioet Inc. All Rights Reserved.

cli.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
#!/usr/bin/env python3
22

3-
print("****************")
4-
print("TimeTracker CLI")
5-
print("****************")
6-
73
import os
84

95
from flask import json
@@ -63,4 +59,8 @@ def save_data(data: str, filename: str) -> None:
6359

6460

6561
if __name__ == "__main__":
62+
print("****************")
63+
print("TimeTracker CLI")
64+
print("****************")
65+
6666
cli_manager.run()

requirements/dev.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# requirements/dev.txt
2+
3+
-r prod.txt
4+
5+
# For development
6+
7+
# Tests
8+
pytest==4.1.1
9+
10+
# Coverage
11+
coverage==4.5.1

setup.cfg

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[tool:pytest]
2+
testpaths = tests
3+
addopts = -p no:warnings
4+
5+
[coverage:run]
6+
branch = True
7+
source =
8+
time_tracker_api

setup.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from setuptools import setup, find_packages
2+
3+
setup(
4+
name="time-tracker-api",
5+
packages=find_packages(),
6+
include_package_data=True,
7+
)

tests/__init__.py

Whitespace-only changes.

tests/conftest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
import pytest
3+
4+
from time_tracker_api import create_app
5+
6+
@pytest.fixture(scope='session')
7+
def app():
8+
"""An instance of the app for tests"""
9+
return create_app()
10+
11+
@pytest.fixture
12+
def client(app):
13+
"""A test client for the app."""
14+
with app.test_client() as c:
15+
return c

tests/projects/__init__.py

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from flask import json
2+
3+
4+
def test_list_should_return_nothing(client):
5+
"""Should return an empty array"""
6+
response = client.get("/projects", follow_redirects=True)
7+
8+
assert 200 == response.status_code
9+
10+
json_data = json.loads(response.data)
11+
assert [] == json_data

0 commit comments

Comments
 (0)