2018-01-02 17:06:12 +01:00
|
|
|
from django.contrib.auth import get_user_model
|
|
|
|
|
|
|
|
from allauth_cas.test.testcases import CASTestCase, CASViewTestCase
|
|
|
|
|
|
|
|
User = get_user_model()
|
|
|
|
|
|
|
|
|
|
|
|
class ClipperProviderTests(CASTestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
2018-04-23 00:22:50 +02:00
|
|
|
pass
|
2018-01-02 17:06:12 +01:00
|
|
|
|
|
|
|
def test_auto_signup(self):
|
|
|
|
self.client_cas_login(
|
2018-04-23 00:22:50 +02:00
|
|
|
self.client, provider_id='clipper', username='clipperuid')
|
2018-01-02 17:06:12 +01:00
|
|
|
|
2018-04-23 00:22:50 +02:00
|
|
|
u = User.objects.get(username__contains='clipperuid')
|
|
|
|
self.assertEqual(u.email, 'clipperuid@clipper.ens.fr')
|
2017-08-03 12:40:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ClipperViewsTests(CASViewTestCase):
|
|
|
|
|
|
|
|
def test_login_view(self):
|
2018-04-23 00:22:50 +02:00
|
|
|
r = self.client.get('/account/clipper/login/')
|
2017-08-03 12:40:52 +02:00
|
|
|
expected = (
|
|
|
|
"https://cas.eleves.ens.fr/login?service=http%3A%2F%2Ftestserver"
|
2018-04-23 00:22:50 +02:00
|
|
|
"%2Faccount%2Fclipper%2Flogin%2Fcallback%2F"
|
2017-08-03 12:40:52 +02:00
|
|
|
)
|
|
|
|
self.assertRedirects(
|
|
|
|
r, expected,
|
|
|
|
fetch_redirect_response=False,
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_callback_view(self):
|
2018-01-02 17:06:12 +01:00
|
|
|
# Required to initialize a SocialLogin.
|
2018-04-23 00:22:50 +02:00
|
|
|
r = self.client.get('/account/clipper/login/')
|
2018-01-02 17:06:12 +01:00
|
|
|
|
|
|
|
# Tests.
|
2017-08-03 12:40:52 +02:00
|
|
|
self.patch_cas_response(valid_ticket='__all__')
|
2018-04-23 00:22:50 +02:00
|
|
|
r = self.client.get('/account/clipper/login/callback/', {
|
2017-08-03 12:40:52 +02:00
|
|
|
'ticket': '123456',
|
|
|
|
})
|
2018-04-23 00:22:50 +02:00
|
|
|
self.assertLoginSuccess(r, "/user/")
|
2017-08-03 12:40:52 +02:00
|
|
|
|
|
|
|
def test_logout_view(self):
|
2018-04-23 00:22:50 +02:00
|
|
|
r = self.client.get('/account/clipper/logout/')
|
2017-08-03 12:40:52 +02:00
|
|
|
expected = (
|
|
|
|
"https://cas.eleves.ens.fr/logout?service=http%3A%2F%2Ftestserver"
|
2018-04-23 00:22:50 +02:00
|
|
|
"%2Fview%2F"
|
2017-08-03 12:40:52 +02:00
|
|
|
)
|
|
|
|
self.assertRedirects(
|
|
|
|
r, expected,
|
|
|
|
fetch_redirect_response=False,
|
|
|
|
)
|