This is a guide for adding the test target API path or functions that the user wants.
The CQA Test App uses the flask library and is easy to modify.
Please refer to the guide below when adding and modifying the code required for the test :)
A. How to Add Basic API
Add 'app.route' for adding basic API path in "runcqatest_app.py"
- As in the example below, Add 'app.route' annotation for adding API path
- format : @app.route({api_path}, methods=[{method name}]
- API Path cannot duplicate an existing path.
- As in the example below, Add 'app.route' annotation for adding API path
Add 'method' to the line below 'app.route' annotation.
- Add api method after adding 'app.route'
- A method name must not overlap with another method name.
- Add "apifunction.makecommon_response" to return to complete basic API addition.
- makecommonresponse is a method that returns a basic response.
- ex :
{"client":"127.0.0.1","code":200,"host":"localhost:10345","method":"GET","msg":"Test OK","path":"/example"}
- Add api method after adding 'app.route'
B. How to Add API with function
First, refer to the 'How to Add Basic API' guide to add the desired API path and method.
- Add 'app.route' and api method for adding basic API interface
- ref : How To Add Basic API
- Add 'app.route' and api method for adding basic API interface
Add API Function method to implement additional function
- Add your function method in "functions/APIFunctions.py"
- Implement codes in the method that your logics to running on CQA Test App
- example code is just run 'df' command & return result
- example code is just run 'df' command & return result
Add Code call API Function on added new api method
- Call "the function method" added in the api method like below.
- Then, when the api is called, the function works.
C. How to Add Swagger API spec
In order to connect the added API to swagger ui, it is necessary to add API Spec.
Add new API's spec on 'resources/swaggerapispec.json'
- Write API specs by referencing or copying other existing API spec formats.
- API path and method must be written according to the added API on code.
Check if new API Spec is well applied to Swagger UI on CQA Test App.
- After add new API spec, Run CQA Test App server.
- Access '/swagger' and Check new API spec is applied to UI
- In local, You can access swagger through 'http://localhost:10345/swagger'
- In local, You can access swagger through 'http://localhost:10345/swagger'
References
For more detailed information on API implementation and specification writing, refer to the documents below.
- Flask Document : https://flask.palletsprojects.com/en/2.3.x/#user-s-guide
- Swagger API Spec : https://swagger.io/specification/