Skip to content
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

Question about testing API's with https #103

Closed
chartjes opened this issue Jan 5, 2017 · 6 comments
Closed

Question about testing API's with https #103

chartjes opened this issue Jan 5, 2017 · 6 comments
Milestone

Comments

@chartjes
Copy link

chartjes commented Jan 5, 2017

My apologies if this is the wrong place to ask.

I'm trying to test a site with endpoints that are behind https. I saw that you can override url_netloc but I don't see how you tell pyswagger to use https

@mission-liao
Copy link
Member

@chartjes I would like to clarify the problem you describe:

  • you are testing a external site
  • the Swagger (OpenAPI) document provided by that site has both scheme defined:
schemes: ["http", "https"]
  • you wants to test that site via "https"
    In this case, pyswagger would select the first items in that array (which is "http") and doesn't provide a way to pick another one, however, it can be refined to add a way to for users to provide preference.

If it's not what you want, could you describe your problem more precisely?

@chartjes
Copy link
Author

chartjes commented Jan 5, 2017

Thanks for the quick response.

Yes, you are describing what I want to do. So am I correct in thinking if I only put https in the schemes section that will work?

@mission-liao
Copy link
Member

Yes, that should work. My personal usage is local testing a development server in http, not https. If there is any problem when using https, please feel free to report it.

And I would add a way to provide a preference on schemes, which would be included in next release.

@mission-liao mission-liao added this to the v0.8.25 milestone Jan 5, 2017
@chartjes
Copy link
Author

chartjes commented Jan 5, 2017

I still feel like I am misunderstanding something. So here is my swagger file:

https://gist.github.com/chartjes/ffb6c9b34f242707f8acd819a7cb8950

And here is my code example taken from the docs:

from pyswagger import App
from pyswagger.contrib.client.requests import Client

# load Swagger resource file into SwaggerApp object
app = App.create('./swagger.json')
client = Client()
op = app.op['__heartbeat__']
opt = {'url_netloc': 'kinto.stage.mozaws.net'}
response = client.request(op, opt=opt)

I do have the requests library already installed
When I run that code I get an error:

(venv27) ~/m/s/kinto (master) $ python pyswagger-qs-01.py 
Traceback (most recent call last):
  File "pyswagger-qs-01.py", line 10, in <module>
    response = client.request(op, opt=opt)
  File "/Users/chartjes/mozilla-services/services-test/kinto/venv27/lib/python2.7/site-packages/pyswagger/contrib/client/requests.py", line 32, in request
    req, resp = super(Client, self).request(req_and_resp, opt)
  File "/Users/chartjes/mozilla-services/services-test/kinto/venv27/lib/python2.7/site-packages/pyswagger/core.py", line 577, in request
    req, resp = req_and_resp
TypeError: 'Operation' object is not iterable

@mission-liao
Copy link
Member

The Operation object is a 'callable' object in python, the parameter used to call it is exactly the parameter you described in Swagger Document. refer to here for a mapping from Swagger Parameter to the python primitives.

In your case, it should work when use it in this way:

response = client.request(op(), opt=opt)

@chartjes
Copy link
Author

chartjes commented Jan 5, 2017

That did the trick. I'll close this and thank you for your help. FYI us QA folk at Mozilla are starting to use Swagger/OpenAPI as part of the overall testing process and pyswagger is a tool I'm hoping to use a lot.

@chartjes chartjes closed this as completed Jan 5, 2017
mission-liao added a commit that referenced this issue Jan 9, 2017
- #103
- #92
- #100 support python
3.6
- #92
mission-liao added a commit to pyopenapi/pyopenapi that referenced this issue Aug 12, 2017
mission-liao added a commit to pyopenapi/pyopenapi that referenced this issue Aug 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants