Skip to content

Commit d2f5d5b

Browse files
committed
refactor: TT-201 add fucntion to add update last entry flag in model
1 parent 9929129 commit d2f5d5b

File tree

2 files changed

+59
-7
lines changed

2 files changed

+59
-7
lines changed

tests/time_tracker_api/api_test.py

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,55 @@ def test_remove_required_constraint():
3030
from flask_restplus import Namespace
3131

3232
ns = Namespace('todos', description='Namespace for testing')
33-
sample_model = ns.model('Todo', {
34-
'id': fields.Integer(readonly=True, description='The task unique identifier'),
35-
'task': fields.String(required=True, description='The task details'),
36-
'done': fields.Boolean(required=False, description='Has it being done or not')
37-
})
33+
sample_model = ns.model(
34+
'Todo',
35+
{
36+
'id': fields.Integer(
37+
readonly=True, description='The task unique identifier'
38+
),
39+
'task': fields.String(
40+
required=True, description='The task details'
41+
),
42+
'done': fields.Boolean(
43+
required=False, description='Has it being done or not'
44+
),
45+
},
46+
)
3847

3948
new_model = remove_required_constraint(sample_model)
4049

4150
assert new_model is not sample_model
4251

4352
for attrib in sample_model:
44-
assert new_model[attrib].required is False, "No attribute should be required"
45-
assert new_model[attrib] is not sample_model[attrib], "No attribute should be required"
53+
assert (
54+
new_model[attrib].required is False
55+
), "No attribute should be required"
56+
assert (
57+
new_model[attrib] is not sample_model[attrib]
58+
), "No attribute should be required"
59+
60+
61+
def test_add_update_last_entry_flag():
62+
from time_tracker_api.api import add_update_last_entry_flag
63+
from flask_restplus import fields
64+
from flask_restplus import Namespace
65+
66+
ns = Namespace('todos', description='Namespace for testing')
67+
sample_model = ns.model(
68+
'Todo',
69+
{
70+
'id': fields.Integer(
71+
readonly=True, description='The task unique identifier'
72+
),
73+
'task': fields.String(
74+
required=True, description='The task details'
75+
),
76+
},
77+
)
78+
79+
new_model = add_update_last_entry_flag(sample_model)
80+
81+
assert new_model is not sample_model
82+
83+
update_last_entry_flag = new_model.get('update_last_entry')
84+
assert update_last_entry_flag is not None

time_tracker_api/api.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ def remove_required_constraint(model: Model):
3434
return result
3535

3636

37+
def add_update_last_entry_flag(time_entry_model: Model):
38+
time_entry_flag = {
39+
'update_last_entry': fields.Boolean(
40+
title='Update last entry',
41+
required=False,
42+
description='Flag that indicates if the last time entry is updated',
43+
example=True,
44+
)
45+
}
46+
new_model = time_entry_model.clone('TimeEntryInput', time_entry_flag)
47+
return new_model
48+
49+
3750
def create_attributes_filter(
3851
ns: namespace, model: Model, filter_attrib_names: list
3952
) -> RequestParser:

0 commit comments

Comments
 (0)