Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
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
django-rest-framework
Commits
fdf9a267
Commit
fdf9a267
authored
May 31, 2013
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unused test helper module
parent
23332069
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
66 deletions
+0
-66
rest_framework/tests/test_testcases.py
+0
-66
No files found.
rest_framework/tests/test_testcases.py
deleted
100644 → 0
View file @
23332069
# http://djangosnippets.org/snippets/1011/
from
__future__
import
unicode_literals
from
django.conf
import
settings
from
django.core.management
import
call_command
from
django.db.models
import
loading
from
django.test
import
TestCase
NO_SETTING
=
(
'!'
,
None
)
class
TestSettingsManager
(
object
):
"""
A class which can modify some Django settings temporarily for a
test and then revert them to their original values later.
Automatically handles resyncing the DB if INSTALLED_APPS is
modified.
"""
def
__init__
(
self
):
self
.
_original_settings
=
{}
def
set
(
self
,
**
kwargs
):
for
k
,
v
in
kwargs
.
iteritems
():
self
.
_original_settings
.
setdefault
(
k
,
getattr
(
settings
,
k
,
NO_SETTING
))
setattr
(
settings
,
k
,
v
)
if
'INSTALLED_APPS'
in
kwargs
:
self
.
syncdb
()
def
syncdb
(
self
):
loading
.
cache
.
loaded
=
False
call_command
(
'syncdb'
,
verbosity
=
0
)
def
revert
(
self
):
for
k
,
v
in
self
.
_original_settings
.
iteritems
():
if
v
==
NO_SETTING
:
delattr
(
settings
,
k
)
else
:
setattr
(
settings
,
k
,
v
)
if
'INSTALLED_APPS'
in
self
.
_original_settings
:
self
.
syncdb
()
self
.
_original_settings
=
{}
class
SettingsTestCase
(
TestCase
):
"""
A subclass of the Django TestCase with a settings_manager
attribute which is an instance of TestSettingsManager.
Comes with a tearDown() method that calls
self.settings_manager.revert().
"""
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
SettingsTestCase
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
self
.
settings_manager
=
TestSettingsManager
()
def
tearDown
(
self
):
self
.
settings_manager
.
revert
()
class
TestModelsTestCase
(
SettingsTestCase
):
def
setUp
(
self
,
*
args
,
**
kwargs
):
installed_apps
=
tuple
(
settings
.
INSTALLED_APPS
)
+
(
'rest_framework.tests'
,)
self
.
settings_manager
.
set
(
INSTALLED_APPS
=
installed_apps
)
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