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
9da81ada
Commit
9da81ada
authored
Oct 20, 2014
by
Will Daly
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5626 from edx/will/more-unit-tests-failures
Fix unit test failures due to duplicate url names
parents
6250c95d
d558a361
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
17 deletions
+38
-17
common/djangoapps/third_party_auth/tests/testutil.py
+2
-0
common/djangoapps/util/testing.py
+29
-10
lms/djangoapps/student_account/test/test_views.py
+4
-4
lms/djangoapps/student_account/urls.py
+2
-2
lms/djangoapps/student_profile/test/test_views.py
+1
-1
No files found.
common/djangoapps/third_party_auth/tests/testutil.py
View file @
9da81ada
...
...
@@ -30,8 +30,10 @@ class TestCase(unittest.TestCase):
def
setUp
(
self
):
super
(
TestCase
,
self
)
.
setUp
()
self
.
_original_providers
=
provider
.
Registry
.
_get_all
()
provider
.
Registry
.
_reset
()
def
tearDown
(
self
):
provider
.
Registry
.
_reset
()
provider
.
Registry
.
configure_once
(
self
.
_original_providers
)
super
(
TestCase
,
self
)
.
tearDown
()
common/djangoapps/util/testing.py
View file @
9da81ada
...
...
@@ -19,19 +19,38 @@ class UrlResetMixin(object):
that affect the contents of urls.py
"""
def
_reset_urls
(
self
,
urlconf
=
None
):
if
urlconf
is
None
:
urlconf
=
settings
.
ROOT_URLCONF
if
urlconf
in
sys
.
modules
:
reload
(
sys
.
modules
[
urlconf
])
def
_reset_urls
(
self
,
urlconf_modules
):
for
urlconf
in
urlconf_modules
:
if
urlconf
in
sys
.
modules
:
reload
(
sys
.
modules
[
urlconf
])
clear_url_caches
()
# Resolve a URL so that the new urlconf gets loaded
resolve
(
'/'
)
def
setUp
(
self
,
**
kwargs
):
"""Reset django default urlconf before tests and after tests"""
def
setUp
(
self
,
*
args
,
**
kwargs
):
"""Reset Django urls before tests and after tests
If you need to reset `urls.py` from a particular Django app (or apps),
specify these modules in *args.
Examples:
# Reload only the root urls.py
super(MyTestCase, self).setUp()
# Reload urls from my_app
super(MyTestCase, self).setUp("my_app.urls")
# Reload urls from my_app and another_app
super(MyTestCase, self).setUp("my_app.urls", "another_app.urls")
"""
super
(
UrlResetMixin
,
self
)
.
setUp
(
**
kwargs
)
self
.
_reset_urls
()
self
.
addCleanup
(
self
.
_reset_urls
)
urlconf_modules
=
[
settings
.
ROOT_URLCONF
]
if
args
:
urlconf_modules
.
extend
(
args
)
self
.
_reset_urls
(
urlconf_modules
)
self
.
addCleanup
(
lambda
:
self
.
_reset_urls
(
urlconf_modules
))
lms/djangoapps/student_account/test/test_views.py
View file @
9da81ada
...
...
@@ -47,7 +47,7 @@ class StudentAccountViewTest(UrlResetMixin, TestCase):
@patch.dict
(
settings
.
FEATURES
,
{
'ENABLE_NEW_DASHBOARD'
:
True
})
def
setUp
(
self
):
super
(
StudentAccountViewTest
,
self
)
.
setUp
()
super
(
StudentAccountViewTest
,
self
)
.
setUp
(
"student_account.urls"
)
# Create/activate a new account
activation_key
=
account_api
.
create_account
(
self
.
USERNAME
,
self
.
PASSWORD
,
self
.
OLD_EMAIL
)
...
...
@@ -62,8 +62,8 @@ class StudentAccountViewTest(UrlResetMixin, TestCase):
self
.
assertContains
(
response
,
"Student Account"
)
@ddt.data
(
(
"login"
,
"login"
),
(
"register"
,
"register"
),
(
"
account_
login"
,
"login"
),
(
"
account_
register"
,
"register"
),
)
@ddt.unpack
def
test_login_and_registration_form
(
self
,
url_name
,
initial_mode
):
...
...
@@ -71,7 +71,7 @@ class StudentAccountViewTest(UrlResetMixin, TestCase):
expected_data
=
u"data-initial-mode=
\"
{mode}
\"
"
.
format
(
mode
=
initial_mode
)
self
.
assertContains
(
response
,
expected_data
)
@ddt.data
(
"
login"
,
"
register"
)
@ddt.data
(
"
account_login"
,
"account_
register"
)
def
test_login_and_registration_third_party_auth_urls
(
self
,
url_name
):
response
=
self
.
client
.
get
(
reverse
(
url_name
))
...
...
lms/djangoapps/student_account/urls.py
View file @
9da81ada
...
...
@@ -4,8 +4,8 @@ from django.conf import settings
urlpatterns
=
patterns
(
'student_account.views'
,
url
(
r'^login/$'
,
'login_and_registration_form'
,
{
'initial_mode'
:
'login'
},
name
=
'login'
),
url
(
r'^register/$'
,
'login_and_registration_form'
,
{
'initial_mode'
:
'register'
},
name
=
'register'
),
url
(
r'^login/$'
,
'login_and_registration_form'
,
{
'initial_mode'
:
'login'
},
name
=
'
account_
login'
),
url
(
r'^register/$'
,
'login_and_registration_form'
,
{
'initial_mode'
:
'register'
},
name
=
'
account_
register'
),
)
if
settings
.
FEATURES
.
get
(
'ENABLE_NEW_DASHBOARD'
):
...
...
lms/djangoapps/student_profile/test/test_views.py
View file @
9da81ada
...
...
@@ -35,7 +35,7 @@ class StudentProfileViewTest(UrlResetMixin, TestCase):
@patch.dict
(
settings
.
FEATURES
,
{
'ENABLE_NEW_DASHBOARD'
:
True
})
def
setUp
(
self
):
super
(
StudentProfileViewTest
,
self
)
.
setUp
()
super
(
StudentProfileViewTest
,
self
)
.
setUp
(
"student_profile.urls"
)
# Create/activate a new account
activation_key
=
account_api
.
create_account
(
self
.
USERNAME
,
self
.
PASSWORD
,
self
.
EMAIL
)
...
...
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