diff --git a/README.md b/README.md index 1e149522..ea331484 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ We are using Pytest](https://docs.pytest.org/en/latest/index.html) for tests. Th To run the tests just execute: -``` +```bash python3 -m pytest -v ``` diff --git a/requirements/dev.txt b/requirements/dev.txt index e7f629d0..7c12fdab 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -5,7 +5,10 @@ # For development # Tests -pytest==4.1.1 +pytest==5.2.0 + +# Mocking +pytest-mock==2.0.0 # Coverage coverage==4.5.1 \ No newline at end of file diff --git a/tests/time_entries/time_enties_namespace_test.py b/tests/time_entries/time_enties_namespace_test.py index 6d542456..b9efd63d 100644 --- a/tests/time_entries/time_enties_namespace_test.py +++ b/tests/time_entries/time_enties_namespace_test.py @@ -1,10 +1,14 @@ from flask import json -def test_list_should_return_empty_array(client): +def test_list_should_return_empty_array(mocker, client): + from time_tracker_api.time_entries.time_entries_namespace import model """Should return an empty array""" + model_mock = mocker.patch.object(model, 'find_all', return_value=[]) + response = client.get("/time-entries", follow_redirects=True) assert 200 == response.status_code json_data = json.loads(response.data) assert [] == json_data + model_mock.assert_called_once() diff --git a/time_tracker_api/__init__.py b/time_tracker_api/__init__.py index c1a26a1a..a37e669c 100644 --- a/time_tracker_api/__init__.py +++ b/time_tracker_api/__init__.py @@ -1,8 +1,9 @@ import os + from flask import Flask -def create_app(config_path='time_tracker_api.config.WhateverDevelopConfig', +def create_app(config_path='time_tracker_api.config.DefaultConfig', config_data=None): flask_app = Flask(__name__) @@ -12,7 +13,7 @@ def create_app(config_path='time_tracker_api.config.WhateverDevelopConfig', return flask_app -def init_app_config(app, config_path, config_data=None): +def init_app_config(app: Flask, config_path: str, config_data: dict = None): if config_path: app.config.from_object(config_path) else: diff --git a/time_tracker_api/config.py b/time_tracker_api/config.py index 7d6fab4b..8caec231 100644 --- a/time_tracker_api/config.py +++ b/time_tracker_api/config.py @@ -7,3 +7,6 @@ class WhateverDevelopConfig(Config): FLASK_DEBUG = True FLASK_ENV = "develop" DATABASE = "whatever" + + +DefaultConfig = WhateverDevelopConfig diff --git a/time_tracker_api/database.py b/time_tracker_api/database.py index 45ec8093..80e297da 100644 --- a/time_tracker_api/database.py +++ b/time_tracker_api/database.py @@ -25,4 +25,4 @@ def create(model_name: str): def use_whatever(): from time_tracker_api import whatever_repository - return whatever_repository \ No newline at end of file + return whatever_repository