Trax-air / swagger-tester

Automatically test your swagger API
MIT License
104 stars 36 forks source link

Response code is 411 — Length required #11

Closed Gray-Wind closed 8 years ago

Gray-Wind commented 8 years ago

My setup is Mac OS 10.11.2, Python 2.7.10, version of swagger-tester is 0.2.3

In [7]:  authorize_error = {
   ...:        'post': {
   ...:            '/pet/{petId}': [200],
   ...:            '/pet': [200]
   ...:        },
   ...:        'put': {
   ...:            '/user/{username}': [200],
   ...:            '/pet': [200]
   ...:        },
   ...:        'delete': {
   ...:            '/pet/{petId}': [200],
   ...:            '/store/order/{orderId}': [200],
   ...:            '/user/{username}': [200]
   ...:        }
   ...:    }

In [8]: swagger_test(app_url='http://petstore.swagger.io/v2', authorize_error=authorize_error)
INFO:swagger_tester.swagger_tester:TESTING POST /v2/pet/42/uploadImage?
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:TESTING POST /v2/user/createWithList?
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:TESTING POST /v2/pet/42?
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:Got authorize error on /v2/pet/42? with status 200
INFO:swagger_tester.swagger_tester:TESTING POST /v2/user?
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:TESTING POST /v2/store/order?
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:TESTING POST /v2/pet?
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:Got authorize error on /v2/pet? with status 200
INFO:swagger_tester.swagger_tester:TESTING POST /v2/user/createWithArray?
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:TESTING GET /v2/store/order/42?
INFO:swagger_tester.swagger_tester:Got status code: 411
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-8-83f0b6a14063> in <module>()
----> 1 swagger_test(app_url='http://petstore.swagger.io/v2', authorize_error=authorize_error)

/Library/Python/2.7/site-packages/swagger_tester/swagger_tester.pyc in swagger_test(swagger_yaml_path, app_url, authorize_error, wait_between_test, use_example)
    207                                 authorize_error=authorize_error,
    208                                 wait_between_test=wait_between_test,
--> 209                                 use_example=use_example):
    210         pass
    211

/Library/Python/2.7/site-packages/swagger_tester/swagger_tester.pyc in swagger_test_yield(swagger_yaml_path, app_url, authorize_error, wait_between_test, use_example)
    317                     response_json = response_text
    318
--> 319                 assert response.status_code < 400
    320
    321                 if 'default' not in response_spec.keys():

AssertionError:
flavianh commented 8 years ago

We can't replicate here, have you given us full info? Can you send us the output of pip freeze?

flavianh commented 8 years ago

@Gray-Wind ?

Gray-Wind commented 8 years ago

Sorry, wrong user pasted first time

$ pip freeze
altgraph==0.10.2
appnope==0.1.0
bdist-mpkg==0.5.0
bonjour-py==0.3
bravado==8.0.1
bravado-core==4.0.1
certifi==2015.11.20.1
characteristic==14.3.0
connexion==1.0.54
crochet==1.4.0
decorator==4.0.9
fido==2.1.2
Flask==0.10.1
functools32==3.2.3.post2
futures==3.0.4
gnureadline==6.3.3
ipython==4.1.1
ipython-genutils==0.1.0
itsdangerous==0.24
Jinja2==2.8
jsonschema==2.5.1
macholib==1.5.1
MarkupSafe==0.23
matplotlib==1.3.1
modulegraph==0.10.4
numpy==1.8.0rc1
path.py==8.1.2
pathlib==1.0.1
pexpect==4.0.1
pickleshare==0.6
ptyprocess==0.5.1
py2app==0.7.3
pyasn1==0.1.9
pyasn1-modules==0.0.8
pyobjc-core==2.5.1
pyobjc-framework-Accounts==2.5.1
pyobjc-framework-AddressBook==2.5.1
pyobjc-framework-AppleScriptKit==2.5.1
pyobjc-framework-AppleScriptObjC==2.5.1
pyobjc-framework-Automator==2.5.1
pyobjc-framework-CFNetwork==2.5.1
pyobjc-framework-Cocoa==2.5.1
pyobjc-framework-Collaboration==2.5.1
pyobjc-framework-CoreData==2.5.1
pyobjc-framework-CoreLocation==2.5.1
pyobjc-framework-CoreText==2.5.1
pyobjc-framework-DictionaryServices==2.5.1
pyobjc-framework-EventKit==2.5.1
pyobjc-framework-ExceptionHandling==2.5.1
pyobjc-framework-FSEvents==2.5.1
pyobjc-framework-InputMethodKit==2.5.1
pyobjc-framework-InstallerPlugins==2.5.1
pyobjc-framework-InstantMessage==2.5.1
pyobjc-framework-LatentSemanticMapping==2.5.1
pyobjc-framework-LaunchServices==2.5.1
pyobjc-framework-Message==2.5.1
pyobjc-framework-OpenDirectory==2.5.1
pyobjc-framework-PreferencePanes==2.5.1
pyobjc-framework-PubSub==2.5.1
pyobjc-framework-QTKit==2.5.1
pyobjc-framework-Quartz==2.5.1
pyobjc-framework-ScreenSaver==2.5.1
pyobjc-framework-ScriptingBridge==2.5.1
pyobjc-framework-SearchKit==2.5.1
pyobjc-framework-ServiceManagement==2.5.1
pyobjc-framework-Social==2.5.1
pyobjc-framework-SyncServices==2.5.1
pyobjc-framework-SystemConfiguration==2.5.1
pyobjc-framework-WebKit==2.5.1
pyOpenSSL==0.13.1
pyparsing==2.0.1
python-dateutil==1.5
pytz==2013.7
PyYAML==3.11
requests==2.9.1
scipy==0.13.0b1
service-identity==14.0.0
simplegeneric==0.8.1
simplejson==3.8.1
six==1.10.0
strict-rfc3339==0.6
swagger-client==1.0.0
swagger-parser==0.1.4
swagger-spec-validator==2.0.2
swagger-tester==0.2.3
traitlets==4.1.0
Twisted==15.4.0
urllib3==1.14
Werkzeug==0.11.3
xattr==0.6.4
yelp-bytes==0.2.0
yelp-encodings==0.1.3
yelp-uri==1.1.0
zope.interface==4.1.1
flavianh commented 8 years ago

