maraujop/django-rules — Issue #10: Tests fail when launched via "manage.py test"
Author: Unode
Created: 2011-10-18 16:24:57+00:00
State: open

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](https://github.com/maraujop/django-rules/blob/master/django_rules/tests/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"

----------------------------------------------------------------------