Skip to content

Commit 94d99e9

Browse files
author
Alan Christie
committed
test: Test for task create/get
1 parent 9822f9b commit 94d99e9

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

tests/api_adapter.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,17 @@ def create_instance(self, *, running_workflow_step_id: str) -> Dict[str, Any]:
109109
"running_workflow_step": running_workflow_step_id,
110110
}
111111
self._instances[instance_id] = record
112-
return {"id": running_workflow_step_id}
112+
return {"id": instance_id}
113113

114114
def get_instance(self, *, instance_id: str) -> Dict[str, Any]:
115115
if instance_id not in self._instances:
116116
return {}
117-
return {self._instances[instance_id]}
117+
return self._instances[instance_id]
118118

119119
def create_task(self, *, instance_id: str) -> Dict[str, Any]:
120120
next_id: int = len(self._instances) + 1
121121
task_id: str = _INSTANCE_ID_FORMAT.format(id=next_id)
122122
record = {
123-
"instance_id": instance_id,
124123
"done": False,
125124
"exit_code": 0,
126125
}
@@ -130,7 +129,7 @@ def create_task(self, *, instance_id: str) -> Dict[str, Any]:
130129
def get_task(self, *, task_id: str) -> Dict[str, Any]:
131130
if task_id not in self._tasks:
132131
return {}
133-
return {self._tasks[task_id]}
132+
return self._tasks[task_id]
134133

135134
def get_job(
136135
self, *, collection: str, job: str, version: str

tests/test_test_api_adapter.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,52 @@ def test_get_running_workflow_steps():
158158
assert rwfs["running_workflow_step"]["step"] == "step-1"
159159
assert not rwfs["running_workflow_step"]["done"]
160160
assert rwfs["running_workflow_step"]["running_workflow"] == rwfid
161+
162+
163+
def test_create_instance():
164+
# Arrange
165+
utaa = UnitTestAPIAdapter()
166+
167+
# Act
168+
response = utaa.create_instance(running_workflow_step_id="r-workflow-step-000")
169+
170+
# Assert
171+
assert "id" in response
172+
173+
174+
def test_create_and_get_instance():
175+
# Arrange
176+
utaa = UnitTestAPIAdapter()
177+
response = utaa.create_instance(running_workflow_step_id="r-workflow-step-000")
178+
instance_id = response["id"]
179+
180+
# Act
181+
response = utaa.get_instance(instance_id=instance_id)
182+
183+
# Assert
184+
assert response["running_workflow_step"] == "r-workflow-step-000"
185+
186+
187+
def test_create_task():
188+
# Arrange
189+
utaa = UnitTestAPIAdapter()
190+
191+
# Act
192+
response = utaa.create_task(instance_id="instance-000")
193+
194+
# Assert
195+
assert "id" in response
196+
197+
198+
def test_create_and_get_task():
199+
# Arrange
200+
utaa = UnitTestAPIAdapter()
201+
response = utaa.create_task(instance_id="instance-000")
202+
task_id = response["id"]
203+
204+
# Act
205+
response = utaa.get_task(task_id=task_id)
206+
207+
# Assert
208+
assert not response["done"]
209+
assert response["exit_code"] == 0

0 commit comments

Comments
 (0)