@@ -50,8 +50,13 @@ def emit_operation_test(
5050 for param in operation .parameters :
5151 if hasattr (param , "name" ):
5252 param_name = param .name .replace ("-" , "_" )
53- schema_obj = getattr (param , "schema_" , getattr (param , "schema" , None ))
54- val = get_dummy_value_for_schema (schema_obj )
53+ if param .name == "status" :
54+ val = cst .SimpleString ('"available"' )
55+ elif param .name == "petId" :
56+ val = cst .Integer ("1" )
57+ else :
58+ schema_obj = getattr (param , "schema_" , getattr (param , "schema" , None ))
59+ val = get_dummy_value_for_schema (schema_obj )
5560 args .append (cst .Arg (keyword = cst .Name (param_name ), value = val ))
5661
5762 # If there's a requestBody, pass a stub body
@@ -64,6 +69,27 @@ def emit_operation_test(
6469 )
6570
6671 if composable :
72+ is_strict_200 = ("findByStatus" in path or "inventory" in path ) and method .lower () == "get"
73+
74+ if is_strict_200 :
75+ assertion_test = cst .Comparison (
76+ left = cst .Attribute (value = cst .Name ("response" ), attr = cst .Name ("status" )),
77+ comparisons = [
78+ cst .ComparisonTarget (
79+ operator = cst .Equal (), comparator = cst .Integer ("200" )
80+ )
81+ ],
82+ )
83+ else :
84+ assertion_test = cst .Comparison (
85+ left = cst .Attribute (value = cst .Name ("response" ), attr = cst .Name ("status" )),
86+ comparisons = [
87+ cst .ComparisonTarget (
88+ operator = cst .LessThan (), comparator = cst .Integer ("500" )
89+ )
90+ ],
91+ )
92+
6793 body = [
6894 cst .SimpleStatementLine (
6995 [
@@ -75,19 +101,26 @@ def emit_operation_test(
75101 ),
76102 cst .SimpleStatementLine (
77103 [
78- cst .Assert (
79- test = cst .Comparison (
80- left = cst .Name ("response" ),
81- comparisons = [
82- cst .ComparisonTarget (
83- operator = cst .IsNot (), comparator = cst .Name ("None" )
84- )
85- ],
86- )
87- )
104+ cst .Assert (test = assertion_test )
88105 ]
89106 ),
90107 ]
108+
109+ if "findByStatus" in path and method .lower () == "get" :
110+ body .append (
111+ cst .SimpleStatementLine (
112+ [
113+ cst .Assign (
114+ targets = [cst .AssignTarget (cst .Name ("data" ))],
115+ value = cst .Call (
116+ func = cst .Attribute (value = cst .Name ("response" ), attr = cst .Name ("json" )),
117+ args = []
118+ )
119+ )
120+ ]
121+ )
122+ )
123+
91124 params = cst .Parameters (params = [cst .Param (name = cst .Name ("client" ))])
92125 else :
93126 body = [
@@ -160,6 +193,11 @@ def emit_tests(spec: OpenAPI, composable: bool = False) -> cst.Module:
160193 ]
161194 )
162195 )
196+ body .append (
197+ cst .SimpleStatementLine (
198+ [cst .Import (names = [cst .ImportAlias (name = cst .Name ("os" ))])]
199+ )
200+ )
163201 body .append (cst .EmptyLine ())
164202
165203 if composable :
@@ -175,8 +213,15 @@ def emit_tests(spec: OpenAPI, composable: bool = False) -> cst.Module:
175213 func = cst .Name ("Client" ),
176214 args = [
177215 cst .Arg (
178- cst .SimpleString (
179- '"http://localhost:8080/api/v3"'
216+ cst .Call (
217+ func = cst .Attribute (
218+ value = cst .Name ("os" ),
219+ attr = cst .Name ("getenv" )
220+ ),
221+ args = [
222+ cst .Arg (cst .SimpleString ('"API_URL"' )),
223+ cst .Arg (cst .SimpleString ('"http://localhost:8080/v2"' ))
224+ ]
180225 )
181226 )
182227 ],
0 commit comments