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
967ef6ff
Commit
967ef6ff
authored
Jul 20, 2013
by
ihoover
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests added
parent
3d669eab
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
113 additions
and
0 deletions
+113
-0
common/djangoapps/student/tests/test_auto_auth.py
+113
-0
No files found.
common/djangoapps/student/tests/test_auto_auth.py
0 → 100644
View file @
967ef6ff
from
django.test
import
TestCase
from
util.testing
import
UrlResetMixin
from
django.contrib.auth.models
import
User
from
django.conf
import
settings
from
mock
import
patch
# from copy import deepcopy, copy
# NEW_SETTINGS = deepcopy(settings)
# update just the auth flag
# NEW_SETTINGS.MITX_FEATURES['AUTOMATIC_AUTH_FOR_LOAD_TESTING'] = True
# NEW_SETTINGS.MITX_FEATURES['MAX_AUTO_AUTH_USERS'] = 1
class
TestAutoAuthEnabled
(
UrlResetMixin
,
TestCase
):
"""
Tests for the Auto auth view that we have for load testing.
"""
@patch.dict
(
"django.conf.settings.MITX_FEATURES"
,
{
"AUTOMATIC_AUTH_FOR_LOAD_TESTING"
:
True
})
def
setUp
(
self
):
# Patching the settings.MITX_FEATURES['AUTOMATIC_AUTH_FOR_LOAD_TESTING']
# value affects the contents of urls.py,
# so we need to call super.setUp() which reloads urls.py (because
# of the UrlResetMixin)
super
(
TestAutoAuthEnabled
,
self
)
.
setUp
()
def
test_create_user
(
self
):
"""
tests that user gets created when visiting the page
"""
print
settings
.
MITX_FEATURES
[
'AUTOMATIC_AUTH_FOR_LOAD_TESTING'
]
url
=
'/auto_auth'
self
.
client
.
get
(
url
)
qset
=
User
.
objects
.
all
()
# assert user was created and is active
self
.
assertEqual
(
qset
.
count
(),
1
)
user
=
qset
[
0
]
assert
user
.
is_active
@patch.dict
(
"django.conf.settings.MITX_FEATURES"
,
{
"MAX_AUTO_AUTH_USERS"
:
10000000
})
def
test_create_multiple_users
(
self
):
"""
speculative test to make sure multiple users are created.
Technically, this test is probabalistic.
However, my judgement is that if the chance of failing due
only to bad luck is less than 1:10^1000, we are OK (it is more
likely that the test failed because the jenkins server was hit
by an asteroid, or the person running the tests was a freind
of Hamlet's).
"""
url
=
'/auto_auth'
# hit the url a few times
# mathematically, is much more efficient
# to hit the site many many times, and
# have a smaller MAX user count, but it is
# the GET request that actually takes a lot
# of time.
for
i
in
range
(
200
):
self
.
client
.
get
(
url
)
qset
=
User
.
objects
.
all
()
# make sure it is the smae user
self
.
assertGreater
(
qset
.
count
(),
1
)
@patch.dict
(
"django.conf.settings.MITX_FEATURES"
,
{
"MAX_AUTO_AUTH_USERS"
:
1
})
def
test_login
(
self
):
"""
test that when we have reached the limit for automatic users
a subsequent request results in an already existant one being
logged in.
"""
# auto-generate 1 user (the max)
url
=
'/auto_auth'
self
.
client
.
get
(
url
)
# go to the site again
self
.
client
.
get
(
url
)
qset
=
User
.
objects
.
all
()
# make sure it is the smae user
self
.
assertEqual
(
qset
.
count
(),
1
)
class
TestAutoAuthDisabled
(
UrlResetMixin
,
TestCase
):
"""
Test that the page is inaccessible with default settings
"""
@patch.dict
(
"django.conf.settings.MITX_FEATURES"
,
{
"AUTOMATIC_AUTH_FOR_LOAD_TESTING"
:
False
})
def
setUp
(
self
):
# Patching the settings.MITX_FEATURES['AUTOMATIC_AUTH_FOR_LOAD_TESTING']
# value affects the contents of urls.py,
# so we need to call super.setUp() which reloads urls.py (because
# of the UrlResetMixin)
super
(
TestAutoAuthDisabled
,
self
)
.
setUp
()
def
test_404
(
self
):
"""
make sure automatic authentication is invisible
"""
url
=
'/auto_auth'
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
404
)
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