2014-03-07 01:39:44 +04:00
|
|
|
from contextlib import contextmanager
|
2014-08-19 20:06:55 +04:00
|
|
|
from django.utils import six
|
2014-03-07 01:39:44 +04:00
|
|
|
from rest_framework.settings import api_settings
|
|
|
|
|
|
|
|
|
|
|
|
@contextmanager
|
|
|
|
def temporary_setting(setting, value, module=None):
|
|
|
|
"""
|
|
|
|
Temporarily change value of setting for test.
|
|
|
|
|
|
|
|
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:
|
2014-03-07 03:51:02 +04:00
|
|
|
six.moves.reload_module(module)
|
2014-03-07 01:39:44 +04:00
|
|
|
|
|
|
|
yield
|
|
|
|
|
|
|
|
setattr(api_settings, setting, original_value)
|
|
|
|
|
|
|
|
if module is not None:
|
2014-03-07 03:51:02 +04:00
|
|
|
six.moves.reload_module(module)
|