aboutsummaryrefslogtreecommitdiffstats
path: root/tests/utils.py
diff options
context:
space:
mode:
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):