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
385e9de1
Commit
385e9de1
authored
Aug 07, 2013
by
Jay Zoldak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modify auto_auth to accept parameters for overriding created user attributes.
parent
92f5246c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
10 deletions
+40
-10
common/djangoapps/student/tests/test_auto_auth.py
+26
-1
common/djangoapps/student/views.py
+14
-9
No files found.
common/djangoapps/student/tests/test_auto_auth.py
View file @
385e9de1
...
...
@@ -37,6 +37,26 @@ class AutoAuthEnabledTestCase(UrlResetMixin, TestCase):
user
=
qset
[
0
]
assert
user
.
is_active
def
test_create_defined_user
(
self
):
"""
Test that the user gets created with the correct attributes
when they are passed as parameters on the auto-auth page.
"""
self
.
client
.
get
(
self
.
url
,
{
'username'
:
'robot'
,
'password'
:
'test'
,
'email'
:
'robot@edx.org'
}
)
qset
=
User
.
objects
.
all
()
# assert user was created with the correct username and password
self
.
assertEqual
(
qset
.
count
(),
1
)
user
=
qset
[
0
]
self
.
assertEqual
(
user
.
username
,
'robot'
)
self
.
assertTrue
(
user
.
check_password
(
'test'
))
self
.
assertEqual
(
user
.
email
,
'robot@edx.org'
)
@patch
(
'student.views.random.randint'
)
def
test_create_multiple_users
(
self
,
randint
):
"""
...
...
@@ -50,8 +70,13 @@ class AutoAuthEnabledTestCase(UrlResetMixin, TestCase):
qset
=
User
.
objects
.
all
()
# make sure that USER_1 and USER_2 were created
# make sure that USER_1 and USER_2 were created
correctly
self
.
assertEqual
(
qset
.
count
(),
2
)
user1
=
qset
[
0
]
self
.
assertEqual
(
user1
.
username
,
'USER_1'
)
self
.
assertTrue
(
user1
.
check_password
(
'PASS_1'
))
self
.
assertEqual
(
user1
.
email
,
'USER_1_dummy_test@mitx.mit.edu'
)
self
.
assertEqual
(
qset
[
1
]
.
username
,
'USER_2'
)
@patch.dict
(
"django.conf.settings.MITX_FEATURES"
,
{
"MAX_AUTO_AUTH_USERS"
:
1
})
def
test_login_already_created_user
(
self
):
...
...
common/djangoapps/student/views.py
View file @
385e9de1
...
...
@@ -945,28 +945,33 @@ def auto_auth(request):
settings.MITX_SETTINGS['AUTOMATIC_AUTH_FOR_LOAD_TESTING'] is true.
"""
def
get_dummy_post_data
(
username
,
password
):
def
get_dummy_post_data
(
username
,
password
,
email
,
name
):
"""
Return a dictionary suitable for passing to post_vars of _do_create_account or post_override
of create_account, with specified
username and password
.
of create_account, with specified
values
.
"""
return
{
'username'
:
username
,
'email'
:
username
+
"_dummy_test@mitx.mit.edu"
,
'email'
:
email
,
'password'
:
password
,
'name'
:
username
+
" "
+
user
name
,
'name'
:
name
,
'honor_code'
:
u'true'
,
'terms_of_service'
:
u'true'
,
}
# generate random user c
e
redentials from a small name space (determined by settings)
# generate random user credentials from a small name space (determined by settings)
name_base
=
'USER_'
pass_base
=
'PASS_'
max_users
=
settings
.
MITX_FEATURES
.
get
(
'MAX_AUTO_AUTH_USERS'
,
200
)
number
=
random
.
randint
(
1
,
max_users
)
username
=
name_base
+
str
(
number
)
password
=
pass_base
+
str
(
number
)
# Get the params from the request to override default user attributes if specified
qdict
=
request
.
GET
# Use the params from the request, otherwise use these defaults
username
=
qdict
.
get
(
'username'
,
name_base
+
str
(
number
))
password
=
qdict
.
get
(
'password'
,
pass_base
+
str
(
number
))
email
=
qdict
.
get
(
'email'
,
'
%
s_dummy_test@mitx.mit.edu'
%
username
)
name
=
qdict
.
get
(
'name'
,
'
%
s Test'
%
username
)
# if they already are a user, log in
try
:
...
...
@@ -976,7 +981,7 @@ def auto_auth(request):
# else create and activate account info
except
ObjectDoesNotExist
:
post_override
=
get_dummy_post_data
(
username
,
password
)
post_override
=
get_dummy_post_data
(
username
,
password
,
email
,
name
)
create_account
(
request
,
post_override
=
post_override
)
request
.
user
.
is_active
=
True
request
.
user
.
save
()
...
...
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