tests_roles.py 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # coding=utf-8
  2. import unittest
  3. import pytest
  4. from tracim_backend.exceptions import RoleDoesNotExist
  5. from tracim_backend.models.roles import WorkspaceRoles
  6. class TestWorkspacesRoles(unittest.TestCase):
  7. """
  8. Test for WorkspaceRoles Enum Object
  9. """
  10. def test_workspace_roles__ok__all_list(self):
  11. roles = list(WorkspaceRoles)
  12. assert len(roles) == 5
  13. for role in roles:
  14. assert role
  15. assert role.slug
  16. assert isinstance(role.slug, str)
  17. assert role.level or role.level == 0
  18. assert isinstance(role.level, int)
  19. assert role.label
  20. assert isinstance(role.slug, str)
  21. assert WorkspaceRoles['READER']
  22. assert WorkspaceRoles['NOT_APPLICABLE']
  23. assert WorkspaceRoles['CONTRIBUTOR']
  24. assert WorkspaceRoles['WORKSPACE_MANAGER']
  25. assert WorkspaceRoles['CONTENT_MANAGER']
  26. def test__workspace_roles__ok__check_model(self):
  27. role = WorkspaceRoles.WORKSPACE_MANAGER
  28. assert role
  29. assert role.slug
  30. assert isinstance(role.slug, str)
  31. assert role.level
  32. assert isinstance(role.level, int)
  33. assert role.label
  34. assert isinstance(role.slug, str)
  35. def test_workspace_roles__ok__get_all_valid_roles(self):
  36. roles = WorkspaceRoles.get_all_valid_role()
  37. assert len(roles) == 4
  38. for role in roles:
  39. assert role
  40. assert role.slug
  41. assert isinstance(role.slug, str)
  42. assert role.level or role.level == 0
  43. assert isinstance(role.level, int)
  44. assert role.level > 0
  45. assert role.label
  46. assert isinstance(role.slug, str)
  47. def test_workspace_roles__ok__get_role__from_level__ok__nominal_case(self):
  48. role = WorkspaceRoles.get_role_from_level(0)
  49. assert role
  50. assert role.slug
  51. assert isinstance(role.slug, str)
  52. assert role.level == 0
  53. assert isinstance(role.level, int)
  54. assert role.label
  55. assert isinstance(role.slug, str)
  56. def test_workspace_roles__ok__get_role__from_slug__ok__nominal_case(self):
  57. role = WorkspaceRoles.get_role_from_slug('reader')
  58. assert role
  59. assert role.slug
  60. assert isinstance(role.slug, str)
  61. assert role.level > 0
  62. assert isinstance(role.level, int)
  63. assert role.label
  64. assert isinstance(role.slug, str)
  65. def test_workspace_roles__ok__get_role__from_level__err__role_does_not_exist(self): # nopep8
  66. with pytest.raises(RoleDoesNotExist):
  67. WorkspaceRoles.get_role_from_level(-1000)
  68. def test_workspace_roles__ok__get_role__from_slug__err__role_does_not_exist(self): # nopep8
  69. with pytest.raises(RoleDoesNotExist):
  70. WorkspaceRoles.get_role_from_slug('this slug does not exist')