test_hapic.py 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # -*- coding: utf-8 -*-
  2. from hapic import Hapic
  3. from hapic.decorator import DECORATION_ATTRIBUTE_NAME
  4. from tests.base import Base
  5. class TestHapic(Base):
  6. def test_unit__decoration__ok__simple_function(self):
  7. hapic = Hapic()
  8. @hapic.with_api_doc()
  9. def controller_a():
  10. pass
  11. token = getattr(controller_a, DECORATION_ATTRIBUTE_NAME, None)
  12. assert token
  13. assert hapic.controllers
  14. assert 1 == len(hapic.controllers)
  15. reference = hapic.controllers[0].reference
  16. assert token == reference.token
  17. assert controller_a == reference.wrapper
  18. assert controller_a != reference.wrapped
  19. def test_unit__decoration__ok__method(self):
  20. hapic = Hapic()
  21. class MyControllers(object):
  22. @hapic.with_api_doc()
  23. def controller_a(self):
  24. pass
  25. my_controllers = MyControllers()
  26. class_method_token = getattr(
  27. MyControllers.controller_a,
  28. DECORATION_ATTRIBUTE_NAME,
  29. None,
  30. )
  31. assert class_method_token
  32. instance_method_token = getattr(
  33. my_controllers.controller_a,
  34. DECORATION_ATTRIBUTE_NAME,
  35. None,
  36. )
  37. assert instance_method_token
  38. assert hapic.controllers
  39. assert 1 == len(hapic.controllers)
  40. reference = hapic.controllers[0].reference
  41. assert class_method_token == reference.token
  42. assert instance_method_token == reference.token
  43. assert MyControllers.controller_a == reference.wrapper
  44. assert MyControllers.controller_a != reference.wrapped
  45. assert my_controllers.controller_a != reference.wrapper
  46. assert my_controllers.controller_a != reference.wrapped