-
Notifications
You must be signed in to change notification settings - Fork 1
/
conftest.py
249 lines (175 loc) · 5.96 KB
/
conftest.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# Copyright (c) 2023-2024 tracetronic GmbH
#
# SPDX-License-Identifier: MIT
import json
import os
from unittest.mock import patch
import pytest
from testguide_report_generator.model.TestCase import (
TestStep,
Verdict,
TestStepFolder,
Parameter,
Direction,
Artifact,
Constant,
Attribute,
Review,
TestCase,
TestStepArtifact,
TestStepArtifactType
)
from testguide_report_generator.model.TestCaseFolder import TestCaseFolder
from testguide_report_generator.model.TestSuite import TestSuite
ARTIFACT_PATH = "tests/resources/artifact.txt"
ARTIFACT_PATH_2 = "tests/resources/artifact2.txt"
TESTCASE_JSON_PATH = "tests/resources/testcase.json"
TESTSUITE_JSON_PATH = "tests/resources/testsuite.json"
JSON_SCHEMA_PATH = "testguide_report_generator/schema/schema.json"
PATH_TO_VALID_JSON = "tests/resources/valid.json"
PATH_TO_INVALID_JSON = "tests/resources/invalid.json"
@pytest.fixture
def artifact_path():
return ARTIFACT_PATH
@pytest.fixture
def artifact_path2():
return ARTIFACT_PATH_2
@pytest.fixture
def testcase_json_path():
return TESTCASE_JSON_PATH
@pytest.fixture
def testsuite_json_path():
return TESTSUITE_JSON_PATH
@pytest.fixture
def json_schema_path():
return JSON_SCHEMA_PATH
@pytest.fixture
def path_to_valid_json():
return PATH_TO_VALID_JSON
@pytest.fixture
def path_to_invalid_json():
return PATH_TO_INVALID_JSON
@pytest.fixture()
def artifact():
return Artifact(ARTIFACT_PATH)
@pytest.fixture
@patch("testguide_report_generator.model.TestCase.get_md5_hash_from_file")
def artifact_mock_hash(mock_hash):
mock_hash.return_value = "hash"
return Artifact(ARTIFACT_PATH)
@pytest.fixture
@patch("testguide_report_generator.model.TestCase.get_md5_hash_from_file")
def teststep_artifact_mock_hash(mock_hash):
mock_hash.return_value = "hash"
return TestStepArtifact(ARTIFACT_PATH, TestStepArtifactType.IMAGE)
@pytest.fixture
def teststep():
return TestStep("ts", Verdict.NONE, "undefined")
@pytest.fixture
def teststep_2():
teststep_with_desc = TestStep("ts2", Verdict.ERROR, "err").set_description("teststep2")
return teststep_with_desc
@pytest.fixture
def teststep_folder_empty():
return TestStepFolder("tsf")
@pytest.fixture
def teststep_folder(teststep, teststep_2):
tsf = TestStepFolder("tsf")
tsf.add_teststep(teststep)
tsf.add_teststep(teststep_2)
return tsf
@pytest.fixture
def parameter():
return Parameter("param", 10, Direction.OUT)
@pytest.fixture
def parameter_2():
return Parameter("param2", 15, Direction.INOUT)
@pytest.fixture
def constant():
return Constant("const", "one")
@pytest.fixture
def constant_2():
return Constant("another", "const")
@pytest.fixture
def attribute():
return Attribute("an", "attribute")
@pytest.fixture
def review():
return Review("comment", "chucknorris", 1670254005)
@pytest.fixture
def testcase(
artifact_mock_hash,
teststep,
teststep_2,
teststep_folder,
parameter,
parameter_2,
constant,
constant_2,
attribute,
review,
):
testcase = TestCase("testcase_one", 1670248341000, Verdict.PASSED)
testcase.set_description("First testcase.")
testcase.set_execution_time_in_sec(5)
testcase.add_parameter_set("myset", [parameter, parameter_2])
testcase.add_constants([constant, constant_2])
testcase.add_constant(Constant("", ""))
testcase.add_constant_pair("const_key", "const_val")
testcase.add_attribute_pair("an", "attribute")
testcase.add_setup_teststep(teststep)
testcase.add_setup_teststep(teststep_folder)
testcase.add_teardown_teststep(teststep_folder)
testcase.add_teardown_teststep(teststep_2)
testcase.add_execution_teststep(teststep_2)
testcase.add_execution_teststep(teststep_folder)
testcase.add_artifact(ARTIFACT_PATH, ignore_on_error=False)
testcase.set_review(review)
with open("local.json", "w") as file:
file.write(json.dumps(testcase.create_json_repr()))
return testcase
@pytest.fixture
def testcase_folder_empty():
return TestCaseFolder("mytcf")
@pytest.fixture
def testcase_folder(testcase):
tcf = TestCaseFolder("mytcf2")
tcf.add_testcase(testcase)
return tcf
@pytest.fixture
def testsuite():
return TestSuite("MyTestSuite", 1666698047000)
@pytest.fixture
def testsuite_json_obj():
testsuite = TestSuite("MyTestSuite", 1666698047000)
testcase = TestCase("TestCase_1", 1666698047001, Verdict.PASSED)
testcase.add_parameter_set(
"MyParameterSet", [Parameter("Input", 7, Direction.IN), Parameter("Output", 42, Direction.OUT)]
)
testcase.add_constant_pair("SOP", "2042")
testcase.add_attribute_pair("ReqId", "007")
testcase.add_attribute_pair("Designer", "Philipp")
testcase.add_execution_teststep(TestStep("Check Picture1", Verdict.PASSED, "Shows traffic light"))
testcase.add_execution_teststep(
TestStepFolder("Action").add_teststep(TestStep("Check car speed", Verdict.PASSED, "ego >= 120"))
)
testcase.add_execution_teststep(TestStep("Check Picture2", Verdict.PASSED, "Shows Ego Vehicle"))
testcase.add_artifact("testguide_report_generator/schema/schema.json", False)
testcase.set_review(Review("Review-Comment", "Reviewer", 1423576765001))
# testcase no. 1: TestCase
testsuite.add_testcase(testcase)
testcase_folder = TestCaseFolder("SubFolder")
testcase_folder.add_testcase(TestCase("TestCase_FAILED", 1423536765000, Verdict.FAILED))
# testcase no. 2: TestCaseFolder
testsuite.add_testcase(testcase_folder)
return testsuite.create_json_repr()
@pytest.fixture(scope="session", autouse=True)
def value_storage():
return ValueStorage()
class ValueStorage:
def __init__(self) -> None:
self.e2e_atxid: str | None = None
self.remote_testcases_json = None
self.BASE_URL = os.getenv("TEST_GUIDE_URL")
self.AUTHKEY = os.getenv("TEST_GUIDE_AUTHKEY")
self.PROJECT_ID = os.getenv("TEST_GUIDE_PROJECT_ID")