Skip to content

Running Django tests with Userena

January 24, 2013

I’m now running django-userena as the plugin for registering users, as it’s most complete and also allows for logging in with either the username or the email.

However, running tests can be a bit tricky, and I got errors like the following:

IntegrityError: insert or update on table “auth_group_permissions” violates foreign key constraint “auth_group_permissions_permission_id_fkey”


DoesNotExist: Permission matching query does not exist.

You only get these errors when you do tests that involve the user management and profiles, but when you are doing testing of forms and views, you want to use a webclient of some sort (I use django-webtest) and then you need to be logged in, and then pretty much all tests involve Userena. The trick was a combination of two tricks that took me a lot of digging, so here they are for the benefit of Django-kind: 1. Subclass from Userenas ProfileTestCase. 2. Run UserenaSignup.objects.check_permissions() during the setUp.

from userena.tests.profiles.test import ProfileTestCase
from userena.models import UserenaSignup

class ModelTests(ProfileTestCase):

    def setUp(self):
        # Setup userena permissions

That’s it (so far at least).


From → django, python

  1. It’s not helping. I am getting the same error even after doing this. 😦

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: