from __future__ import absolute_import
from django.contrib.auth.backends import RemoteUserBackend
from .compat import from_wsgi_safe_string


class WebtestUserBackend(RemoteUserBackend):
    """ Auth backend for django-webtest auth system """

    def authenticate(self, request, django_webtest_user):
        return super(WebtestUserBackend, self).authenticate(
            request, django_webtest_user)

    def clean_username(self, username):
        return from_wsgi_safe_string(username)

from __future__ import absolute_import
from django.utils.version import get_complete_version
from django.contrib.auth.backends import RemoteUserBackend
from .compat import from_wsgi_safe_string

class WebtestUserBackend(RemoteUserBackend):
    """ Auth backend for django-webtest auth system """

    if get_complete_version() >= (1, 11):
        def authenticate(self, request, django_webtest_user):
            return super(WebtestUserBackend, self).authenticate(
                request, django_webtest_user)
    else:
        def authenticate(self, django_webtest_user):
            return super(WebtestUserBackend, self).authenticate(
                django_webtest_user)

    def clean_username(self, username):
        return from_wsgi_safe_string(username)

Define WebtestUserBackend.authenticate based on Django version
Define WebtestUserBackend.authenticate based on Django version

This is required because the signature of RemoteUserBackend.authenticate
has changed in Django 1.11.

  from __future__ import absolute_import
+ from django.utils.version import get_complete_version
  from django.contrib.auth.backends import RemoteUserBackend
  from .compat import from_wsgi_safe_string
- 
  
  class WebtestUserBackend(RemoteUserBackend):
      """ Auth backend for django-webtest auth system """
  
+     if get_complete_version() >= (1, 11):
-     def authenticate(self, request, django_webtest_user):
+         def authenticate(self, request, django_webtest_user):
-         return super(WebtestUserBackend, self).authenticate(
+             return super(WebtestUserBackend, self).authenticate(
-             request, django_webtest_user)
+                 request, django_webtest_user)
+     else:
+         def authenticate(self, django_webtest_user):
+             return super(WebtestUserBackend, self).authenticate(
+                 django_webtest_user)
  
      def clean_username(self, username):
          return from_wsgi_safe_string(username)
  
Define WebtestUserBackend.authenticate based on Django version
## Code Before:
from __future__ import absolute_import
from django.contrib.auth.backends import RemoteUserBackend
from .compat import from_wsgi_safe_string


class WebtestUserBackend(RemoteUserBackend):
    """ Auth backend for django-webtest auth system """

    def authenticate(self, request, django_webtest_user):
        return super(WebtestUserBackend, self).authenticate(
            request, django_webtest_user)

    def clean_username(self, username):
        return from_wsgi_safe_string(username)

## Instruction:
Define WebtestUserBackend.authenticate based on Django version
## Code After:
from __future__ import absolute_import
from django.utils.version import get_complete_version
from django.contrib.auth.backends import RemoteUserBackend
from .compat import from_wsgi_safe_string

class WebtestUserBackend(RemoteUserBackend):
    """ Auth backend for django-webtest auth system """

    if get_complete_version() >= (1, 11):
        def authenticate(self, request, django_webtest_user):
            return super(WebtestUserBackend, self).authenticate(
                request, django_webtest_user)
    else:
        def authenticate(self, django_webtest_user):
            return super(WebtestUserBackend, self).authenticate(
                django_webtest_user)

    def clean_username(self, username):
        return from_wsgi_safe_string(username)
