test_signals.py 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. from django.contrib.auth.models import User
  2. from django.contrib.auth.signals import user_logged_in, user_logged_out
  3. from fixtures.sudo_testutils import BaseTestCase
  4. from sudo.signals import grant, revoke
  5. from sudo.utils import grant_sudo_privileges, has_sudo_privileges
  6. class SignalsTestCase(BaseTestCase):
  7. def test_grant(self):
  8. self.login()
  9. grant(User, self.request)
  10. self.assertTrue(has_sudo_privileges(self.request))
  11. def test_revoke(self):
  12. self.login()
  13. grant(User, self.request)
  14. revoke(User, self.request)
  15. self.assertFalse(has_sudo_privileges(self.request))
  16. def test_user_logged_in(self):
  17. self.login()
  18. user_logged_in.send_robust(sender=User, request=self.request)
  19. self.assertTrue(has_sudo_privileges(self.request))
  20. def test_user_logged_out(self):
  21. self.login()
  22. grant_sudo_privileges(self.request)
  23. self.assertTrue(has_sudo_privileges(self.request))
  24. user_logged_out.send_robust(sender=User, request=self.request)
  25. self.assertFalse(has_sudo_privileges(self.request))