test_system.py 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. # coding=utf-8
  2. from tracim_backend.tests import FunctionalTest
  3. from tracim_backend.models.applications import applications
  4. """
  5. Tests for /api/v2/system subpath endpoints.
  6. """
  7. class TestApplicationEndpoint(FunctionalTest):
  8. """
  9. Tests for /api/v2/system/applications
  10. """
  11. def test_api__get_applications__ok_200__nominal_case(self):
  12. """
  13. Get applications list with a registered user.
  14. """
  15. self.testapp.authorization = (
  16. 'Basic',
  17. (
  18. 'admin@admin.admin',
  19. 'admin@admin.admin'
  20. )
  21. )
  22. res = self.testapp.get('/api/v2/system/applications', status=200)
  23. res = res.json_body
  24. assert len(res) == len(applications)
  25. for counter, application in enumerate(applications):
  26. assert res[counter]['label'] == application.label
  27. assert res[counter]['slug'] == application.slug
  28. assert res[counter]['fa_icon'] == application.fa_icon
  29. assert res[counter]['hexcolor'] == application.hexcolor
  30. assert res[counter]['is_active'] == application.is_active
  31. assert res[counter]['config'] == application.config
  32. def test_api__get_applications__err_401__unregistered_user(self):
  33. """
  34. Get applications list with an unregistered user (bad auth)
  35. """
  36. self.testapp.authorization = (
  37. 'Basic',
  38. (
  39. 'john@doe.doe',
  40. 'lapin'
  41. )
  42. )
  43. res = self.testapp.get('/api/v2/system/applications', status=401)
  44. assert isinstance(res.json, dict)
  45. assert 'code' in res.json.keys()
  46. assert 'message' in res.json.keys()
  47. assert 'details' in res.json.keys()
  48. class TestContentsTypesEndpoint(FunctionalTest):
  49. """
  50. Tests for /api/v2/system/content_types
  51. """
  52. def test_api__get_content_types__ok_200__nominal_case(self):
  53. """
  54. Get system content_types list with a registered user.
  55. """
  56. self.testapp.authorization = (
  57. 'Basic',
  58. (
  59. 'admin@admin.admin',
  60. 'admin@admin.admin'
  61. )
  62. )
  63. res = self.testapp.get('/api/v2/system/content_types', status=200)
  64. res = res.json_body
  65. content_type = res[1]
  66. assert content_type['slug'] == 'thread'
  67. assert content_type['fa_icon'] == 'comments-o'
  68. assert content_type['hexcolor'] == '#ad4cf9'
  69. assert content_type['label'] == 'Thread'
  70. assert content_type['creation_label'] == 'Discuss about a topic'
  71. assert 'available_statuses' in content_type
  72. assert len(content_type['available_statuses']) == 4
  73. content_type = res[2]
  74. assert content_type['slug'] == 'file'
  75. assert content_type['fa_icon'] == 'paperclip'
  76. assert content_type['hexcolor'] == '#FF9900'
  77. assert content_type['label'] == 'File'
  78. assert content_type['creation_label'] == 'Upload a file'
  79. assert 'available_statuses' in content_type
  80. assert len(content_type['available_statuses']) == 4
  81. content_type = res[3]
  82. assert content_type['slug'] == 'markdownpage'
  83. assert content_type['fa_icon'] == 'file-code-o'
  84. assert content_type['hexcolor'] == '#f12d2d'
  85. assert content_type['label'] == 'Rich Markdown File'
  86. assert content_type['creation_label'] == 'Create a Markdown document'
  87. assert 'available_statuses' in content_type
  88. assert len(content_type['available_statuses']) == 4
  89. content_type = res[4]
  90. assert content_type['slug'] == 'html-document'
  91. assert content_type['fa_icon'] == 'file-text-o'
  92. assert content_type['hexcolor'] == '#3f52e3'
  93. assert content_type['label'] == 'Text Document'
  94. assert content_type['creation_label'] == 'Write a document'
  95. assert 'available_statuses' in content_type
  96. assert len(content_type['available_statuses']) == 4
  97. # TODO - G.M - 31-05-2018 - Check Folder type
  98. # TODO - G.M - 29-05-2018 - Better check for available_statuses
  99. def test_api__get_content_types__err_401__unregistered_user(self):
  100. """
  101. Get system content_types list with an unregistered user (bad auth)
  102. """
  103. self.testapp.authorization = (
  104. 'Basic',
  105. (
  106. 'john@doe.doe',
  107. 'lapin'
  108. )
  109. )
  110. res = self.testapp.get('/api/v2/system/content_types', status=401)
  111. assert isinstance(res.json, dict)
  112. assert 'code' in res.json.keys()
  113. assert 'message' in res.json.keys()
  114. assert 'details' in res.json.keys()