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

'application/json; charset=utf-8' is rejected as an invalid header #3

Open
alexwlchan opened this issue Apr 13, 2018 · 2 comments
Open

Comments

@alexwlchan
Copy link

alexwlchan commented Apr 13, 2018

If I do a local patch for #2, and run the tool again, I get a complaint about Content-Type headers:

$ python -m swaggerconformance 'https://api.wellcomecollection.org/catalogue/v1/swagger.json'
AssertionError: application/json not in ['application/json; charset=utf-8']

I’ve included the traceback below. Also, this error message should explain what the significance of the quoted header is, rather than having me poke around in the traceback to discover it‘s the Content-Type header.

Same versions as in #2.

Complete traceback
Validation failed of operation: Operation(id=None, method='get', path='/works', params={'page': Parameter(name='page', type='integer', format='int32', required=False), 'pageSize': Parameter(name='pageSize', type='integer', format='int32', required=False), 'query': Parameter(name='query', type='string', format=None, required=False), 'includes': Parameter(name='includes', type='array', format=None, required=False)})
Traceback (most recent call last):
  File "/Users/chana/repos/swagger-conformance/swaggerconformance/_basictests.py", line 34, in api_conformance_test
    operation_conformance_test(client, operation, num_tests_per_op)
  File "/Users/chana/repos/swagger-conformance/swaggerconformance/_basictests.py", line 86, in operation_conformance_test
    single_operation_test(client, operation) # pylint: disable=E1120
  File "/Users/chana/repos/swagger-conformance/swaggerconformance/_basictests.py", line 62, in single_operation_test
    max_examples=num_tests,
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/hypothesis/core.py", line 1054, in wrapped_test
    state.run()
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/hypothesis/core.py", line 822, in run
    falsifying_example.__expected_traceback,
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/hypothesis/core.py", line 583, in execute
    result = self.test_runner(data, run)
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/hypothesis/executors.py", line 58, in default_new_style_executor
    return function(data)
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/hypothesis/core.py", line 575, in run
    return test(*args, **kwargs)
  File "/Users/chana/repos/swagger-conformance/swaggerconformance/_basictests.py", line 62, in single_operation_test
    max_examples=num_tests,
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/hypothesis/core.py", line 522, in test
    result = self.test(*args, **kwargs)
  File "/Users/chana/repos/swagger-conformance/swaggerconformance/_basictests.py", line 76, in single_operation_test
    result = client.request(operation, params)
  File "/Users/chana/repos/swagger-conformance/swaggerconformance/client.py", line 70, in request
    result = client.request(operation._pyswagger_operation(**parameters))  # pylint: disable=protected-access
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/pyswagger/contrib/client/requests.py", line 74, in request
    raw=six.BytesIO(rs.content).getvalue()
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/pyswagger/io.py", line 417, in apply_with
    self.__data = r.schema._prim_(data, self.__op._prim_factory, ctx=dict(read=True))
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/pyswagger/spec/v2_0/objects.py", line 92, in _prim_
    return prim_factory.produce(self, v, ctx)
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/pyswagger/primitives/__init__.py", line 192, in produce
    val = _2nd(obj, ret, val, ctx)
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/pyswagger/primitives/comm.py", line 40, in _2nd_pass_obj
    return ret.apply_with(obj, val, ctx)
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/pyswagger/primitives/_model.py", line 29, in apply_with
    self[k] = ctx['factory'].produce(pobj, v)
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/pyswagger/primitives/__init__.py", line 192, in produce
    val = _2nd(obj, ret, val, ctx)
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/pyswagger/primitives/comm.py", line 40, in _2nd_pass_obj
    return ret.apply_with(obj, val, ctx)
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/pyswagger/primitives/_array.py", line 48, in apply_with
    self.extend(map(functools.partial(ctx['factory'].produce, obj.items), val))
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/pyswagger/primitives/__init__.py", line 192, in produce
    val = _2nd(obj, ret, val, ctx)
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/pyswagger/primitives/comm.py", line 40, in _2nd_pass_obj
    return ret.apply_with(obj, val, ctx)
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/pyswagger/primitives/_model.py", line 29, in apply_with
    self[k] = ctx['factory'].produce(pobj, v)
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/pyswagger/primitives/__init__.py", line 192, in produce
    val = _2nd(obj, ret, val, ctx)
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/pyswagger/primitives/comm.py", line 40, in _2nd_pass_obj
    return ret.apply_with(obj, val, ctx)
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/pyswagger/primitives/_model.py", line 23, in apply_with
    for k, v in six.iteritems(val):
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/six.py", line 587, in iteritems
    return iter(d.items(**kw))
