Skip to content

YoooFeng/api_manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Autotest

Input a swagger spec, autotest all APIs in the spec and validate responses.

How to use

###1.Prerequisites ### Python2.7

###2.Install Related Package ### $ pip intall codecs $ pip intall datetime $ pip intall jinja2 $ pip intall json $ pip intall re $ pip intall six $ pip intall yaml $ pip intall logging $ pip intall logging.handlers $ pip intall requests $ pip intall six $ pip intall time $ pip intall tablib

###3.Editor Parameter Configure File ### Autotest provides two ways to get parameters.

(1) For simple Web APIs, just call the method get_example_from_prop_spec(self, prop_spec, param_name) in param_generator.py, it will return simple parameter according to the type of param.

(2) For some complex Web APIs, we must send valid params to the server side so that we could get valid resonse. Editor param_generator.py before testing.
Uber Example:
def uber_example(): return { 'latitude': 38.76623, 'longitude': 116.43213, 'start_latitude': 38.76623, 'start_longitude': 116.43213, 'end_latitude': 39.917023, 'end_longitude': 116.396813, 'access_token': 'CjCEg6plCW4SH1X3bVHjQKFpNtBeAD9TTcSVMg2k' }

###4.Define Response ###

  We define three responses in my_tester.py:youku, uber, instagram.

def validate_youku_definition(swagger_parser, valid_response, response)
def validate_uber_definition(swagger_parser, valid_response, response)
def validate_ins_definition(swagger_parser, valid_response, response)

If you want to test your own Web APIs, define your response in my_tester.py before testing.

###5.Execute testing###

Autotest is easy to use, just execute the method swagger_test() in my_tester.py.

def swagger_test(swagger_yaml_path=None, app_url=None, authorize_error=None,wait_between_test=False, use_example=True)
  • swagger_yaml_path: Your swagger file path in local.
  • app_url : If you have a running Web APIs, you can test it like app_url = 'https://apis-guru.github.io/api-models/instagram.com/1.0.0'
  • authorize_error: user-defined error, tester will ignore those errors.
  • wait_between_test: Just preventing to be identified as a attacker by the server side.
  • use_example: use user-defined params or not.

Example Usage: swagger_test(swagger_yaml_path='./input/swagger-ins.json',authorize_error=authorize_error)

About

A tool used to manage APIs.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages