-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #131 from EsupPortail/dev
Dev
- Loading branch information
Showing
25 changed files
with
901 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
""" | ||
Unit tests for authentication views | ||
""" | ||
import os | ||
|
||
from django.conf import settings | ||
from django.test import override_settings | ||
from django.test import TestCase | ||
from django.test import Client | ||
from django.contrib.auth.models import User | ||
|
||
|
||
@override_settings( | ||
MEDIA_ROOT=os.path.join(settings.BASE_DIR, 'media'), | ||
DATABASES={ | ||
'default': { | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
'NAME': 'db.sqlite', | ||
} | ||
}, | ||
LANGUAGE_CODE='en' | ||
) | ||
class authenticationViewsTestCase(TestCase): | ||
fixtures = ['initial_data.json', ] | ||
|
||
def setUp(self): | ||
User.objects.create(username='pod', password='podv2') | ||
print(" ---> SetUp of authenticationViewsTestCase : OK !") | ||
|
||
def test_authentication_login_gateway(self): | ||
self.client = Client() | ||
# CAS_GATEWAY is valued to False | ||
response = self.client.get('/authentication_login_gateway/') | ||
self.assertEqual(response.content, | ||
b'You must set CAS_GATEWAY to True to use this view') | ||
self.assertEqual(response.status_code, 200) | ||
|
||
print( | ||
" ---> test_authentication_login_gateway \ | ||
of authenticationViewsTestCase : OK !") | ||
|
||
def test_authentication_login(self): | ||
self.client = Client() | ||
self.user = User.objects.get(username="pod") | ||
|
||
# User already authenticated | ||
self.client.force_login(self.user) | ||
response = self.client.get('/authentication_login/') | ||
self.assertRedirects(response, '/') | ||
|
||
# User not authenticated and CAS are valued to False | ||
self.client.logout() | ||
response = self.client.get('/authentication_login/') | ||
self.assertRedirects(response, '/accounts/login/?next=/') | ||
|
||
print( | ||
" ---> test_authentication_login \ | ||
of authenticationViewsTestCase : OK !") | ||
|
||
def test_authentication_logout(self): | ||
self.client = Client() | ||
# USE_CAS is valued to False | ||
response = self.client.get('/authentication_logout/') | ||
self.assertRedirects(response, '/accounts/logout/?next=/', | ||
target_status_code=302) | ||
|
||
print( | ||
" ---> test_authentication_logout \ | ||
of authenticationViewsTestCase : OK !") | ||
|
||
def test_userpicture(self): | ||
self.client = Client() | ||
self.user = User.objects.get(username="pod") | ||
# User is not loged in | ||
response = self.client.get('/accounts/userpicture/') | ||
self.assertEqual(response.status_code, 302) # Redirect to login page | ||
|
||
# User is loged in | ||
self.client.force_login(self.user) | ||
# GET method | ||
response = self.client.get('/accounts/userpicture/') | ||
messages = list(response.wsgi_request._messages) | ||
self.assertEqual(len(messages), 0) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertTemplateUsed(response, 'userpicture/userpicture.html') | ||
# POST method | ||
# Form is valid | ||
response = self.client.post('/accounts/userpicture/', | ||
{'userpicture': ''}) | ||
messages = list(response.wsgi_request._messages) | ||
self.assertEqual(len(messages), 1) | ||
self.assertEqual(str(messages[0]), 'Your picture has been saved.') | ||
self.assertEqual(response.status_code, 200) | ||
self.assertTemplateUsed(response, 'userpicture/userpicture.html') | ||
# Form is not valid | ||
response = self.client.post('/accounts/userpicture/', | ||
{'userpicture': 12}) | ||
messages = list(response.wsgi_request._messages) | ||
self.assertEqual(len(messages), 1) | ||
self.assertEqual(str(messages[0]), | ||
'One or more errors have been found in the form.') | ||
self.assertEqual(response.status_code, 200) | ||
self.assertTemplateUsed(response, 'userpicture/userpicture.html') | ||
|
||
print( | ||
" ---> test_userpicture of authenticationViewsTestCase : OK !") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.