@@ -7,10 +7,6 @@ def test_property_of(app):
77 obj = type ("obj" , (object ,), {"property_name" : "propertyValue" })
88
99 GeneratedClass = builder .property_of (obj , "property_name" )
10-
11- assert callable (GeneratedClass .get )
12- assert callable (GeneratedClass .post )
13-
1410 app .add_url_rule ("/" , view_func = GeneratedClass .as_view ("index" ))
1511
1612 with app .test_client () as c :
@@ -32,11 +28,6 @@ def test_property_of_dict(app):
3228 )
3329
3430 GeneratedClass = builder .property_of (obj , "properties" )
35-
36- assert callable (GeneratedClass .get )
37- assert callable (GeneratedClass .post )
38- assert callable (GeneratedClass .put )
39-
4031 app .add_url_rule ("/" , view_func = GeneratedClass .as_view ("index" ))
4132
4233 with app .test_client () as c :
@@ -65,10 +56,64 @@ def test_property_of_readonly():
6556
6657def test_property_of_name_description ():
6758 obj = type ("obj" , (object ,), {"property_name" : "propertyValue" })
68-
6959 GeneratedClass = builder .property_of (
7060 obj , "property_name" , name = "property_name" , description = "property description"
7161 )
7262
7363 assert GeneratedClass .__apispec__ .get ("description" ) == "property description"
7464 assert GeneratedClass .__apispec__ .get ("summary" ) == "property description"
65+
66+
67+ def test_action_from (app ):
68+ def f (arg : int , kwarg : str = "default" ):
69+ return {"arg" : arg , "kwarg" : kwarg }
70+
71+ GeneratedClass = builder .action_from (f )
72+ app .add_url_rule ("/" , view_func = GeneratedClass .as_view ("index" ))
73+
74+ with app .test_client () as c :
75+ assert c .post ("/" , json = {"arg" : 5 }).data == b'{"arg":5,"kwarg":"default"}\n '
76+
77+
78+ def test_action_from_task (app ):
79+ def f (arg : int , kwarg : str = "default" ):
80+ return {"arg" : arg , "kwarg" : kwarg }
81+
82+ GeneratedClass = builder .action_from (f , task = True ,)
83+ app .add_url_rule ("/" , view_func = GeneratedClass .as_view ("index" ))
84+
85+ with app .test_client () as c :
86+ response = c .post ("/" , json = {"arg" : 5 }).json
87+ # Check we get back a Task representation
88+ assert isinstance (response , dict )
89+ assert isinstance (response .get ("id" ), str )
90+ assert isinstance (response .get ("function" ), str )
91+
92+
93+ def test_action_from_options (app ):
94+ def f (arg : int , kwarg : str = "default" ):
95+ return {"arg" : arg , "kwarg" : kwarg }
96+
97+ assert builder .action_from (
98+ f ,
99+ name = "action_name" ,
100+ description = "action_description" ,
101+ safe = True ,
102+ idempotent = True ,
103+ )
104+
105+
106+ def test_static_from (app , app_ctx , static_path ):
107+
108+ GeneratedClass = builder .static_from (static_path ,)
109+ app .add_url_rule ("/static" , view_func = GeneratedClass .as_view ("index" ))
110+
111+ with app_ctx .test_request_context ():
112+ assert GeneratedClass ().get ("text" ).status_code == 200
113+
114+ with app .test_client () as c :
115+ assert c .get ("/static/text" ).data == b"text"
116+
117+
118+ def test_static_from_options (app , app_ctx , static_path ):
119+ assert builder .static_from (static_path , name = "static_name" )
0 commit comments