Skip to content

Commit 37882c2

Browse files
author
Alan Christie
committed
fix: Better project ID location
1 parent f6c737f commit 37882c2

File tree

5 files changed

+83
-16
lines changed

5 files changed

+83
-16
lines changed

tests/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""An emulation of the Data Manager config module.
2+
A location of common constants."""
3+
4+
# The project ID used in the tests (there is only one atm)
5+
TEST_PROJECT_ID: str = "project-00000000-0000-0000-0000-000000000001"

tests/instance_launcher.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from informaticsmatters.protobuf.datamanager.pod_message_pb2 import PodMessage
88

99
from tests.api_adapter import UnitTestAPIAdapter
10+
from tests.config import TEST_PROJECT_ID
1011
from tests.message_dispatcher import UnitTestMessageDispatcher
1112
from workflow.workflow_abc import InstanceLauncher, LaunchResult
1213

@@ -52,8 +53,7 @@ def launch(
5253
assert workflow_id
5354
assert step_specification
5455

55-
# Project must be `project-00000000-0000-0000-0000-000000000001`
56-
assert project_id == "project-00000000-0000-0000-0000-000000000001"
56+
assert project_id == TEST_PROJECT_ID
5757

5858
# We're passed a RunningWorkflowStep ID but a record is expected to have been
5959
# created bt the caller, we simply create instance records.

tests/test_test_api_adapter.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
pytestmark = pytest.mark.unit
66

77
from tests.api_adapter import UnitTestAPIAdapter
8+
from tests.config import TEST_PROJECT_ID
89

910

1011
def test_get_nop_job():
@@ -76,7 +77,7 @@ def test_create_running_workflow():
7677
# Act
7778
response = utaa.create_running_workflow(
7879
workflow_id=response["id"],
79-
project_id="project-00000000-0000-0000-0000-000000000001",
80+
project_id=TEST_PROJECT_ID,
8081
)
8182

8283
# Assert
@@ -89,7 +90,7 @@ def test_get_running_workflow():
8990
response = utaa.create_workflow(workflow_definition={"name": "blah"})
9091
wfid = response["id"]
9192
response = utaa.create_running_workflow(
92-
workflow_id=wfid, project_id="project-00000000-0000-0000-0000-000000000001"
93+
workflow_id=wfid, project_id=TEST_PROJECT_ID
9394
)
9495
rwfid = response["id"]
9596

@@ -108,7 +109,7 @@ def test_set_running_workflow_done_when_success():
108109
response = utaa.create_workflow(workflow_definition={"name": "blah"})
109110
response = utaa.create_running_workflow(
110111
workflow_id=response["id"],
111-
project_id="project-00000000-0000-0000-0000-000000000001",
112+
project_id=TEST_PROJECT_ID,
112113
)
113114
rwfid = response["id"]
114115

@@ -127,7 +128,7 @@ def test_set_running_workflow_done_when_failed():
127128
response = utaa.create_workflow(workflow_definition={"name": "blah"})
128129
response = utaa.create_running_workflow(
129130
workflow_id=response["id"],
130-
project_id="project-00000000-0000-0000-0000-000000000001",
131+
project_id=TEST_PROJECT_ID,
131132
)
132133
rwfid = response["id"]
133134

@@ -146,7 +147,7 @@ def test_create_running_workflow_step():
146147
response = utaa.create_workflow(workflow_definition={"name": "blah"})
147148
response = utaa.create_running_workflow(
148149
workflow_id=response["id"],
149-
project_id="project-00000000-0000-0000-0000-000000000001",
150+
project_id=TEST_PROJECT_ID,
150151
)
151152

152153
# Act
@@ -164,7 +165,7 @@ def test_get_running_workflow_step():
164165
response = utaa.create_workflow(workflow_definition={"name": "blah"})
165166
wfid = response["id"]
166167
response = utaa.create_running_workflow(
167-
workflow_id=wfid, project_id="project-00000000-0000-0000-0000-000000000001"
168+
workflow_id=wfid, project_id=TEST_PROJECT_ID
168169
)
169170
rwfid = response["id"]
170171
response = utaa.create_running_workflow_step(
@@ -188,7 +189,7 @@ def test_get_running_workflow_steps():
188189
response = utaa.create_workflow(workflow_definition={"name": "blah"})
189190
wfid = response["id"]
190191
response = utaa.create_running_workflow(
191-
workflow_id=wfid, project_id="project-00000000-0000-0000-0000-000000000001"
192+
workflow_id=wfid, project_id=TEST_PROJECT_ID
192193
)
193194
rwfid = response["id"]
194195
response = utaa.create_running_workflow_step(

tests/test_test_instance_launcher.py

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
pytestmark = pytest.mark.unit
66

77
from tests.api_adapter import UnitTestAPIAdapter
8+
from tests.config import TEST_PROJECT_ID
89
from tests.instance_launcher import UnitTestInstanceLauncher
910
from tests.message_dispatcher import UnitTestMessageDispatcher
1011
from tests.message_queue import UnitTestMessageQueue
@@ -21,14 +22,14 @@ def basic_launcher():
2122
return [api_adapter, instance_launcher]
2223

2324

24-
def test_get_nop_job(basic_launcher):
25+
def test_launch_nop(basic_launcher):
2526
# Arrange
2627
utaa = basic_launcher[0]
2728
launcher = basic_launcher[1]
2829
response = utaa.create_workflow(workflow_definition={"name": "blah"})
2930
response = utaa.create_running_workflow(
3031
workflow_id=response["id"],
31-
project_id="project-00000000-0000-0000-0000-000000000001",
32+
project_id=TEST_PROJECT_ID,
3233
)
3334
response = utaa.create_running_workflow_step(
3435
running_workflow_id=response["id"], step="step-1"
@@ -37,14 +38,75 @@ def test_get_nop_job(basic_launcher):
3738

3839
# Act
3940
result = launcher.launch(
40-
project_id="project-00000000-0000-0000-0000-000000000001",
41+
project_id=TEST_PROJECT_ID,
4142
workflow_id="workflow-00000000-0000-0000-0000-000000000001",
4243
running_workflow_step_id=rwfsid,
4344
workflow_definition={},
44-
step_specification={"job": "nop", "variables": {"x": 1}},
45+
step_specification={"job": "nop"},
4546
)
4647

4748
# Assert
4849
assert result.error == 0
4950
assert result.command.startswith("python ")
5051
assert result.command.endswith("tests/jobs/nop.py")
52+
53+
54+
def test_launch_nop_fail(basic_launcher):
55+
# Arrange
56+
utaa = basic_launcher[0]
57+
launcher = basic_launcher[1]
58+
response = utaa.create_workflow(workflow_definition={"name": "blah"})
59+
response = utaa.create_running_workflow(
60+
workflow_id=response["id"],
61+
project_id=TEST_PROJECT_ID,
62+
)
63+
response = utaa.create_running_workflow_step(
64+
running_workflow_id=response["id"], step="step-1"
65+
)
66+
rwfsid = response["id"]
67+
68+
# Act
69+
result = launcher.launch(
70+
project_id=TEST_PROJECT_ID,
71+
workflow_id="workflow-00000000-0000-0000-0000-000000000001",
72+
running_workflow_step_id=rwfsid,
73+
workflow_definition={},
74+
step_specification={"job": "nop-fail"},
75+
)
76+
77+
# Assert
78+
assert result.error == 0
79+
assert result.command.startswith("python ")
80+
assert result.command.endswith("tests/jobs/nop-fail.py")
81+
82+
83+
def test_launch_smiles_to_file(basic_launcher):
84+
# Arrange
85+
utaa = basic_launcher[0]
86+
launcher = basic_launcher[1]
87+
response = utaa.create_workflow(workflow_definition={"name": "blah"})
88+
response = utaa.create_running_workflow(
89+
workflow_id=response["id"],
90+
project_id=TEST_PROJECT_ID,
91+
)
92+
response = utaa.create_running_workflow_step(
93+
running_workflow_id=response["id"], step="step-1"
94+
)
95+
rwfsid = response["id"]
96+
97+
# Act
98+
result = launcher.launch(
99+
project_id=TEST_PROJECT_ID,
100+
workflow_id="workflow-00000000-0000-0000-0000-000000000001",
101+
running_workflow_step_id=rwfsid,
102+
workflow_definition={},
103+
step_specification={
104+
"job": "smiles-to-file",
105+
"variables": {"smiles": "C1=CC=CC=C1", "outputFile": "output.smi"},
106+
},
107+
)
108+
109+
# Assert
110+
assert result.error == 0
111+
assert result.command.startswith("python ")
112+
assert result.command.endswith("tests/jobs/smiles-to-file.py")

tests/test_workflow_engine_examples.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from informaticsmatters.protobuf.datamanager.workflow_message_pb2 import WorkflowMessage
1212

1313
from tests.api_adapter import UnitTestAPIAdapter
14+
from tests.config import TEST_PROJECT_ID
1415
from tests.instance_launcher import UnitTestInstanceLauncher
1516
from tests.message_dispatcher import UnitTestMessageDispatcher
1617
from tests.message_queue import UnitTestMessageQueue
@@ -71,9 +72,7 @@ def start_workflow(md, da, workflow_file_name) -> str:
7172
assert wfid
7273
print(f"Created workflow definition {wfid}")
7374
# 2.
74-
response = da.create_running_workflow(
75-
workflow_id=wfid, project_id="project-00000000-0000-0000-0000-000000000001"
76-
)
75+
response = da.create_running_workflow(workflow_id=wfid, project_id=TEST_PROJECT_ID)
7776
r_wfid = response["id"]
7877
assert r_wfid
7978
print(f"Created running workflow {r_wfid}")

0 commit comments

Comments
 (0)