Skip to content
Tags

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”

or

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
        UserenaSignup.objects.check_permissions()

That’s it (so far at least).

About these ads

From → django, python

Leave a Comment

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 1,300 other followers

%d bloggers like this: