Guest User

Untitled

a guest
Sep 14th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #
  2. # run me with nosetests -vs test_oas.py
  3. #
  4. import sys
  5. from glob import glob
  6.  
  7. import connexion
  8. import werkzeug.exceptions
  9. from connexion.resolver import Resolver
  10.  
  11. me = sys.modules[__name__]
  12.  
  13.  
  14. def noop(*args, **kwds): raise NotImplementedError
  15.  
  16.  
  17. class FakeResolver(Resolver):
  18.  
  19. def resolve_operation_id(self, operation):
  20. """
  21. Mock operation id, just to validate API.
  22. :type operation: connexion.operations.AbstractOperation
  23. """
  24. oid = operation.operation_id
  25. if "." in oid:
  26. oid = oid.split(".")[-1]
  27. # Append the operation function to this module.
  28. setattr(me, oid, noop)
  29. return "test_oas." + oid
  30.  
  31.  
  32. def test_oas3():
  33. files = (
  34. "/home/rob/workspace/api-starter-kit/openapi/simple.yaml.src",
  35. "/home/rob/workspace/api-starter-kit/openapi/openapi.yaml.src",
  36. "/home/rob/workspace/api-starter-kit/openapi/spid.yaml.src")
  37.  
  38. def assert_parse_oas3(zapp, f):
  39. zapp.add_api(f, resolver=FakeResolver())
  40.  
  41. def assert_is_oas3(zapp):
  42. assert zapp.options.oas_version > (2, 0)
  43.  
  44. for f in files:
  45. zapp = connexion.FlaskApp(__name__, specification_dir='.',)
  46. yield assert_parse_oas3, zapp, f
  47. yield assert_is_oas3, zapp
Add Comment
Please, Sign In to add comment