-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_integration.py
145 lines (125 loc) · 5.25 KB
/
test_integration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import os
import os.path
import random
import unittest
import goldie
from nextmv import cloud
# Get token for communication with platform
API_KEY = os.getenv("NEXTMV_API_KEY_NEXTPIPE")
CLIENT = cloud.Client(api_key=API_KEY)
def _create_key_file(path: str):
with open(os.path.join(path, "key.json"), "w") as f:
f.write(f'{{"nextmv_api_key": "{API_KEY}"}}')
class TestPlatform(unittest.TestCase):
def test_platform(self):
try:
# Generate a random APP_ID
app = None
APP_ID = "int-test-" + "".join(random.choices("0123456789", k=8))
# Log test app id
print(f"Test app id: {APP_ID}")
# Create app for testing
app = cloud.Application.new(CLIENT, APP_ID, APP_ID, is_workflow=True)
self.assertEqual(app.id, APP_ID)
# Check if app is created
app = cloud.Application(CLIENT, APP_ID)
self.assertIsNotNone(app)
self.assertEqual(app.id, APP_ID)
# Push the app to the platform
path = os.path.join(os.path.dirname(__file__), "deploy")
current_dir = os.getcwd()
os.chdir(path)
_create_key_file(path)
app.push() # Use verbose=True for step-by-step output.
os.chdir(current_dir)
# Run the app
r = random.randint(0, 100)
polling_opts = cloud.PollingOptions(max_tries=500, max_duration=240)
result = app.new_run_with_result(input={"random": r}, polling_options=polling_opts)
self.assertTrue(hasattr(result, "error_log") and result.error_log is None)
self.assertEqual(result.output["echo"]["data"]["enhanced"], True)
self.assertEqual(result.output["echo"]["data"]["prepared"], True)
self.assertEqual(result.output["echo"]["data"]["random"], r)
finally:
# Make sure to delete the app
if app:
app.delete()
class TestExample(unittest.TestCase):
def test_locals(self):
# Create key file
path = os.path.join(os.path.dirname(__file__), "pipelines")
_create_key_file(path)
# Create base configuration
config = goldie.ConfigFileTest(
run_configuration=goldie.ConfigRun(
# We simply run the script in this directory.
cmd="python",
args=["{pipeline}"],
cwd=path,
# The script reads from stdin and writes to stdout.
input_mode=goldie.InputMode.STDIN,
output_mode=goldie.OutputMode.STDOUT,
),
comparison_configuration=goldie.ConfigComparison(
# We want to leverage the JSON structure instead of comparing raw strings.
comparison_type=goldie.ComparisonType.JSON,
),
)
# CHAIN
goldie.run_file_unittest(
test=self,
td=goldie.TestDefinition(
input_file=os.path.join(path, "chain.json"),
extra_args=[("pipeline", os.path.join(path, "chain.py"))],
),
configuration=config,
)
# FOREACH
config.comparison_configuration.json_processing_config = goldie.ConfigProcessJson(
replacements=[
goldie.JsonReplacement(path="$[0].statistics.run.duration", value=0.123),
goldie.JsonReplacement(path="$[1].statistics.run.duration", value=0.123),
goldie.JsonReplacement(path="$[2].statistics.run.duration", value=0.123),
],
)
goldie.run_file_unittest(
test=self,
td=goldie.TestDefinition(
input_file=os.path.join(path, "foreach.json"),
extra_args=[("pipeline", os.path.join(path, "foreach.py"))],
),
configuration=config,
)
# FOREACH 2 PREDECESSORS
config.comparison_configuration.json_processing_config = goldie.ConfigProcessJson(
replacements=[
goldie.JsonReplacement(path="$[0][0].statistics.run.duration", value=0.123),
goldie.JsonReplacement(path="$[1][0].statistics.run.duration", value=0.123),
goldie.JsonReplacement(path="$[2][0].statistics.run.duration", value=0.123),
],
)
goldie.run_file_unittest(
test=self,
td=goldie.TestDefinition(
input_file=os.path.join(path, "foreach-2-pred.json"),
extra_args=[("pipeline", os.path.join(path, "foreach-2-pred.py"))],
),
configuration=config,
)
# COMPLEX
config.comparison_configuration.json_processing_config = goldie.ConfigProcessJson(
replacements=[
goldie.JsonReplacement(path="$.statistics.result.duration", value="0.123"),
goldie.JsonReplacement(path="$.statistics.run.duration", value="0.123"),
],
)
goldie.run_file_unittest(
test=self,
td=goldie.TestDefinition(
input_file=os.path.join(path, "complex.json"),
extra_args=[("pipeline", os.path.join(path, "complex.py"))],
),
configuration=config,
)
if __name__ == "__main__":
unittest.main()