Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
3b217df9
Commit
3b217df9
authored
Dec 04, 2015
by
Christine Lytwynec
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add new tests for auto_auth redirecting
parent
e10614e7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
8 deletions
+59
-8
common/djangoapps/student/tests/test_auto_auth.py
+37
-2
common/djangoapps/student/views.py
+22
-6
No files found.
common/djangoapps/student/tests/test_auto_auth.py
View file @
3b217df9
...
...
@@ -175,7 +175,40 @@ class AutoAuthEnabledTestCase(UrlResetMixin, TestCase):
response_data
)
def
_auto_auth
(
self
,
params
=
None
,
**
kwargs
):
@ddt.data
(
*
COURSE_IDS_DDT
)
@ddt.unpack
def
test_redirect_to_course
(
self
,
course_id
,
course_key
):
# Create a user and enroll in a course
response
=
self
.
_auto_auth
({
'username'
:
'test'
,
'course_id'
:
course_id
,
'redirect'
:
True
,
'staff'
:
'true'
,
},
status_code
=
302
)
# Check that a course enrollment was created for the user
self
.
assertEqual
(
CourseEnrollment
.
objects
.
count
(),
1
)
enrollment
=
CourseEnrollment
.
objects
.
get
(
course_id
=
course_key
)
self
.
assertEqual
(
enrollment
.
user
.
username
,
"test"
)
# Check that the redirect was to the course info/outline page
urls
=
(
'/info'
,
'course/{}'
.
format
(
course_key
.
to_deprecated_string
()))
response
.
url
.
endswith
(
urls
)
# pylint: disable=no-member
def
test_redirect_to_main
(
self
):
# Create user and redirect to 'home' (cms) or 'dashboard' (lms)
response
=
self
.
_auto_auth
({
'username'
:
'test'
,
'redirect'
:
True
,
'staff'
:
'true'
,
},
status_code
=
302
)
# Check that the redirect was to either /dashboard or /home
urls
=
(
'/dashboard'
,
'/home'
)
response
.
url
.
endswith
(
urls
)
# pylint: disable=no-member
def
_auto_auth
(
self
,
params
=
None
,
status_code
=
None
,
**
kwargs
):
"""
Make a request to the auto-auth end-point and check
that the response is successful.
...
...
@@ -189,7 +222,9 @@ class AutoAuthEnabledTestCase(UrlResetMixin, TestCase):
"""
params
=
params
or
{}
response
=
self
.
client
.
get
(
self
.
url
,
params
,
**
kwargs
)
self
.
assertEqual
(
response
.
status_code
,
200
)
expected_status_code
=
status_code
if
status_code
else
200
self
.
assertEqual
(
response
.
status_code
,
expected_status_code
)
# Check that session and CSRF are set in the response
for
cookie
in
[
'csrftoken'
,
'sessionid'
]:
...
...
common/djangoapps/student/views.py
View file @
3b217df9
...
...
@@ -21,7 +21,7 @@ from django.contrib.auth.views import password_reset_confirm
from
django.contrib
import
messages
from
django.core.context_processors
import
csrf
from
django.core
import
mail
from
django.core.urlresolvers
import
reverse
from
django.core.urlresolvers
import
reverse
,
NoReverseMatch
from
django.core.validators
import
validate_email
,
ValidationError
from
django.db
import
IntegrityError
,
transaction
from
django.http
import
(
HttpResponse
,
HttpResponseBadRequest
,
HttpResponseForbidden
,
...
...
@@ -1891,12 +1891,28 @@ def auto_auth(request):
if
redirect_when_done
:
# Redirect to course info page if course_id is known
if
course_id
:
return
redirect
(
reverse
(
'info'
,
kwargs
=
{
'course_id'
:
unicode
(
course_id
)}))
# Otherwise redirect to dashboard
try
:
# redirect to course info page in LMS
redirect_url
=
reverse
(
'info'
,
kwargs
=
{
'course_id'
:
unicode
(
course_id
)}
)
except
NoReverseMatch
:
# redirect to course outline page in Studio
redirect_url
=
reverse
(
'course_handler'
,
kwargs
=
{
'course_key_string'
:
unicode
(
course_key
)}
)
else
:
return
redirect
(
reverse
(
'dashboard'
))
if
request
.
META
.
get
(
'HTTP_ACCEPT'
)
==
'application/json'
:
try
:
# redirect to dashboard for LMS
redirect_url
=
reverse
(
'dashboard'
)
except
NoReverseMatch
:
# redirect to home for Studio
redirect_url
=
reverse
(
'home'
)
return
redirect
(
redirect_url
)
elif
request
.
META
.
get
(
'HTTP_ACCEPT'
)
==
'application/json'
:
response
=
JsonResponse
({
'created_status'
:
u"Logged in"
if
login_when_done
else
"Created"
,
'username'
:
username
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment