test_system.py 5.7KB

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