AttributeError: 'list' object has no attribute 'items'
Validation failed of operation: Operation(id=None, method='get', path='/works/{id}', params={'id': Parameter(name='id', type='string', format=None, required=True), 'includes': Parameter(name='includes', type='array', format=None, required=False)})
Traceback (most recent call last):
  File "/Users/chana/repos/swagger-conformance/swaggerconformance/_basictests.py", line 34, in api_conformance_test
    operation_conformance_test(client, operation, num_tests_per_op)
  File "/Users/chana/repos/swagger-conformance/swaggerconformance/_basictests.py", line 86, in operation_conformance_test
    single_operation_test(client, operation) # pylint: disable=E1120
  File "/Users/chana/repos/swagger-conformance/swaggerconformance/_basictests.py", line 62, in single_operation_test
    max_examples=num_tests,
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/hypothesis/core.py", line 1054, in wrapped_test
    state.run()
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/hypothesis/core.py", line 822, in run
    falsifying_example.__expected_traceback,
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/hypothesis/core.py", line 583, in execute
    result = self.test_runner(data, run)
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/hypothesis/executors.py", line 58, in default_new_style_executor
    return function(data)
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/hypothesis/core.py", line 575, in run
    return test(*args, **kwargs)
  File "/Users/chana/repos/swagger-conformance/swaggerconformance/_basictests.py", line 62, in single_operation_test
    max_examples=num_tests,
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/hypothesis/core.py", line 522, in test
    result = self.test(*args, **kwargs)
  File "/Users/chana/repos/swagger-conformance/swaggerconformance/_basictests.py", line 82, in single_operation_test
    "application/json not in {}".format(result.headers['Content-Type'])
AssertionError: application/json not in ['application/json; charset=utf-8']
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/chana/repos/swagger-conformance/swaggerconformance/__main__.py", line 38, in <module>
    main()
  File "/Users/chana/repos/swagger-conformance/swaggerconformance/__main__.py", line 32, in main
    _run_comformance_test(parsed_args)
  File "/Users/chana/repos/swagger-conformance/swaggerconformance/__main__.py", line 27, in _run_comformance_test
    num_tests_per_op=parsed_args.num_tests_per_op)
  File "/Users/chana/repos/swagger-conformance/swaggerconformance/_basictests.py", line 45, in api_conformance_test
    '\n'.join(hit_errors)))
Exception: 2 operation(s) failed conformance tests - check output in logging and tracebacks below for details
Traceback (most recent call last):
  File "/Users/chana/repos/swagger-conformance/swaggerconformance/_basictests.py", line 34, in api_conformance_test
    operation_conformance_test(client, operation, num_tests_per_op)
  File "/Users/chana/repos/swagger-conformance/swaggerconformance/_basictests.py", line 86, in operation_conformance_test
    single_operation_test(client, operation) # pylint: disable=E1120
  File "/Users/chana/repos/swagger-conformance/swaggerconformance/_basictests.py", line 62, in single_operation_test
    max_examples=num_tests,
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/hypothesis/core.py", line 1054, in wrapped_test
    state.run()
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/hypothesis/core.py", line 822, in run
    falsifying_example.__expected_traceback,
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/hypothesis/core.py", line 583, in execute
    result = self.test_runner(data, run)
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/hypothesis/executors.py", line 58, in default_new_style_executor
    return function(data)
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/hypothesis/core.py", line 575, in run
    return test(*args, **kwargs)
  File "/Users/chana/repos/swagger-conformance/swaggerconformance/_basictests.py", line 62, in single_operation_test
    max_examples=num_tests,
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/hypothesis/core.py", line 522, in test
    result = self.test(*args, **kwargs)
  File "/Users/chana/repos/swagger-conformance/swaggerconformance/_basictests.py", line 76, in single_operation_test
    result = client.request(operation, params)
  File "/Users/chana/repos/swagger-conformance/swaggerconformance/client.py", line 70, in request
    result = client.request(operation._pyswagger_operation(**parameters))  # pylint: disable=protected-access
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/pyswagger/contrib/client/requests.py", line 74, in request
    raw=six.BytesIO(rs.content).getvalue()
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/pyswagger/io.py", line 417, in apply_with
    self.__data = r.schema._prim_(data, self.__op._prim_factory, ctx=dict(read=True))
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/pyswagger/spec/v2_0/objects.py", line 92, in _prim_
    return prim_factory.produce(self, v, ctx)
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/pyswagger/primitives/__init__.py", line 192, in produce
    val = _2nd(obj, ret, val, ctx)
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/pyswagger/primitives/comm.py", line 40, in _2nd_pass_obj
    return ret.apply_with(obj, val, ctx)
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/pyswagger/primitives/_model.py", line 29, in apply_with
    self[k] = ctx['factory'].produce(pobj, v)
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/pyswagger/primitives/__init__.py", line 192, in produce
    val = _2nd(obj, ret, val, ctx)
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/pyswagger/primitives/comm.py", line 40, in _2nd_pass_obj
    return ret.apply_with(obj, val, ctx)
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/pyswagger/primitives/_array.py", line 48, in apply_with
    self.extend(map(functools.partial(ctx['factory'].produce, obj.items), val))
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/pyswagger/primitives/__init__.py", line 192, in produce
    val = _2nd(obj, ret, val, ctx)
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/pyswagger/primitives/comm.py", line 40, in _2nd_pass_obj
    return ret.apply_with(obj, val, ctx)
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/pyswagger/primitives/_model.py", line 29, in apply_with
    self[k] = ctx['factory'].produce(pobj, v)
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/pyswagger/primitives/__init__.py", line 192, in produce
    val = _2nd(obj, ret, val, ctx)
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/pyswagger/primitives/comm.py", line 40, in _2nd_pass_obj
    return ret.apply_with(obj, val, ctx)
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/pyswagger/primitives/_model.py", line 23, in apply_with
    for k, v in six.iteritems(val):
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/six.py", line 587, in iteritems
    return iter(d.items(**kw))
