REMOTE_USER without effect

Issue #19 new
Laurent Payot
created an issue

When I put

extra_environ = {'REMOTE_USER': 'my_superuser'}

in my TestCase class nothing happens. I still have to add the user='my_superuser' keyword in every get() or follow() I use and it's such a drag when I have to test restricted access pages.

I'm using Ubuntu 13.04 64 bit and Python 3.3.1 with the last commit of django, the last commit of webtest and the last commit of django-webtest.

Comments (5)

  1. Mikhail Korobov repo owner

    django-webtest doesn't use REMOTE_USER wsgi environment variable. What is exactly the issue - is it RemoteUserMiddleware that doesn't work with django-webtest?

    I think setting WEBTEST_USER variable should work, but it is an implementation detail, not a documented feature.

  2. Laurent Payot reporter

    Great, it's working with WEBTEST_USER. If you look at the webtest documentation here you'll see that webtest use the REMOTE_USER environment variable to simulate authentication. It would be nice to have the same name with django-webtest, and to document it because this is so useful.

  3. Laurent Payot reporter

    And to answer your question I use it like this in my tests:

    class MediaCRUDSuperuserTestCase(WebTest):
        """Client tests when user is logged as superuser."""
        csrf_checks = False
        extra_environ = {'HTTP_USER_AGENT': 'Mozilla/5.0',
                         'HTTP_ACCEPT_LANGUAGE': 'en',
                         # laurent is superuser
                         'WEBTEST_USER': 'laurent',
        def setUpClass(cls):
            # doing setup stuff here (superuser and media creation etc...)
        def test001_media_read_superuser_ok(self):
            # media --> 301 --> book
            response ='www:media-detail', kwargs={'pk': "1"})).follow()
            self.assertEqual(response.context['media'].title, "Python for dummies")

    Am I using it in a bad way ? I have to say I'm not using standard 'django.contrib.auth.backends.RemoteUserBackend' authentication backend so this might be the source of the different behaviour. It may also be the cause of the issue #20.

    It would be great if django-webtest was authentication-backend independant, but I understand it can be tricky to implement.

  4. Mikhail Korobov repo owner

    No, you're not using it in a bad way. Now I see why this can be confusing.

    django-webtest should be auth-backend independent. It used to rely on RemoteUserBackend but I changed it to use a custom backend specifically to allow RemoteUserBackend in user code a long time ago.

  5. Laurent Payot reporter

    I see. If possible it wouldn't hurt if django-webtest was more webtest-compatible by allowing the use of the REMOTE_USER environment variable the way they do in webtest. Anyway I'm happy using WEBTEST_USER for now. Thanks!

  6. Log in to comment