-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Testing invalid inputs #88
Comments
My proposal is to patch the pyswagger.io.Request before passing it to client.request via inspecting _p property and patch it by yourself. For example, in your case, it could be done like this: from pyswagger import App
from pyswagger.contrib.client.requests import Client
app = App._create_('http://petstore.swagger.io/v2/swagger.json')
client = Client()
pet_tom = dict(
id=123,
name='Tom',
photoUrls='https://github.com/',
status='available')
req, resp = app.op['addPet'](body=pet_tom)
# patching the "body" parameter named "body", ... which seems cumbersome
req._p['body']['body']['id'] = 'not_valid'
resp = client.request((req, resp,))
print resp.status # the code I tried is 500, not 405 Note: this property is used internally for testing or debugging when developing this library, and might be changed with the latest version of Swagger (Open API) (ex. 'form' becomes 'formData' after upgrading from swagger 1.2 to 2.0) |
Thank you from the information. Definitely will try it out tomorrow and look more closely on the |
I did found a way, by doing this, I can overwrite the http method from post to get:
By this it should be easy task to look over the http methods which are not supported by the API and verify that correct status code is received. Also your example gives a clean solution how to manipulate the My application is using swagger 2.0 and next I will start plying with that. But debugger should be able to guide me to the right direction. Thank you from the help. But because this might be useful to someone else too, should this be placed in the wiki pages, or somewhere other documentation? |
Did you mean the part to manipulate _p, and anything else? I think it's a good idea to document those stuffs. (Please correct me if you didn't mean that part). I'll create some md files in tutorial part later. |
Yes, that |
- #88 - also update some document
- pyopenapi/pyswagger#88 - also update some document
Is it possible to test with invalid inputs? I have two requirements
For the first one when the specification says that
id
must be integer, I would like to input a string and verify that proper error code is retruned. For the second one intead of using the http post for theaddPet
, I would like to use http get or delete. Is this something possible and if yes, how I can do it?Example when I try to do this:
I get error from
pyswagger
side:The text was updated successfully, but these errors were encountered: