Skip to content

Commit 25ac870

Browse files
πŸ“Œ ISSUE-#23: Updated unit tests
1 parent 6ac7f65 commit 25ac870

File tree

7 files changed

+94
-59
lines changed

7 files changed

+94
-59
lines changed

β€Žtests/core/decorators/test_action.pyβ€Ž

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,10 @@
99
from dotflow.core.decorators.action import action
1010

1111

12-
def dummy_step():
13-
pass
14-
15-
16-
def dummy_step_with_fail():
17-
logging.error("Fail!")
18-
raise Exception("Fail!")
19-
20-
21-
def dummy_step_previous_context(previous_context):
22-
logging.debug(previous_context.storage)
12+
from tests.mocks import (
13+
simple_step,
14+
dummy_step_previous_context
15+
)
2316

2417

2518
class TestMethodAction(unittest.TestCase):
@@ -29,7 +22,7 @@ def inject_fixtures(self, caplog):
2922
self._caplog = caplog
3023

3124
def test_instantiating_action_method(self):
32-
inside = action(dummy_step)
25+
inside = action(simple_step)
3326
decorated_function = inside()
3427

3528
self.assertIsInstance(decorated_function, Context)
Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,11 @@
88
from dotflow.core.context import Context
99
from dotflow.core.action import Action
1010

11-
12-
def dummy_step():
13-
pass
14-
15-
16-
def dummy_step_with_fail():
17-
logging.error("Fail!")
18-
raise Exception("Fail!")
19-
20-
21-
def dummy_step_previous_context(previous_context):
22-
logging.debug(previous_context.storage)
11+
from tests.mocks import (
12+
simple_step,
13+
dummy_step_previous_context,
14+
dummy_step_with_fail
15+
)
2316

2417

2518
class TestClassActions(unittest.TestCase):
@@ -31,21 +24,21 @@ def inject_fixtures(self, caplog):
3124
def test_instantiating_action_class(self):
3225
number_of_retries = 1
3326

34-
inside = Action(dummy_step)
27+
inside = Action(simple_step)
3528
decorated_function = inside()
3629

3730
self.assertEqual(inside.retry, number_of_retries)
38-
self.assertEqual(inside.func, dummy_step)
31+
self.assertEqual(inside.func, simple_step)
3932
self.assertIsInstance(decorated_function, Context)
4033

4134
def test_instantiating_action_class_with_retry(self):
4235
number_of_retries = 5
4336

44-
inside = Action(dummy_step, retry=number_of_retries)
37+
inside = Action(simple_step, retry=number_of_retries)
4538
decorated_function = inside()
4639

4740
self.assertEqual(inside.retry, number_of_retries)
48-
self.assertEqual(inside.func, dummy_step)
41+
self.assertEqual(inside.func, simple_step)
4942
self.assertIsInstance(decorated_function, Context)
5043

5144
def test_instantiating_action_class_with_fail_retry(self):

β€Žtests/core/test_context.pyβ€Ž

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,18 @@
99
class TestContext(unittest.TestCase):
1010

1111
def setUp(self):
12-
self.example = {"foo": "bar"}
12+
self.content = {"foo": "bar"}
1313

1414
def test_instantiating_class(self):
15-
context = Context(storage=self.example)
15+
context = Context(storage=self.content)
1616

1717
self.assertIsInstance(context.time, datetime)
18-
self.assertEqual(context.storage, self.example)
18+
self.assertEqual(context.storage, self.content)
19+
20+
def test_instantiates_context_with_context(self):
21+
context = Context(
22+
storage=Context(storage=self.content)
23+
)
24+
25+
self.assertIsInstance(context.time, datetime)
26+
self.assertEqual(context.storage, self.content)

β€Žtests/core/test_task.pyβ€Ž

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,11 @@
44

55
from dotflow.core.context import Context
66
from dotflow.core.task import Task
7-
from dotflow.core.action import Action as action
87

9-
10-
@action
11-
def dummy_step():
12-
pass
13-
14-
15-
def dummy_callback(*args, **kwargs):
16-
pass
8+
from tests.mocks import (
9+
action_step,
10+
simple_callback
11+
)
1712

1813

