test_permission.py 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # coding=utf-8
  2. import transaction
  3. from tracim.tests import eq_
  4. from tracim.tests import BaseTest
  5. from tracim.models.auth import Permission
  6. class TestPermissionModel(BaseTest):
  7. """
  8. Test for permission model
  9. """
  10. def test_unit__create__ok__nominal_case(self):
  11. self.session.flush()
  12. transaction.commit()
  13. name = 'my_permission'
  14. description = 'my_perm_description'
  15. permission = Permission()
  16. permission.permission_name = name
  17. permission.description = description
  18. self.session.add(permission)
  19. self.session.flush()
  20. transaction.commit()
  21. new_permission = self.session.query(Permission).filter(permission.permission_name == name).one() # nopep8
  22. assert new_permission.permission_name == name
  23. assert new_permission.description == description
  24. assert new_permission.permission_id
  25. assert isinstance(new_permission.permission_id, int)
  26. # TODO - G.M -24-05-2018 - Do test for groups
  27. def test_unit__repr__ok__nominal_case(self):
  28. name = 'my_permission'
  29. description = 'my_perm_description'
  30. permission = Permission()
  31. permission.permission_name = name
  32. permission.description = description
  33. assert permission.__repr__() == "<Permission: name='my_permission'>"
  34. def test_unit__unicode__ok__nominal_case(self):
  35. name = 'my_permission'
  36. description = 'my_perm_description'
  37. permission = Permission()
  38. permission.permission_name = name
  39. permission.description = description
  40. assert permission.__unicode__() == name