test_business.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. from unittest import TestCase
  2. from unittest.mock import MagicMock, patch
  3. from django_sso.business import (
  4. _get_user,
  5. _login_user,
  6. _logout_user,
  7. _redirect_url,
  8. _service_url,
  9. )
  10. class DjangoAuthBusinessTests(TestCase):
  11. def test_get_user(self):
  12. request = MagicMock()
  13. ticket = "mock_ticket"
  14. service = "foo.bar"
  15. with (patch("django_sso.business.authenticate")):
  16. _ = _get_user(request, service, ticket)
  17. def test_login_user(self):
  18. request = MagicMock()
  19. user = MagicMock()
  20. with (patch("django_sso.business.django_login")):
  21. _ = _login_user(request, user)
  22. def test_logout_user(self):
  23. request = MagicMock()
  24. with (patch("django_sso.business.django_logout")):
  25. _ = _logout_user(request)
  26. class PvtBusinessTests(TestCase):
  27. def test_service_url(self):
  28. request = MagicMock()
  29. request.is_secure.return_value = True
  30. request.get_host.return_value = "foo.example.com"
  31. request.path = "/?foo"
  32. redirect_to = "example.com"
  33. with (patch("django_sso.business.authenticate")):
  34. _ = _service_url(request, redirect_to)
  35. def test_redirect_url(self):
  36. request = MagicMock()
  37. request.GET = {}
  38. settings = MagicMock()
  39. settings.CAS_IGNORE_REFERER = False
  40. with (patch("django_sso.business.authenticate")):
  41. _ = _redirect_url(request, settings)