1914
class TestTask(unittest.TestCase):
@@ -27,8 +22,8 @@ def test_instantiating_class(self):
2722
initial_context=Context(
2823
storage=self.example
2924
),
30-
step=dummy_step,
31-
callback=dummy_callback
25+
step=action_step,
26+
callback=simple_callback
3227
)
3328

3429
def test_task_id(self):
@@ -37,8 +32,8 @@ def test_task_id(self):
3732
initial_context=Context(
3833
storage=self.example
3934
),
40-
step=dummy_step,
41-
callback=dummy_callback
35+
step=action_step,
36+
callback=simple_callback
4237
)
4338

4439
self.assertEqual(task.task_id, 0)
@@ -49,8 +44,8 @@ def test_initial_context(self):
4944
initial_context=Context(
5045
storage=self.example
5146
),
52-
step=dummy_step,
53-
callback=dummy_callback
47+
step=action_step,
48+
callback=simple_callback
5449
)
5550

5651
self.assertEqual(

β€Žtests/core/test_task_build.pyβ€Ž

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33
import unittest
44

55
from dotflow.core.context import Context
6+
from dotflow.core.exception import MissingStepDecorator
67
from dotflow.core.task import Task, TaskBuilder
7-
from dotflow.core.action import Action as action
88
from dotflow.core.utils import callback
99

10-
11-
@action
12-
def dummy_step():
13-
pass
10+
from tests.mocks import action_step, simple_step
1411

1512

1613
class TestTaskBuild(unittest.TestCase):
@@ -25,7 +22,7 @@ def test_instantiating_class(self):
2522

2623
def test_add_method(self):
2724
task = TaskBuilder()
28-
task.add(step=dummy_step)
25+
task.add(step=action_step)
2926

3027
self.assertEqual(task.queu[0].task_id, 0)
3128
self.assertIsInstance(task.queu[0], Task)
@@ -35,7 +32,7 @@ def test_add_method(self):
3532
def test_add_method_with_class_context(self):
3633
task = TaskBuilder()
3734
task.add(
38-
step=dummy_step,
35+
step=action_step,
3936
initial_context=Context(
4037
storage=self.example
4138
)
@@ -54,7 +51,7 @@ def test_add_method_with_class_context(self):
5451
def test_add_method_without_class_context(self):
5552
task = TaskBuilder()
5653
task.add(
57-
step=dummy_step,
54+
step=action_step,
5855
initial_context=self.example
5956
)
6057

@@ -71,9 +68,30 @@ def test_add_method_without_class_context(self):
7168
def test_count_method(self):
7269
task = TaskBuilder()
7370

74-
initial_count = task.count()
75-
self.assertEqual(initial_count, 0)
71+
initial_count = 0
72+
final_count = 1
73+
74+
self.assertEqual(task.count(), initial_count)
75+
76+
task.add(step=action_step)
77+
78+
self.assertEqual(task.count(), final_count)
79+
80+
def test_clear_method(self):
81+
task = TaskBuilder()
82+
83+
expected_count_before = 1
84+
expected_count_after = 0
85+
86+
task.add(step=action_step)
87+
self.assertEqual(task.count(), expected_count_before)
88+
89+
task.clear()
90+
91+
self.assertEqual(task.count(), expected_count_after)
92+
93+
def test_with_step_without_decorator(self):
94+
task = TaskBuilder()
7695

77-
task.add(step=dummy_step)
78-
final_count = task.count()
79-
self.assertEqual(final_count, 1)
96+
with self.assertRaises(MissingStepDecorator):
97+
task.add(step=simple_step)

β€Žtests/core/test_workflow.pyβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Test context of workflow"""

β€Žtests/mocks.pyβ€Ž

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""Module Mock"""
2+
3+
import logging
4+
5+
from dotflow.core.action import Action as action
6+
7+
8+
@action
9+
def action_step() -> None:
10+
pass
11+
12+
13+
def simple_step() -> None:
14+
pass
15+
16+
17+
def simple_callback(*args, **kwargs):
18+
pass
19+
20+
21+
def dummy_step_with_fail() -> None:
22+
logging.error("Fail!")
23+
raise Exception("Fail!")
24+
25+
26+
def dummy_step_previous_context(previous_context):
27+
logging.debug(previous_context.storage)

0 commit comments

Comments
Β (0)