ampad

Nachhaltige Software

Oblivious to the obvious

Raphael Kimmig, 28 Sep 2013

Just be­cause I've just spent half an hour tra­cing through WebTest and the Django au­th in­tern­als...

When you are us­ing WebTest to test cus­tom ad­min views and for some reas­on your user lo­gin doesn't seem to work - make sure to check for is_staff=True on the test user.

from django_webtest import WebTest
from django_dynamic_fixture import G

class CustomAdminTest(WebTest):
    def setUp(self):
        self.user = G(User, is_superuser=True, is_staff=True)

    def test_custom_admin_page(self):
        custom_page = self.app.get(reverse('admin:custom_page'), user=self.user)
        self.assertContains(custom_page, 'custom value')