Here's my attempt at replicating the issue:

$ pip freeze
bravado==8.0.1
bravado-core==4.0.1
cffi==1.5.2
characteristic==14.3.0
connexion==1.0.54
crochet==1.4.0
cryptography==1.2.2
decorator==4.0.9
enum34==1.1.2
fido==2.1.2
Flask==0.10.1
freeze==1.0.9
functools32==3.2.3.post2
futures==3.0.4
idna==2.0
ipaddress==1.0.16
ipython==4.1.1
ipython-genutils==0.1.0
itsdangerous==0.24
Jinja2==2.8
jsonschema==2.5.1
MarkupSafe==0.23
path.py==8.1.2
pathlib==1.0.1
pexpect==4.0.1
pickleshare==0.6
ptyprocess==0.5.1
pyasn1==0.1.9
pyasn1-modules==0.0.8
pycparser==2.14
pyOpenSSL==0.13.1
python-dateutil==1.5
PyYAML==3.11
requests==2.9.1
service-identity==14.0.0
simplegeneric==0.8.1
simplejson==3.8.1
six==1.10.0
strict-rfc3339==0.6
swagger-parser==0.1.4
swagger-spec-validator==2.0.2
swagger-tester==0.2.3
traitlets==4.1.0
Twisted==15.4.0
urllib3==1.14
Werkzeug==0.11.3
wheel==0.29.0
yelp-bytes==0.2.0
yelp-encodings==0.1.3
yelp-uri==1.1.0
zope.interface==4.1.1

Test file:

# coding: utf-8
authorize_error = {
      'post': {
          '/pet/{petId}': [200],
          '/pet': [200]
      },
      'put': {
          '/user/{username}': [200],
          '/pet': [200]
      },
      'delete': {
          '/pet/{petId}': [200],
          '/store/order/{orderId}': [200],
          '/user/{username}': [200]
      }
  }
from swagger_tester import swagger_test
swagger_test(app_url='http://petstore.swagger.io/v2', authorize_error=authorize_error)

Output when executing the file:

INFO:swagger_tester.swagger_tester:TESTING POST /v2/pet/42/uploadImage?
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:TESTING POST /v2/user/createWithList?
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:TESTING POST /v2/pet/42?
INFO:swagger_tester.swagger_tester:Got status code: 404
INFO:swagger_tester.swagger_tester:TESTING POST /v2/user?
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:TESTING POST /v2/store/order?
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:TESTING POST /v2/pet?
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:Got authorize error on /v2/pet? with status 200
INFO:swagger_tester.swagger_tester:TESTING POST /v2/user/createWithArray?
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:TESTING POST /v2/pet/42?
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:Got authorize error on /v2/pet/42? with status 200
INFO:swagger_tester.swagger_tester:TESTING GET /v2/store/order/42?
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:TESTING GET /v2/user/string?
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:TESTING GET /v2/pet/findByStatus?status=string%2Cstring2
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:TESTING GET /v2/user/logout?
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:TESTING GET /v2/store/inventory?
INFO:swagger_tester.swagger_tester:Got status code: 200
WARNING:swagger_tester.swagger_tester:Error in the swagger file
INFO:swagger_tester.swagger_tester:TESTING GET /v2/user/login?username=string&password=string
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:TESTING GET /v2/pet/42?
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:TESTING GET /v2/pet/findByTags?tags=string%2Cstring2
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:TESTING PUT /v2/user/string?
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:Got authorize error on /v2/user/string? with status 200
INFO:swagger_tester.swagger_tester:TESTING PUT /v2/pet?
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:Got authorize error on /v2/pet? with status 200
INFO:swagger_tester.swagger_tester:TESTING DELETE /v2/pet/42?
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:Got authorize error on /v2/pet/42? with status 200
INFO:swagger_tester.swagger_tester:TESTING DELETE /v2/store/order/42?
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:Got authorize error on /v2/store/order/42? with status 200
INFO:swagger_tester.swagger_tester:TESTING DELETE /v2/user/string?
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:Got authorize error on /v2/user/string? with status 200

