test_group_api.py 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # coding=utf-8
  2. import pytest
  3. from tracim_backend.exceptions import GroupDoesNotExist
  4. from tracim_backend.lib.core.group import GroupApi
  5. from tracim_backend.tests import DefaultTest
  6. from tracim_backend.fixtures.users_and_groups import Base as BaseFixture
  7. from tracim_backend.fixtures.content import Content as ContentFixture
  8. class TestGroupApi(DefaultTest):
  9. fixtures = [BaseFixture, ContentFixture]
  10. def test_unit__get_one__ok_nominal_case(self) -> None:
  11. """
  12. Get one group by id
  13. """
  14. api = GroupApi(
  15. current_user=None,
  16. session=self.session,
  17. config=self.app_config,
  18. )
  19. group = api.get_one(1)
  20. assert group.group_id == 1
  21. assert group.group_name == 'users'
  22. def test_unit__get_one__err__group_not_exist(self) -> None:
  23. """
  24. Get one group who does not exist by id
  25. """
  26. api = GroupApi(
  27. current_user=None,
  28. session=self.session,
  29. config=self.app_config,
  30. )
  31. with pytest.raises(GroupDoesNotExist):
  32. group = api.get_one(10)
  33. def test_unit__get_one_group_with_name__nominal_case(self) -> None:
  34. """
  35. get one group by name
  36. """
  37. api = GroupApi(
  38. current_user=None,
  39. session=self.session,
  40. config=self.app_config,
  41. )
  42. group = api.get_one_with_name('administrators')
  43. assert group.group_id == 3
  44. assert group.group_name == 'administrators'
  45. def test_unit__get_one_with_name__err__group_not_exist(self) -> None:
  46. """
  47. get one group by name who does not exist
  48. """
  49. api = GroupApi(
  50. current_user=None,
  51. session=self.session,
  52. config=self.app_config,
  53. )
  54. with pytest.raises(GroupDoesNotExist):
  55. group = api.get_one_with_name('unknown_group')
  56. def test_unit__get_all__ok__nominal_case(self):
  57. """
  58. get all groups
  59. """
  60. api = GroupApi(
  61. current_user=None,
  62. session=self.session,
  63. config=self.app_config,
  64. )
  65. groups = api.get_all()
  66. assert ['users', 'managers', 'administrators'] == [group.group_name for group in groups] # nopep8