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
5b8163dc
Commit
5b8163dc
authored
Jun 12, 2013
by
Calen Pennington
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #92 from edx/fix/cale/url-tests
Fix tests that vary urls.py
parents
e641d2c6
6c24694a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
9 deletions
+55
-9
common/djangoapps/mitxmako/tests.py
+3
-6
common/djangoapps/util/testing.py
+34
-0
lms/djangoapps/django_comment_client/base/tests.py
+14
-1
lms/envs/test.py
+4
-2
No files found.
common/djangoapps/mitxmako/tests.py
View file @
5b8163dc
from
django.test
import
TestCase
from
django.test.utils
import
override_settings
from
django.core.urlresolvers
import
reverse
from
django.conf
import
settings
from
mitxmako.shortcuts
import
marketing_link
from
mock
import
patch
from
nose.plugins.skip
import
SkipTest
from
util.testing
import
UrlResetMixin
class
ShortcutsTests
(
TestCase
):
class
ShortcutsTests
(
UrlResetMixin
,
TestCase
):
"""
Test the mitxmako shortcuts file
"""
# TODO: fix this test. It is causing intermittent test failures on
# subsequent tests due to the way urls are loaded
raise
SkipTest
()
@override_settings
(
MKTG_URLS
=
{
'ROOT'
:
'dummy-root'
,
'ABOUT'
:
'/about-us'
})
@override_settings
(
MKTG_URL_LINK_MAP
=
{
'ABOUT'
:
'login'
})
def
test_marketing_link
(
self
):
...
...
common/djangoapps/util/testing.py
0 → 100644
View file @
5b8163dc
import
sys
from
django.conf
import
settings
from
django.core.urlresolvers
import
clear_url_caches
class
UrlResetMixin
(
object
):
"""Mixin to reset urls.py before and after a test
Django memoizes the function that reads the urls module (whatever module
urlconf names). The module itself is also stored by python in sys.modules.
To fully reload it, we need to reload the python module, and also clear django's
cache of the parsed urls.
However, the order in which we do this doesn't matter, because neither one will
get reloaded until the next request
Doing this is expensive, so it should only be added to tests that modify settings
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
])
clear_url_caches
()
def
setUp
(
self
):
"""Reset django default urlconf before tests and after tests"""
super
(
UrlResetMixin
,
self
)
.
setUp
()
self
.
_reset_urls
()
self
.
addCleanup
(
self
.
_reset_urls
)
lms/djangoapps/django_comment_client/base/tests.py
View file @
5b8163dc
import
logging
from
django.conf
import
settings
from
django.test.utils
import
override_settings
from
django.test.client
import
Client
from
django.contrib.auth.models
import
User
...
...
@@ -8,6 +9,7 @@ from xmodule.modulestore.tests.factories import CourseFactory
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
from
django.core.urlresolvers
import
reverse
from
django.core.management
import
call_command
from
util.testing
import
UrlResetMixin
from
courseware.tests.tests
import
TEST_DATA_MONGO_MODULESTORE
from
nose.tools
import
assert_true
,
assert_equal
...
...
@@ -18,8 +20,19 @@ log = logging.getLogger(__name__)
@override_settings
(
MODULESTORE
=
TEST_DATA_MONGO_MODULESTORE
)
@patch
(
'comment_client.utils.requests.request'
)
class
ViewsTestCase
(
ModuleStoreTestCase
):
class
ViewsTestCase
(
UrlResetMixin
,
ModuleStoreTestCase
):
def
setUp
(
self
):
# This feature affects the contents of urls.py, so we change
# it before the call to super.setUp() which reloads urls.py (because
# of the UrlResetMixin)
# This setting is cleaned up at the end of the test by @override_settings, which
# restores all of the old settings
settings
.
MITX_FEATURES
[
'ENABLE_DISCUSSION_SERVICE'
]
=
True
super
(
ViewsTestCase
,
self
)
.
setUp
()
# create a course
self
.
course
=
CourseFactory
.
create
(
org
=
'MITx'
,
course
=
'999'
,
display_name
=
'Robot Super Course'
)
...
...
lms/envs/test.py
View file @
5b8163dc
...
...
@@ -20,8 +20,10 @@ from path import path
# can test everything else :)
MITX_FEATURES
[
'DISABLE_START_DATES'
]
=
True
# Until we have discussion actually working in test mode, just turn it off
MITX_FEATURES
[
'ENABLE_DISCUSSION_SERVICE'
]
=
True
# Most tests don't use the discussion service, so we turn it off to speed them up.
# Tests that do can enable this flag, but must use the UrlResetMixin class to force urls.py
# to reload
MITX_FEATURES
[
'ENABLE_DISCUSSION_SERVICE'
]
=
False
MITX_FEATURES
[
'ENABLE_SERVICE_STATUS'
]
=
True
...
...
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