Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Tests fail when launched via "manage.py test" #10

Closed
Unode opened this Issue · 3 comments

2 participants

@Unode

After adding django_rules to INSTALLED_APPS and "django_rules.backends.ObjectPermissionBackend" to AUTHENTICATION_BACKENDS, launching tests via manage.py cause several failures.

Some of these errors can be corrected by adding "django_rules.tests" to INSTALLED_APPS but three different errors remain.

Running tests via the provided runtests.py script works fine but a lot less tests are executed.

The errors are:

======================================================================
ERROR: test_has_perm (django.contrib.auth.tests.auth_backends.NoAnonymousUserBackendTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/virtualenv/lib/python2.6/site-packages/django/contrib/auth/tests/auth_backends.py", line 265, in test_has_perm
    self.assertEqual(self.user1.has_perm('perm', TestObj()), False)
  File "/virtualenv/lib/python2.6/site-packages/django/contrib/auth/models.py", line 466, in has_perm
    return _user_has_perm(self, perm, obj=obj)
  File "/virtualenv/lib/python2.6/site-packages/django/contrib/auth/models.py", line 181, in _user_has_perm
    backend.has_perm(user, perm, obj)):
  File "/virtualenv/lib/python2.6/site-packages/django_rules/backends.py", line 36, in has_perm
    user_obj = User.objects.get(pk=settings.ANONYMOUS_USER_ID)
  File "/virtualenv/lib/python2.6/site-packages/django/db/models/manager.py", line 132, in get
    return self.get_query_set().get(*args, **kwargs)
  File "/virtualenv/lib/python2.6/site-packages/django/db/models/query.py", line 349, in get
    % self.model._meta.object_name)
DoesNotExist: User matching query does not exist.

======================================================================
ERROR: test_has_perms (django.contrib.auth.tests.auth_backends.NoAnonymousUserBackendTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/virtualenv/lib/python2.6/site-packages/django/contrib/auth/tests/auth_backends.py", line 269, in test_has_perms
    self.assertEqual(self.user1.has_perms(['anon'], TestObj()), False)
  File "/virtualenv/lib/python2.6/site-packages/django/contrib/auth/models.py", line 470, in has_perms
    if not self.has_perm(perm, obj):
  File "/virtualenv/lib/python2.6/site-packages/django/contrib/auth/models.py", line 466, in has_perm
    return _user_has_perm(self, perm, obj=obj)
  File "/virtualenv/lib/python2.6/site-packages/django/contrib/auth/models.py", line 181, in _user_has_perm
    backend.has_perm(user, perm, obj)):
  File "/virtualenv/lib/python2.6/site-packages/django_rules/backends.py", line 36, in has_perm
    user_obj = User.objects.get(pk=settings.ANONYMOUS_USER_ID)
  File "/virtualenv/lib/python2.6/site-packages/django/db/models/manager.py", line 132, in get
    return self.get_query_set().get(*args, **kwargs)
  File "/virtualenv/lib/python2.6/site-packages/django/db/models/query.py", line 349, in get
    % self.model._meta.object_name)
DoesNotExist: User matching query does not exist.

======================================================================
ERROR: test_has_perm (django.contrib.auth.tests.auth_backends.NoInActiveUserBackendTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/virtualenv/lib/python2.6/site-packages/django/contrib/auth/tests/auth_backends.py", line 350, in test_has_perm
    self.assertEqual(self.user1.has_perm('perm', TestObj()), False)
  File "/virtualenv/lib/python2.6/site-packages/django/contrib/auth/models.py", line 324, in has_perm
    return _user_has_perm(self, perm, obj)
  File "/virtualenv/lib/python2.6/site-packages/django/contrib/auth/models.py", line 181, in _user_has_perm
    backend.has_perm(user, perm, obj)):
  File "/virtualenv/lib/python2.6/site-packages/django_rules/backends.py", line 68, in has_perm
    ctype = ContentType.objects.get_for_model(obj)
  File "/virtualenv/lib/python2.6/site-packages/django/contrib/contenttypes/models.py", line 24, in get_for_model
    opts = model._meta
