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
ea31b17d
Commit
ea31b17d
authored
Jul 23, 2013
by
Jay Zoldak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix up auto auth tests.
parent
967ef6ff
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
49 deletions
+27
-49
common/djangoapps/student/tests/test_auto_auth.py
+27
-49
No files found.
common/djangoapps/student/tests/test_auto_auth.py
View file @
ea31b17d
from
django.test
import
TestCase
from
django.test
import
TestCase
from
util.testing
import
UrlResetMixin
from
django.test.client
import
Client
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.conf
import
settings
from
util.testing
import
UrlResetMixin
from
mock
import
patch
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
AutoAuthEnabledTestCase
(
UrlResetMixin
,
TestCase
):
class
TestAutoAuthEnabled
(
UrlResetMixin
,
TestCase
):
"""
"""
Tests for the Auto auth view that we have for load testing.
Tests for the Auto auth view that we have for load testing.
"""
"""
...
@@ -23,15 +16,15 @@ class TestAutoAuthEnabled(UrlResetMixin, TestCase):
...
@@ -23,15 +16,15 @@ class TestAutoAuthEnabled(UrlResetMixin, TestCase):
# value affects the contents of urls.py,
# value affects the contents of urls.py,
# so we need to call super.setUp() which reloads urls.py (because
# so we need to call super.setUp() which reloads urls.py (because
# of the UrlResetMixin)
# of the UrlResetMixin)
super
(
TestAutoAuthEnabled
,
self
)
.
setUp
()
super
(
AutoAuthEnabledTestCase
,
self
)
.
setUp
()
self
.
url
=
'/auto_auth'
self
.
client
=
Client
()
def
test_create_user
(
self
):
def
test_create_user
(
self
):
"""
"""
tests that user gets created when visiting the page
Test that user gets created when visiting the page.
"""
"""
print
settings
.
MITX_FEATURES
[
'AUTOMATIC_AUTH_FOR_LOAD_TESTING'
]
self
.
client
.
get
(
self
.
url
)
url
=
'/auto_auth'
self
.
client
.
get
(
url
)
qset
=
User
.
objects
.
all
()
qset
=
User
.
objects
.
all
()
...
@@ -40,43 +33,29 @@ class TestAutoAuthEnabled(UrlResetMixin, TestCase):
...
@@ -40,43 +33,29 @@ class TestAutoAuthEnabled(UrlResetMixin, TestCase):
user
=
qset
[
0
]
user
=
qset
[
0
]
assert
user
.
is_active
assert
user
.
is_active
@patch
.dict
(
"django.conf.settings.MITX_FEATURES"
,
{
"MAX_AUTO_AUTH_USERS"
:
10000000
}
)
@patch
(
'student.views.random.randint'
)
def
test_create_multiple_users
(
self
):
def
test_create_multiple_users
(
self
,
randint
):
"""
"""
speculative test to make sure multiple users are created.
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).
"""
"""
randint
.
return_value
=
1
self
.
client
.
get
(
self
.
url
)
url
=
'/auto_auth'
randint
.
return_value
=
2
self
.
client
.
get
(
self
.
url
)
# 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
()
qset
=
User
.
objects
.
all
()
# make sure
it is the smae user
# make sure
that USER_1 and USER_2 were created
self
.
assert
Greater
(
qset
.
count
(),
1
)
self
.
assert
Equal
(
qset
.
count
(),
2
)
@patch.dict
(
"django.conf.settings.MITX_FEATURES"
,
{
"MAX_AUTO_AUTH_USERS"
:
1
})
@patch.dict
(
"django.conf.settings.MITX_FEATURES"
,
{
"MAX_AUTO_AUTH_USERS"
:
1
})
def
test_login
(
self
):
def
test_login
_already_created_user
(
self
):
"""
"""
t
est that when we have reached the limit for automatic users
T
est that when we have reached the limit for automatic users
a subsequent request results in an already existant one being
a subsequent request results in an already existant one being
logged in.
logged in.
"""
"""
# auto-generate 1 user (the max)
# auto-generate 1 user (the max)
url
=
'/auto_auth'
url
=
'/auto_auth'
self
.
client
.
get
(
url
)
self
.
client
.
get
(
url
)
...
@@ -85,11 +64,11 @@ class TestAutoAuthEnabled(UrlResetMixin, TestCase):
...
@@ -85,11 +64,11 @@ class TestAutoAuthEnabled(UrlResetMixin, TestCase):
self
.
client
.
get
(
url
)
self
.
client
.
get
(
url
)
qset
=
User
.
objects
.
all
()
qset
=
User
.
objects
.
all
()
# make sure it is the s
ma
e user
# make sure it is the s
am
e user
self
.
assertEqual
(
qset
.
count
(),
1
)
self
.
assertEqual
(
qset
.
count
(),
1
)
class
TestAutoAuthDisabled
(
UrlResetMixin
,
TestCase
):
class
AutoAuthDisabledTestCase
(
UrlResetMixin
):
"""
"""
Test that the page is inaccessible with default settings
Test that the page is inaccessible with default settings
"""
"""
...
@@ -100,14 +79,13 @@ class TestAutoAuthDisabled(UrlResetMixin, TestCase):
...
@@ -100,14 +79,13 @@ class TestAutoAuthDisabled(UrlResetMixin, TestCase):
# value affects the contents of urls.py,
# value affects the contents of urls.py,
# so we need to call super.setUp() which reloads urls.py (because
# so we need to call super.setUp() which reloads urls.py (because
# of the UrlResetMixin)
# of the UrlResetMixin)
super
(
TestAutoAuthDisabled
,
self
)
.
setUp
()
super
(
AutoAuthDisabledTestCase
,
self
)
.
setUp
()
self
.
url
=
'/auto_auth'
self
.
client
=
Client
()
def
test_
404
(
self
):
def
test_
auto_auth_disabled
(
self
):
"""
"""
make sure automatic authentication is invisible
Make sure automatic authentication is disabled.
"""
"""
response
=
self
.
client
.
get
(
self
.
url
)
url
=
'/auto_auth'
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
404
)
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