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
7be356b3
Commit
7be356b3
authored
Feb 25, 2014
by
jsa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto_auth: add ability to configure forum roles and scrape user id.
parent
7ee08eae
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
6 deletions
+50
-6
common/djangoapps/student/tests/test_auto_auth.py
+38
-3
common/djangoapps/student/views.py
+2
-2
common/test/acceptance/pages/studio/auto_auth.py
+10
-1
No files found.
common/djangoapps/student/tests/test_auto_auth.py
View file @
7be356b3
from
django.test
import
TestCase
from
django.test.client
import
Client
from
django.contrib.auth.models
import
User
from
django_comment_common.models
import
(
Role
,
FORUM_ROLE_ADMINISTRATOR
,
FORUM_ROLE_MODERATOR
,
FORUM_ROLE_STUDENT
)
from
django_comment_common.utils
import
seed_permissions_roles
from
student.models
import
CourseEnrollment
,
UserProfile
from
util.testing
import
UrlResetMixin
from
mock
import
patch
from
django.core.urlresolvers
import
reverse
,
NoReverseMatch
class
AutoAuthEnabledTestCase
(
UrlResetMixin
,
TestCase
):
...
...
@@ -103,6 +105,39 @@ class AutoAuthEnabledTestCase(UrlResetMixin, TestCase):
enrollment
=
CourseEnrollment
.
objects
.
get
(
course_id
=
course_id
)
self
.
assertEqual
(
enrollment
.
user
.
username
,
"test"
)
def
test_set_roles
(
self
):
course_id
=
"edX/Test101/2014_Spring"
seed_permissions_roles
(
course_id
)
course_roles
=
dict
((
r
.
name
,
r
)
for
r
in
Role
.
objects
.
filter
(
course_id
=
course_id
))
self
.
assertEqual
(
len
(
course_roles
),
4
)
# sanity check
# Student role is assigned by default on course enrollment.
self
.
_auto_auth
(
username
=
'a_student'
,
course_id
=
course_id
)
user
=
User
.
objects
.
get
(
username
=
'a_student'
)
user_roles
=
user
.
roles
.
all
()
self
.
assertEqual
(
len
(
user_roles
),
1
)
self
.
assertEqual
(
user_roles
[
0
],
course_roles
[
FORUM_ROLE_STUDENT
])
self
.
_auto_auth
(
username
=
'a_moderator'
,
course_id
=
course_id
,
roles
=
'Moderator'
)
user
=
User
.
objects
.
get
(
username
=
'a_moderator'
)
user_roles
=
user
.
roles
.
all
()
self
.
assertEqual
(
set
(
user_roles
),
set
([
course_roles
[
FORUM_ROLE_STUDENT
],
course_roles
[
FORUM_ROLE_MODERATOR
]]))
# check multiple roles work.
self
.
_auto_auth
(
username
=
'an_admin'
,
course_id
=
course_id
,
roles
=
'{},{}'
.
format
(
FORUM_ROLE_MODERATOR
,
FORUM_ROLE_ADMINISTRATOR
))
user
=
User
.
objects
.
get
(
username
=
'an_admin'
)
user_roles
=
user
.
roles
.
all
()
self
.
assertEqual
(
set
(
user_roles
),
set
([
course_roles
[
FORUM_ROLE_STUDENT
],
course_roles
[
FORUM_ROLE_MODERATOR
],
course_roles
[
FORUM_ROLE_ADMINISTRATOR
]]))
def
_auto_auth
(
self
,
**
params
):
"""
Make a request to the auto-auth end-point and check
...
...
@@ -113,8 +148,8 @@ class AutoAuthEnabledTestCase(UrlResetMixin, TestCase):
# Check that session and CSRF are set in the response
for
cookie
in
[
'csrftoken'
,
'sessionid'
]:
self
.
assertIn
(
cookie
,
response
.
cookies
)
#pylint: disable=E1103
self
.
assertTrue
(
response
.
cookies
[
cookie
]
.
value
)
#pylint: disable=E1103
self
.
assertIn
(
cookie
,
response
.
cookies
)
#
pylint: disable=E1103
self
.
assertTrue
(
response
.
cookies
[
cookie
]
.
value
)
#
pylint: disable=E1103
class
AutoAuthDisabledTestCase
(
UrlResetMixin
,
TestCase
):
...
...
common/djangoapps/student/views.py
View file @
7be356b3
...
...
@@ -1274,8 +1274,8 @@ def auto_auth(request):
# Provide the user with a valid CSRF token
# then return a 200 response
success_msg
=
u"Logged in user {0} ({1}) with password {2}"
.
format
(
username
,
email
,
password
success_msg
=
u"Logged in user {0} ({1}) with password {2}
and user_id {3}
"
.
format
(
username
,
email
,
password
,
user
.
id
)
response
=
HttpResponse
(
success_msg
)
response
.
set_cookie
(
'csrftoken'
,
csrf
(
request
)[
'csrf_token'
])
...
...
common/test/acceptance/pages/studio/auto_auth.py
View file @
7be356b3
...
...
@@ -2,6 +2,7 @@
Auto-auth page (used to automatically log in during testing).
"""
import
re
import
urllib
from
bok_choy.page_object
import
PageObject
from
.
import
BASE_URL
...
...
@@ -14,7 +15,7 @@ class AutoAuthPage(PageObject):
this url will create a user and log them in.
"""
def
__init__
(
self
,
browser
,
username
=
None
,
email
=
None
,
password
=
None
,
staff
=
None
,
course_id
=
None
):
def
__init__
(
self
,
browser
,
username
=
None
,
email
=
None
,
password
=
None
,
staff
=
None
,
course_id
=
None
,
roles
=
None
):
"""
Auto-auth is an end-point for HTTP GET requests.
By default, it will create accounts with random user credentials,
...
...
@@ -47,6 +48,9 @@ class AutoAuthPage(PageObject):
if
course_id
is
not
None
:
self
.
_params
[
'course_id'
]
=
course_id
if
roles
is
not
None
:
self
.
_params
[
'roles'
]
=
roles
@property
def
url
(
self
):
"""
...
...
@@ -62,3 +66,8 @@ class AutoAuthPage(PageObject):
def
is_browser_on_page
(
self
):
return
True
def
get_user_id
(
self
):
message
=
self
.
css_text
(
'BODY'
)[
0
]
.
strip
()
match
=
re
.
search
(
r' user_id ([^$]+)$'
,
message
)
return
match
.
groups
()[
0
]
if
match
else
None
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