Skip to content

Commit d1e687c

Browse files
author
Sergio García Prado
committed
ISSUE #469
* Improve tests.
1 parent 0264f7c commit d1e687c

File tree

3 files changed

+68
-9
lines changed
  • packages/plugins

3 files changed

+68
-9
lines changed

packages/plugins/minos-database-aiopg/minos/plugins/aiopg/factories/saga.py

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
)
44

55
import json
6+
from typing import (
7+
Any,
8+
Optional,
9+
)
610
from uuid import (
711
UUID,
812
)
@@ -88,10 +92,28 @@ def build_create(self) -> DatabaseOperation:
8892
]
8993
)
9094

91-
def build_store(self, uuid: UUID, **kwargs) -> DatabaseOperation:
95+
def build_store(
96+
self,
97+
uuid: UUID,
98+
definition: dict[str, Any],
99+
status: str,
100+
executed_steps: list[dict[str, Any]],
101+
paused_step: Optional[dict[str, Any]],
102+
context: str,
103+
already_rollback: bool,
104+
user: Optional[UUID],
105+
**kwargs,
106+
) -> DatabaseOperation:
92107
"""Build the database operation to store a saga execution.
93108
94109
:param uuid: The identifier of the saga execution.
110+
:param definition: The ``Saga`` definition.
111+
:param context: The execution context.
112+
:param status: The status of the execution.
113+
:param executed_steps: The executed steps of the execution.
114+
:param paused_step: The paused step of the execution.
115+
:param already_rollback: ``True`` if already rollback of ``False`` otherwise.
116+
:param user: The user that launched the execution.
95117
:param kwargs: The attributes of the saga execution.
96118
:return: A ``DatabaseOperation`` instance.
97119
"""
@@ -123,11 +145,17 @@ def build_store(self, uuid: UUID, **kwargs) -> DatabaseOperation:
123145
;
124146
"""
125147
)
126-
# FIXME
127-
kwargs["definition"] = json.dumps(kwargs["definition"])
128-
kwargs["executed_steps"] = json.dumps(kwargs["executed_steps"])
129-
kwargs["paused_step"] = json.dumps(kwargs["paused_step"])
130-
return AiopgDatabaseOperation(query, {"uuid": uuid} | kwargs)
148+
parameters = {
149+
"uuid": uuid,
150+
"definition": json.dumps(definition),
151+
"status": status,
152+
"executed_steps": json.dumps(executed_steps),
153+
"paused_step": json.dumps(paused_step),
154+
"context": context,
155+
"already_rollback": already_rollback,
156+
"user": user,
157+
}
158+
return AiopgDatabaseOperation(query, parameters)
131159

132160
def build_load(self, uuid: UUID) -> DatabaseOperation:
133161
"""Build the database operation to load a saga execution.

packages/plugins/minos-database-aiopg/tests/test_aiopg/test_factories/test_saga/test_factories.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,29 @@
88
AiopgSagaExecutionDatabaseOperationFactory,
99
)
1010
from minos.saga import (
11+
Saga,
12+
SagaExecution,
1113
SagaExecutionDatabaseOperationFactory,
1214
)
1315

1416

17+
def _fn(context):
18+
pass
19+
20+
1521
class TestAiopgSagaExecutionDatabaseOperationFactory(unittest.TestCase):
22+
def setUp(self) -> None:
23+
super().setUp()
24+
25+
self.execution = SagaExecution.from_definition(Saga().local_step(_fn).commit())
26+
1627
def test_is_subclass(self):
1728
self.assertTrue(issubclass(AiopgSagaExecutionDatabaseOperationFactory, SagaExecutionDatabaseOperationFactory))
1829

19-
@unittest.skip
2030
def test_build_store(self):
2131
factory = AiopgSagaExecutionDatabaseOperationFactory()
2232

23-
operation = factory.build_store(uuid4(), foo="bar")
33+
operation = factory.build_store(**self.execution.raw)
2434
self.assertIsInstance(operation, AiopgDatabaseOperation)
2535

2636
def test_build_load(self):

packages/plugins/minos-database-lmdb/tests/test_lmdb/test_factories/test_saga/test_factories.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,45 @@
33
uuid4,
44
)
55

6+
from minos.common import (
7+
ComposedDatabaseOperation,
8+
)
69
from minos.plugins.lmdb import (
710
LmdbDatabaseOperation,
811
LmdbDatabaseOperationType,
912
LmdbSagaExecutionDatabaseOperationFactory,
1013
)
1114
from minos.saga import (
15+
Saga,
16+
SagaExecution,
1217
SagaExecutionDatabaseOperationFactory,
1318
)
1419

1520

21+
def _fn(context):
22+
pass
23+
24+
1625
class TestLmdbSagaExecutionDatabaseOperationFactory(unittest.TestCase):
26+
def setUp(self) -> None:
27+
super().setUp()
28+
29+
self.execution = SagaExecution.from_definition(Saga().local_step(_fn).commit())
30+
1731
def test_is_subclass(self):
1832
self.assertTrue(issubclass(LmdbSagaExecutionDatabaseOperationFactory, SagaExecutionDatabaseOperationFactory))
1933

34+
def test_build_create(self):
35+
factory = LmdbSagaExecutionDatabaseOperationFactory()
36+
37+
operation = factory.build_create()
38+
self.assertIsInstance(operation, ComposedDatabaseOperation)
39+
self.assertEqual(0, len(operation.operations))
40+
2041
def test_build_store(self):
2142
factory = LmdbSagaExecutionDatabaseOperationFactory()
2243

23-
operation = factory.build_store(uuid4(), foo="bar")
44+
operation = factory.build_store(**self.execution.raw)
2445
self.assertIsInstance(operation, LmdbDatabaseOperation)
2546
self.assertEqual(LmdbDatabaseOperationType.CREATE, operation.type_)
2647

0 commit comments

Comments
 (0)