test_system.py 4.0KB

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