I ran this on an Ubuntu 14.04 VM. I selected the relevant dependencies in the dependencies you indicated (since it seems some of them are libraries that you created) and tried several versions as well. I ran the test file several times to make sure this was not a random error. So now, I think there are two things left to check, so could you:

Thanks!

Gray-Wind commented 8 years ago

Copy-pasted to test.py Requirements copied to .txt file and installed with pip install -r requirements.txt But I deleted from list pyOpenSSL==0.13.1 because of

    OpenSSL/crypto/x509.h:17:10: fatal error: 'openssl/ssl.h' file not found
    #include <openssl/ssl.h>
             ^
    1 error generated.
    error: command 'cc' failed with exit status 1

And output from pip freeze and test are:

(venv) ~/test❯ python test.py
INFO:swagger_tester.swagger_tester:TESTING POST /v2/pet/42/uploadImage?
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:TESTING POST /v2/user/createWithList?
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:TESTING POST /v2/pet/42?
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:Got authorize error on /v2/pet/42? with status 200
INFO:swagger_tester.swagger_tester:TESTING POST /v2/user?
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:TESTING POST /v2/store/order?
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:TESTING POST /v2/pet?
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:Got authorize error on /v2/pet? with status 200
INFO:swagger_tester.swagger_tester:TESTING POST /v2/user/createWithArray?
INFO:swagger_tester.swagger_tester:Got status code: 200
INFO:swagger_tester.swagger_tester:TESTING GET /v2/store/order/42?
INFO:swagger_tester.swagger_tester:Got status code: 411
Traceback (most recent call last):
  File "test.py", line 18, in <module>
    swagger_test(app_url='http://petstore.swagger.io/v2', authorize_error=authorize_error)
  File "/Users/test/test/venv/lib/python2.7/site-packages/swagger_tester/swagger_tester.py", line 209, in swagger_test
    use_example=use_example):
  File "/Users/test/test/venv/lib/python2.7/site-packages/swagger_tester/swagger_tester.py", line 319, in swagger_test_yield
    assert response.status_code < 400
AssertionError

(venv) ~/test❯ pip freeze
appnope==0.1.0
bravado==8.0.1
bravado-core==4.0.1
cffi==1.5.2
characteristic==14.3.0
connexion==1.0.54
crochet==1.4.0
cryptography==1.2.2
decorator==4.0.9
enum34==1.1.2
fido==2.1.2
Flask==0.10.1
freeze==1.0.9
functools32==3.2.3.post2
futures==3.0.4
gnureadline==6.3.3
idna==2.0
ipaddress==1.0.16
ipython==4.1.1
ipython-genutils==0.1.0
itsdangerous==0.24
Jinja2==2.8
jsonschema==2.5.1
MarkupSafe==0.23
path.py==8.1.2
pathlib==1.0.1
pexpect==4.0.1
pickleshare==0.6
ptyprocess==0.5.1
pyasn1==0.1.9
pyasn1-modules==0.0.8
pycparser==2.14
pyOpenSSL==0.15.1
python-dateutil==1.5
PyYAML==3.11
requests==2.9.1
service-identity==14.0.0
simplegeneric==0.8.1
simplejson==3.8.1
six==1.10.0
strict-rfc3339==0.6
swagger-parser==0.1.4
swagger-spec-validator==2.0.2
swagger-tester==0.2.3
traitlets==4.1.0
Twisted==15.4.0
urllib3==1.14
Werkzeug==0.11.3
wheel==0.29.0
yelp-bytes==0.2.0
yelp-encodings==0.1.3
yelp-uri==1.1.0
zope.interface==4.1.1
flavianh commented 8 years ago

As for your cc error you could try the following workaround (from https://github.com/python-pillow/Pillow/issues/527):

export CFLAGS=-Qunused-arguments
export CPPFLAGS=-Qunused-arguments

Must be a mac specific error then, possibly linked to the use of connection. Could you please try the following:

logging.basicConfig()
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)

Please post the output of your experiments, I hope this gives us sufficient insight

flavianh commented 8 years ago

@Gray-Wind Any issue with the above suggestion? Do you need me to do anything?

flavianh commented 8 years ago

So, if I can't reproduce this, I will close it soon

Gray-Wind commented 8 years ago

Sorry for the delay with response, but I cannot try to reproduce it now. I'll be able to do this on Thursday. Sorry again.

flavianh commented 8 years ago

Cool! Looking forward to knowing what you'll find out! Le 23 févr. 2016 09:53, "Ilia" notifications@github.com a écrit :

Sorry for the delay with response, but I cannot try to reproduce it now. I'll be able to do this on Thursday. Sorry again.

— Reply to this email directly or view it on GitHub https://github.com/Trax-air/swagger-tester/issues/11#issuecomment-187605598 .

Gray-Wind commented 8 years ago

It was squid problem in our old office network. We moved to another one this week and the issue became resolved. Sorry for inconvenience.

flavianh commented 8 years ago

Seemed like a network error yes :). Glad you worked that out, have fun with the lib