Skip to content

Commit 1c2fb43

Browse files
author
EliuX
committed
Closes #23 Add mocking support
1 parent b94a95f commit 1c2fb43

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

requirements/dev.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
# For development
66

77
# Tests
8-
pytest==4.1.1
8+
pytest==5.2.0
9+
10+
# Mocking
11+
pytest-mock==2.0.0
912

1013
# Coverage
1114
coverage==4.5.1
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
from flask import json
22

3-
def test_list_should_return_empty_array(client):
3+
def test_list_should_return_empty_array(mocker, client):
4+
from time_tracker_api.time_entries.time_entries_namespace import model
45
"""Should return an empty array"""
6+
model_mock = mocker.patch.object(model, 'find_all', return_value=[])
7+
58
response = client.get("/time-entries", follow_redirects=True)
69

710
assert 200 == response.status_code
811

912
json_data = json.loads(response.data)
1013
assert [] == json_data
14+
model_mock.assert_called_once()

time_tracker_api/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import os
2+
23
from flask import Flask
34

45

5-
def create_app(config_path='time_tracker_api.config.WhateverDevelopConfig',
6+
def create_app(config_path='time_tracker_api.config.DefaultConfig',
67
config_data=None):
78
flask_app = Flask(__name__)
89

@@ -12,7 +13,7 @@ def create_app(config_path='time_tracker_api.config.WhateverDevelopConfig',
1213
return flask_app
1314

1415

15-
def init_app_config(app, config_path, config_data=None):
16+
def init_app_config(app: Flask, config_path: str, config_data: dict = None):
1617
if config_path:
1718
app.config.from_object(config_path)
1819
else:

time_tracker_api/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ class WhateverDevelopConfig(Config):
77
FLASK_DEBUG = True
88
FLASK_ENV = "develop"
99
DATABASE = "whatever"
10+
11+
12+
DefaultConfig = WhateverDevelopConfig

time_tracker_api/database.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ def create(model_name: str):
2525

2626
def use_whatever():
2727
from time_tracker_api import whatever_repository
28-
return whatever_repository
28+
return whatever_repository

0 commit comments

Comments
 (0)