test_system.py 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # coding=utf-8
  2. import transaction
  3. from tracim_backend.extensions import app_list
  4. from tracim_backend.lib.core.application import ApplicationApi
  5. from tracim_backend.models import get_tm_session
  6. from tracim_backend.app_models.contents import CONTENT_TYPES
  7. from tracim_backend.tests import FunctionalTest
  8. """
  9. Tests for /api/v2/system subpath endpoints.
  10. """
  11. class TestApplicationEndpoint(FunctionalTest):
  12. """
  13. Tests for /api/v2/system/applications
  14. """
  15. def test_api__get_applications__ok_200__nominal_case(self):
  16. """
  17. Get applications list with a registered user.
  18. """
  19. self.testapp.authorization = (
  20. 'Basic',
  21. (
  22. 'admin@admin.admin',
  23. 'admin@admin.admin'
  24. )
  25. )
  26. res = self.testapp.get('/api/v2/system/applications', status=200)
  27. res = res.json_body
  28. dbsession = get_tm_session(self.session_factory, transaction.manager)
  29. app_api = ApplicationApi(
  30. app_list=app_list,
  31. )
  32. applications = app_api.get_all()
  33. assert len(res) == len(applications)
  34. for counter, application in enumerate(applications):
  35. assert res[counter]['label'] == application.label
  36. assert res[counter]['slug'] == application.slug
  37. assert res[counter]['fa_icon'] == application.fa_icon
  38. assert res[counter]['hexcolor'] == application.hexcolor
  39. assert res[counter]['is_active'] == application.is_active
  40. assert res[counter]['config'] == application.config
  41. def test_api__get_applications__err_401__unregistered_user(self):
  42. """
  43. Get applications list with an unregistered user (bad auth)
  44. """
  45. self.testapp.authorization = (
  46. 'Basic',
  47. (
  48. 'john@doe.doe',
  49. 'lapin'
  50. )
  51. )
  52. res = self.testapp.get('/api/v2/system/applications', status=401)
  53. assert isinstance(res.json, dict)
  54. assert 'code' in res.json.keys()
  55. assert 'message' in res.json.keys()
  56. assert 'details' in res.json.keys()
  57. class TestContentsTypesEndpoint(FunctionalTest):
  58. """
  59. Tests for /api/v2/system/content_types
  60. """
  61. def test_api__get_content_types__ok_200__nominal_case(self):
  62. """
  63. Get system content_types list with a registered user.
  64. """
  65. self.testapp.authorization = (
  66. 'Basic',
  67. (
  68. 'admin@admin.admin',
  69. 'admin@admin.admin'
  70. )
  71. )
  72. res = self.testapp.get('/api/v2/system/content_types', status=200)
  73. res = res.json_body
  74. assert len(res) == len(CONTENT_TYPES.endpoint_allowed_types_slug())
  75. content_types = CONTENT_TYPES.endpoint_allowed_types_slug()
  76. for counter, content_type_slug in enumerate(content_types):
  77. content_type = CONTENT_TYPES.get_one_by_slug(content_type_slug)
  78. assert res[counter]['slug'] == content_type.slug
  79. assert res[counter]['fa_icon'] == content_type.fa_icon
  80. assert res[counter]['hexcolor'] == content_type.hexcolor
  81. assert res[counter]['label'] == content_type.label
  82. assert res[counter]['creation_label'] == content_type.creation_label
  83. for status_counter, status in enumerate(content_type.available_statuses):
  84. assert res[counter]['available_statuses'][status_counter]['fa_icon'] == status.fa_icon # nopep8
  85. assert res[counter]['available_statuses'][status_counter]['global_status'] == status.global_status # nopep8
  86. assert res[counter]['available_statuses'][status_counter]['slug'] == status.slug # nopep8
  87. assert res[counter]['available_statuses'][status_counter]['hexcolor'] == status.hexcolor # nopep8
  88. def test_api__get_content_types__err_401__unregistered_user(self):
  89. """
  90. Get system content_types list with an unregistered user (bad auth)
  91. """
  92. self.testapp.authorization = (
  93. 'Basic',
  94. (
  95. 'john@doe.doe',
  96. 'lapin'
  97. )
  98. )
  99. res = self.testapp.get('/api/v2/system/content_types', status=401)
  100. assert isinstance(res.json, dict)
  101. assert 'code' in res.json.keys()
  102. assert 'message' in res.json.keys()
  103. assert 'details' in res.json.keys()