Skip to content

Commit 00472ee

Browse files
authored
Merge pull request #44 from Artifizer/main
test: add new tests for wildcard validation
2 parents ad5de74 + 12d56c7 commit 00472ee

2 files changed

Lines changed: 192 additions & 0 deletions

File tree

tests/test_op1_id_validation.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,3 +409,80 @@ def test_start(self, param):
409409
.assert_equal("body.valid", True)
410410
),
411411
]
412+
413+
414+
class TestCaseOp1WildcardEdgeCasesInvalid(HttpRunner):
415+
"""OP#1 - Wildcard edge cases that should be rejected"""
416+
config = Config(
417+
"OP#1 - Wildcard edge cases (invalid)"
418+
).base_url(
419+
get_gts_base_url()
420+
)
421+
422+
@pytest.mark.parametrize(
423+
"param",
424+
Parameters(
425+
{
426+
"id": [
427+
# a) '*' not at end of pattern
428+
"gts.a.b.c.d.v1~a.*~",
429+
# b) '*' not at token boundary
430+
"gts.a.b.c.d.v1~a*",
431+
# d) '*' in the middle of a type segment
432+
"gts.a.b.c.*.v1~a.*",
433+
]
434+
}
435+
),
436+
)
437+
def test_start(self, param):
438+
super().test_start(param)
439+
440+
teststeps = [
441+
Step(
442+
RunRequest("validate wildcard invalid cases")
443+
.get("/validate-id")
444+
.with_params(**{"gts_id": "${id}"})
445+
.validate()
446+
.assert_equal("status_code", 200)
447+
.assert_equal("body.id", "${id}")
448+
.assert_equal("body.valid", False)
449+
.assert_equal("body.is_wildcard", True)
450+
.assert_not_equal("body.error", "")
451+
),
452+
]
453+
454+
455+
class TestCaseOp1WildcardEdgeCasesValid(HttpRunner):
456+
"""OP#1 - Wildcard edge cases that should be accepted"""
457+
config = Config(
458+
"OP#1 - Wildcard edge cases (valid)"
459+
).base_url(
460+
get_gts_base_url()
461+
)
462+
463+
@pytest.mark.parametrize(
464+
"param",
465+
Parameters(
466+
{
467+
"id": [
468+
# c) wildcard at token boundary at the end
469+
"gts.a.b.c.d.v1~a.*",
470+
]
471+
}
472+
),
473+
)
474+
def test_start(self, param):
475+
super().test_start(param)
476+
477+
teststeps = [
478+
Step(
479+
RunRequest("validate wildcard valid case")
480+
.get("/validate-id")
481+
.with_params(**{"gts_id": "${id}"})
482+
.validate()
483+
.assert_equal("status_code", 200)
484+
.assert_equal("body.id", "${id}")
485+
.assert_equal("body.valid", True)
486+
.assert_equal("body.is_wildcard", True)
487+
),
488+
]

tests/test_op3_id_parsing.py

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,118 @@ def test_start(self):
216216
.assert_equal("body.segments[0].namespace", "events")
217217
),
218218
]
219+
220+
221+
class TestCaseTestOp3Parsing_WildcardInvalid(HttpRunner):
222+
"""OP#3 - Wildcard parsing edge cases that should be rejected"""
223+
config = Config("OP#3 - Wildcard parsing (invalid)").base_url(
224+
get_gts_base_url()
225+
)
226+
227+
@pytest.mark.parametrize(
228+
"param",
229+
Parameters(
230+
{
231+
"id": [
232+
# a) '*' not at end of pattern
233+
"gts.a.b.c.d.v1~a.*~",
234+
# b) '*' not at token boundary
235+
"gts.a.b.c.d.v1~a*",
236+
# d) '*' in the middle of a type segment
237+
"gts.a.b.c.*.v1~a.*",
238+
]
239+
}
240+
),
241+
)
242+
def test_start(self, param):
243+
super().test_start(param)
244+
245+
teststeps = [
246+
Step(
247+
RunRequest("parse wildcard invalid cases")
248+
.get("/parse-id")
249+
.with_params(**{"gts_id": "${id}"})
250+
.validate()
251+
.assert_equal("status_code", 200)
252+
.assert_equal("body.id", "${id}")
253+
.assert_equal("body.ok", False)
254+
.assert_equal("body.is_wildcard", True)
255+
.assert_not_equal("body.error", "")
256+
),
257+
]
258+
259+
260+
class TestCaseTestOp3Parsing_WildcardValid(HttpRunner):
261+
"""OP#3 - Wildcard parsing edge cases that should be accepted"""
262+
config = Config("OP#3 - Wildcard parsing (valid)").base_url(
263+
get_gts_base_url()
264+
)
265+
266+
@pytest.mark.parametrize(
267+
"param",
268+
Parameters(
269+
{
270+
"id": [
271+
# c) wildcard at token boundary at the end
272+
"gts.a.b.c.d.v1~a.*",
273+
]
274+
}
275+
),
276+
)
277+
def test_start(self, param):
278+
super().test_start(param)
279+
280+
teststeps = [
281+
Step(
282+
RunRequest("parse wildcard valid case")
283+
.get("/parse-id")
284+
.with_params(**{"gts_id": "${id}"})
285+
.validate()
286+
.assert_equal("status_code", 200)
287+
.assert_equal("body.id", "${id}")
288+
.assert_equal("body.ok", True)
289+
.assert_equal("body.is_wildcard", True)
290+
),
291+
]
292+
293+
294+
class TestCaseTestOp3Parsing_IsSchemaField(HttpRunner):
295+
"""OP#3 - Verify is_schema field is returned correctly"""
296+
config = Config("OP#3 - is_schema field verification").base_url(
297+
get_gts_base_url()
298+
)
299+
300+
def test_start(self):
301+
super().test_start()
302+
303+
teststeps = [
304+
Step(
305+
RunRequest("parse type (is_schema=true)")
306+
.get("/parse-id")
307+
.with_params(**{"gts_id": "gts.x.pkg.ns.type.v1~"})
308+
.validate()
309+
.assert_equal("status_code", 200)
310+
.assert_equal("body.ok", True)
311+
.assert_equal("body.is_schema", True)
312+
.assert_equal("body.is_wildcard", False)
313+
),
314+
Step(
315+
RunRequest("parse instance (is_schema=false)")
316+
.get("/parse-id")
317+
.with_params(**{"gts_id": "gts.x.pkg.ns.type.v1~a.b.c.d.v1.0"})
318+
.validate()
319+
.assert_equal("status_code", 200)
320+
.assert_equal("body.ok", True)
321+
.assert_equal("body.is_schema", False)
322+
.assert_equal("body.is_wildcard", False)
323+
),
324+
Step(
325+
RunRequest("parse wildcard type (is_schema=true)")
326+
.get("/parse-id")
327+
.with_params(**{"gts_id": "gts.x.pkg.ns.*"})
328+
.validate()
329+
.assert_equal("status_code", 200)
330+
.assert_equal("body.ok", True)
331+
.assert_equal("body.is_wildcard", True)
332+
),
333+
]

0 commit comments

Comments
 (0)