/usr/lib/python2.7/dist-packages/guardian/testapp/tests/conf.py is in python-django-guardian 1.2.4+git20141127-0.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | from __future__ import unicode_literals
import os
import django
from guardian.compat import unittest
from guardian.utils import abspath
from django.conf import settings
from django.conf import UserSettingsHolder
from django.utils.functional import wraps
THIS = abspath(os.path.dirname(__file__))
TEST_TEMPLATES_DIR = abspath(THIS, 'templates')
TEST_SETTINGS = dict(
TEMPLATE_DIRS=[TEST_TEMPLATES_DIR],
)
def skipUnlessTestApp(obj):
app = 'guardian.testapp'
return unittest.skipUnless(app in settings.INSTALLED_APPS,
'app %r must be installed to run this test' % app)(obj)
def skipUnlessSupportsCustomUser(obj):
# XXX: Following fixes problem with Python 2.6 and Django 1.2
gte15 = django.VERSION >= (1, 5)
if not gte15:
return lambda *args, **kwargs: None
# XXX: End of the workaround
return unittest.skipUnless(django.VERSION >= (1, 5), 'Must have Django 1.5 or greater')(obj)
class TestDataMixin(object):
def setUp(self):
super(TestDataMixin, self).setUp()
from django.contrib.auth.models import Group
try:
from django.contrib.auth import get_user_model
User = get_user_model()
except ImportError:
from django.contrib.auth.models import User
Group.objects.create(pk=1, name='admins')
jack_group = Group.objects.create(pk=2, name='jackGroup')
User.objects.get_or_create(pk=settings.ANONYMOUS_USER_ID)
jack = User.objects.create(pk=1, username='jack', is_active=True,
is_superuser=False, is_staff=False)
jack.groups.add(jack_group)
class override_settings(object):
"""
Acts as either a decorator, or a context manager. If it's a decorator it
takes a function and returns a wrapped function. If it's a contextmanager
it's used with the ``with`` statement. In either event entering/exiting
are called before and after, respectively, the function/block is executed.
"""
def __init__(self, **kwargs):
self.options = kwargs
self.wrapped = settings._wrapped
def __enter__(self):
self.enable()
def __exit__(self, exc_type, exc_value, traceback):
self.disable()
def __call__(self, test_func):
from django.test import TransactionTestCase
if isinstance(test_func, type) and issubclass(test_func, TransactionTestCase):
original_pre_setup = test_func._pre_setup
original_post_teardown = test_func._post_teardown
def _pre_setup(innerself):
self.enable()
original_pre_setup(innerself)
def _post_teardown(innerself):
original_post_teardown(innerself)
self.disable()
test_func._pre_setup = _pre_setup
test_func._post_teardown = _post_teardown
return test_func
else:
@wraps(test_func)
def inner(*args, **kwargs):
with self:
return test_func(*args, **kwargs)
return inner
def enable(self):
override = UserSettingsHolder(settings._wrapped)
for key, new_value in self.options.items():
setattr(override, key, new_value)
settings._wrapped = override
def disable(self):
settings._wrapped = self.wrapped
|