Quantcast
Channel: Planet Plone - Where Developers And Integrators Write
Viewing all articles
Browse latest Browse all 3535

Lennart Regebro: Running Django tests with Userena

$
0
0

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).


Filed under: django, python Tagged: userena

Viewing all articles
Browse latest Browse all 3535

Trending Articles