aboutsummaryrefslogtreecommitdiffstats
path: root/tests/utils.py
diff options
context:
space:
mode:
authorTom Christie2015-02-06 14:35:06 +0000
committerTom Christie2015-02-06 14:35:06 +0000
commit3dff9a4fe2952cf632ca7f4cd9ecf4221059ca91 (patch)
tree0649d42b20b875e97cb551b987644b61e7860e84 /tests/utils.py
parentc06a82d0531f4cb290baacee196829c770913eaa (diff)
parent1f996128458570a909d13f15c3d739fb12111984 (diff)
downloaddjango-rest-framework-model-serializer-caching.tar.bz2
Resolve merge conflictmodel-serializer-caching
Diffstat (limited to 'tests/utils.py')
-rw-r--r--tests/utils.py35
1 files changed, 17 insertions, 18 deletions
diff --git a/tests/utils.py b/tests/utils.py
index 5e902ba9..b9034996 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -1,30 +1,29 @@
-from contextlib import contextmanager
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import NoReverseMatch
-from django.utils import six
-from rest_framework.settings import api_settings
-@contextmanager
-def temporary_setting(setting, value, module=None):
+class UsingURLPatterns(object):
"""
- Temporarily change value of setting for test.
+ Isolates URL patterns used during testing on the test class itself.
+ For example:
- Optionally reload given module, useful when module uses value of setting on
- import.
- """
- original_value = getattr(api_settings, setting)
- setattr(api_settings, setting, value)
-
- if module is not None:
- six.moves.reload_module(module)
+ class MyTestCase(UsingURLPatterns, TestCase):
+ urlpatterns = [
+ ...
+ ]
- yield
+ def test_something(self):
+ ...
+ """
+ urls = __name__
- setattr(api_settings, setting, original_value)
+ def setUp(self):
+ global urlpatterns
+ urlpatterns = self.urlpatterns
- if module is not None:
- six.moves.reload_module(module)
+ def tearDown(self):
+ global urlpatterns
+ urlpatterns = []
class MockObject(object):