AttributeError: 'list' object has no attribute 'items'

Traceback (most recent call last):
  File "/Users/chana/repos/swagger-conformance/swaggerconformance/_basictests.py", line 34, in api_conformance_test
    operation_conformance_test(client, operation, num_tests_per_op)
  File "/Users/chana/repos/swagger-conformance/swaggerconformance/_basictests.py", line 86, in operation_conformance_test
    single_operation_test(client, operation) # pylint: disable=E1120
  File "/Users/chana/repos/swagger-conformance/swaggerconformance/_basictests.py", line 62, in single_operation_test
    max_examples=num_tests,
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/hypothesis/core.py", line 1054, in wrapped_test
    state.run()
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/hypothesis/core.py", line 822, in run
    falsifying_example.__expected_traceback,
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/hypothesis/core.py", line 583, in execute
    result = self.test_runner(data, run)
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/hypothesis/executors.py", line 58, in default_new_style_executor
    return function(data)
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/hypothesis/core.py", line 575, in run
    return test(*args, **kwargs)
  File "/Users/chana/repos/swagger-conformance/swaggerconformance/_basictests.py", line 62, in single_operation_test
    max_examples=num_tests,
  File "/Users/chana/.virtualenvs/swcon/lib/python3.6/site-packages/hypothesis/core.py", line 522, in test
    result = self.test(*args, **kwargs)
  File "/Users/chana/repos/swagger-conformance/swaggerconformance/_basictests.py", line 82, in single_operation_test
    "application/json not in {}".format(result.headers['Content-Type'])
AssertionError: application/json not in ['application/json; charset=utf-8']

Falsifying example: single_operation_test(client=Client(schema_path='https://api.wellcomecollection.org/catalogue/v1/swagger.json'), operation=Operation(id=None, method='get', path='/works', params={'page': Parameter(name='page', type='integer', format='int32', required=False), 'pageSize': Parameter(name='pageSize', type='integer', format='int32', required=False), 'query': Parameter(name='query', type='string', format=None, required=False), 'includes': Parameter(name='includes', type='array', format=None, required=False)}), params={})
Falsifying example: single_operation_test(client=Client(schema_path='https://api.wellcomecollection.org/catalogue/v1/swagger.json'), operation=Operation(id=None, method='get', path='/works/{id}', params={'id': Parameter(name='id', type='string', format=None, required=True), 'includes': Parameter(name='includes', type='array', format=None, required=False)}), params={'id': '0'})
@olipratt
Copy link
Owner

Thanks for raising Alex.

My lack of any real interop testing showing through.

It seems that from here the syntax for the header is:

Content-Type := type "/" subtype *[";" parameter] 

So I'll change the check to a startswith instead, clarify the assertion output, and update the tests.

@Zac-HD
Copy link

Zac-HD commented Sep 29, 2018

Closed by #5?

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

3 participants