AttributeError: 'TestObj' object has no attribute '_meta'

======================================================================
ERROR: test_has_perm (django.contrib.auth.tests.auth_backends.RowlevelBackendTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/virtualenv/lib/python2.6/site-packages/django/contrib/auth/tests/auth_backends.py", line 187, in test_has_perm
    self.assertEqual(self.user1.has_perm('perm', TestObj()), False)
  File "/virtualenv/lib/python2.6/site-packages/django/contrib/auth/models.py", line 324, in has_perm
    return _user_has_perm(self, perm, obj)
  File "/virtualenv/lib/python2.6/site-packages/django/contrib/auth/models.py", line 181, in _user_has_perm
    backend.has_perm(user, perm, obj)):
  File "/virtualenv/lib/python2.6/site-packages/django_rules/backends.py", line 68, in has_perm
    ctype = ContentType.objects.get_for_model(obj)
  File "/virtualenv/lib/python2.6/site-packages/django/contrib/contenttypes/models.py", line 24, in get_for_model
    opts = model._meta
AttributeError: 'TestObj' object has no attribute '_meta'

======================================================================
ERROR: test_central_authorizations_right_module_checked_within (django_rules.tests.test_core.BackendTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/virtualenv/lib/python2.6/site-packages/django_rules/tests/test_core.py", line 95, in test_central_authorizations_right_module_checked_within
    self.assertTrue(self.otherUser.has_perm('all_can_pass', self.obj))
  File "/virtualenv/lib/python2.6/site-packages/django/contrib/auth/models.py", line 324, in has_perm
    return _user_has_perm(self, perm, obj)
  File "/virtualenv/lib/python2.6/site-packages/django/contrib/auth/models.py", line 181, in _user_has_perm
    backend.has_perm(user, perm, obj)):
  File "/virtualenv/lib/python2.6/site-packages/django_rules/backends.py", line 47, in has_perm
    raise RulesError('Error importing central authorizations module %s: "%s"' % (module, e))
RulesError: Error importing central authorizations module utils: "No module named utils"

======================================================================
ERROR: test_central_authorizations_right_module_passes_over (django_rules.tests.test_core.BackendTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/virtualenv/lib/python2.6/site-packages/django_rules/tests/test_core.py", line 100, in test_central_authorizations_right_module_passes_over
    self.assertFalse(self.otherUser.has_perm('can_ship', self.obj))
  File "/virtualenv/lib/python2.6/site-packages/django/contrib/auth/models.py", line 324, in has_perm
    return _user_has_perm(self, perm, obj)
  File "/virtualenv/lib/python2.6/site-packages/django/contrib/auth/models.py", line 181, in _user_has_perm
    backend.has_perm(user, perm, obj)):
  File "/virtualenv/lib/python2.6/site-packages/django_rules/backends.py", line 47, in has_perm
    raise RulesError('Error importing central authorizations module %s: "%s"' % (module, e))
RulesError: Error importing central authorizations module utils: "No module named utils"

----------------------------------------------------------------------
@maraujop
Owner

Hi Renato,

I'm very sorry to have taken 6 months to answer this issue. All I can say is I rarely take so long.

There is no way to solve this issue at the moment as far as I know. If you need to run django-rules tests, you will have to use the custom test runner defined in runtests.py (33 tests on 2012/24/4)

I've opened an issue in Django to see what they think about this use case. You can see it here:
https://code.djangoproject.com/ticket/18199

All, I can say is that tests fail due to the fact that they don't get the test runner preparation work, which setups the testing environment.

Cheers,
Miguel

@maraujop maraujop closed this
@Unode

I've worked around the problem by using django-nose. The default NoseTestSuiteRunner doesn't pull django-rules into the tests.

@maraujop
Owner

Thanks for sharing the tip :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.