[Python-modules-commits] [python-django-otp] 01/08: Import python-django-otp_0.3.13.orig.tar.gz

Michael Fladischer fladi at moszumanska.debian.org
Fri May 12 19:58:55 UTC 2017


This is an automated email from the git hooks/post-receive script.

fladi pushed a commit to branch master
in repository python-django-otp.

commit 005240302b4cd9ccd4ce1a68918268b4c6b01906
Author: Michael Fladischer <FladischerMichael at fladi.at>
Date:   Fri May 12 21:46:34 2017 +0200

    Import python-django-otp_0.3.13.orig.tar.gz
---
 CHANGES                               | 14 ++++++-
 PKG-INFO                              |  2 +-
 django_otp.egg-info/PKG-INFO          |  2 +-
 django_otp/middleware.py              | 10 ++++-
 django_otp/plugins/otp_email/tests.py | 11 +++--
 django_otp/plugins/otp_hotp/admin.py  |  6 ++-
 django_otp/plugins/otp_totp/admin.py  |  6 ++-
 django_otp/tests.py                   | 76 +++++++++++++++++++++++++++++++----
 docs/source/conf.py                   |  2 +-
 setup.py                              |  2 +-
 10 files changed, 112 insertions(+), 19 deletions(-)

diff --git a/CHANGES b/CHANGES
index 315f432..00bdbde 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,8 +1,20 @@
+v0.3.13 - April 11, 2017 - Pickle compatibility
+-----------------------------------------------
+
+- Allow verified users to be pickled.
+
+
+v0.3.12 - April 2, 2017 - Forward compatibility
+-----------------------------------------------
+
+- Minor fixes for Django 1.11 and 2.0.
+
+
 v0.3.11 - March 8, 2017 - Built-in QR Code support
 --------------------------------------------------
 
 - `#20`_: Generate HOTP and TOTP otpauth URLs and corresponding QR Codes. To
-  enable this feature, install ``django_otp[qrcode]`` or just install the
+  enable this feature, install ``django-otp[qrcode]`` or just install the
   `qrcode`_ package.
 
 - Support for Python 2.6 and Django 1.4 were dropped in this version (long
diff --git a/PKG-INFO b/PKG-INFO
index a86bb0e..4f350ca 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: django-otp
-Version: 0.3.11
+Version: 0.3.13
 Summary: A pluggable framework for adding two-factor authentication to Django using one-time passwords.
 Home-page: https://bitbucket.org/psagers/django-otp
 Author: Peter Sagerson
diff --git a/django_otp.egg-info/PKG-INFO b/django_otp.egg-info/PKG-INFO
index a86bb0e..4f350ca 100644
--- a/django_otp.egg-info/PKG-INFO
+++ b/django_otp.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: django-otp
-Version: 0.3.11
+Version: 0.3.13
 Summary: A pluggable framework for adding two-factor authentication to Django using one-time passwords.
 Home-page: https://bitbucket.org/psagers/django-otp
 Author: Peter Sagerson
diff --git a/django_otp/middleware.py b/django_otp/middleware.py
index e72301d..30609fd 100644
--- a/django_otp/middleware.py
+++ b/django_otp/middleware.py
@@ -1,5 +1,7 @@
 from __future__ import absolute_import, division, print_function, unicode_literals
 
+import functools
+
 try:
     from django.utils.deprecation import MiddlewareMixin
 except ImportError:
@@ -11,6 +13,10 @@ from django_otp import DEVICE_ID_SESSION_KEY, _user_is_authenticated
 from django_otp.models import Device
 
 
+def is_verified(user):
+    return user.otp_device is not None
+
+
 class OTPMiddleware(MiddlewareMixin):
     """
     This must be installed after
@@ -25,7 +31,7 @@ class OTPMiddleware(MiddlewareMixin):
     def process_request(self, request):
         user = getattr(request, 'user', None)
         if user is not None:
-            request.user = SimpleLazyObject(lambda: self._verify_user(request, user))
+            request.user = SimpleLazyObject(functools.partial(self._verify_user, request, user))
 
         return None
 
@@ -34,7 +40,7 @@ class OTPMiddleware(MiddlewareMixin):
         Sets OTP-related fields on an authenticated user.
         """
         user.otp_device = None
-        user.is_verified = lambda: user.otp_device is not None
+        user.is_verified = functools.partial(is_verified, user)
 
         if _user_is_authenticated(user):
             device_id = request.session.get(DEVICE_ID_SESSION_KEY)
diff --git a/django_otp/plugins/otp_email/tests.py b/django_otp/plugins/otp_email/tests.py
index e984218..eecb73e 100644
--- a/django_otp/plugins/otp_email/tests.py
+++ b/django_otp/plugins/otp_email/tests.py
@@ -1,7 +1,8 @@
 from __future__ import absolute_import, division, print_function, unicode_literals
 
-from django.db import IntegrityError
 from django.core import mail
+from django.db import IntegrityError
+from django.test.utils import override_settings
 
 from django_otp.forms import OTPAuthenticationForm
 from django_otp.tests import TestCase
@@ -17,9 +18,13 @@ class AuthFormTest(TestCase):
         else:
             alice.emaildevice_set.create()
 
-        if not hasattr(alice, 'email'):
+        if hasattr(alice, 'email'):
+            alice.email = 'alice at example.com'
+            alice.save()
+        else:
             self.skipTest("User model has no email.")
 
+    @override_settings(OTP_EMAIL_SENDER='test at example.com')
     def test_email_interaction(self):
         data = {
             'username': 'alice',
@@ -30,7 +35,7 @@ class AuthFormTest(TestCase):
         }
         form = OTPAuthenticationForm(None, data)
 
-        self.assertTrue(not form.is_valid())
+        self.assertFalse(form.is_valid())
         alice = form.get_user()
         self.assertTrue(alice.get_username() == 'alice')
         self.assertTrue(alice.otp_device is None)
diff --git a/django_otp/plugins/otp_hotp/admin.py b/django_otp/plugins/otp_hotp/admin.py
index 54acab2..f93ac0d 100644
--- a/django_otp/plugins/otp_hotp/admin.py
+++ b/django_otp/plugins/otp_hotp/admin.py
@@ -3,11 +3,15 @@ from __future__ import absolute_import, division, print_function, unicode_litera
 from django.conf.urls import url
 from django.contrib import admin
 from django.contrib.admin.sites import AlreadyRegistered
-from django.core.urlresolvers import reverse
 from django.http import HttpResponse
 from django.template.response import TemplateResponse
 from django.utils.html import format_html
 
+try:
+    from django.urls import reverse
+except ImportError:
+    from django.core.urlresolvers import reverse
+
 from .models import HOTPDevice
 
 
diff --git a/django_otp/plugins/otp_totp/admin.py b/django_otp/plugins/otp_totp/admin.py
index 53d547d..9c5dbf7 100644
--- a/django_otp/plugins/otp_totp/admin.py
+++ b/django_otp/plugins/otp_totp/admin.py
@@ -3,11 +3,15 @@ from __future__ import absolute_import, division, print_function, unicode_litera
 from django.conf.urls import url
 from django.contrib import admin
 from django.contrib.admin.sites import AlreadyRegistered
-from django.core.urlresolvers import reverse
 from django.http import HttpResponse
 from django.template.response import TemplateResponse
 from django.utils.html import format_html
 
+try:
+    from django.urls import reverse
+except ImportError:
+    from django.core.urlresolvers import reverse
+
 from .models import TOTPDevice
 
 
diff --git a/django_otp/tests.py b/django_otp/tests.py
index 3ecd8a1..0cdd515 100644
--- a/django_otp/tests.py
+++ b/django_otp/tests.py
@@ -1,12 +1,16 @@
 from __future__ import absolute_import, division, print_function, unicode_literals
 
+import pickle
 from doctest import DocTestSuite
 
 import django
+from django.db import IntegrityError
 import django.test
 
 from django_otp import oath
 from django_otp import util
+from django_otp import DEVICE_ID_SESSION_KEY
+from django_otp.middleware import OTPMiddleware
 
 if django.VERSION < (1, 7):
     from django.utils import unittest
@@ -45,13 +49,71 @@ class TestCase(django.test.TestCase):
 
     def create_user(self, username, password):
         """
-        Try to create a user, honoring the custom user model, if any. This may
-        raise an exception if the user model is too exotic for our purposes.
+        Try to create a user, honoring the custom user model, if any.
+
+        This may raise an exception if the user model is too exotic for our
+        purposes.
         """
+        return self.User.objects.create_user(username, password=password)
+
+
+class OTPMiddlewareTestCase(TestCase):
+    def setUp(self):
+        self.factory = django.test.RequestFactory()
         try:
-            user = self.User.objects.create_user(username, password=password)
-        except TypeError:
-            # Django < 1.4
-            user = self.User.objects.create_user(username, email='user at example.com', password=password)
+            self.alice = self.create_user('alice', 'password')
+            self.bob = self.create_user('bob', 'password')
+        except IntegrityError:
+            self.skipTest("Unable to create a test user.")
+        else:
+            for user in [self.alice, self.bob]:
+                device = user.staticdevice_set.create()
+                device.token_set.create(token=user.get_username())
+
+        self.middleware = OTPMiddleware()
+
+    def test_verified(self):
+        request = self.factory.get('/')
+        request.user = self.alice
+        device = self.alice.staticdevice_set.get()
+        request.session = {
+            DEVICE_ID_SESSION_KEY: device.persistent_id
+        }
+
+        self.middleware.process_request(request)
+
+        self.assertTrue(request.user.is_verified())
+
+    def test_unverified(self):
+        request = self.factory.get('/')
+        request.user = self.alice
+        request.session = {}
+
+        self.middleware.process_request(request)
+
+        self.assertFalse(request.user.is_verified())
+
+    def test_wrong_user(self):
+        request = self.factory.get('/')
+        request.user = self.alice
+        device = self.bob.staticdevice_set.get()
+        request.session = {
+            DEVICE_ID_SESSION_KEY: device.persistent_id
+        }
+
+        self.middleware.process_request(request)
+
+        self.assertFalse(request.user.is_verified())
+
+    def test_pickling(self):
+        request = self.factory.get('/')
+        request.user = self.alice
+        device = self.alice.staticdevice_set.get()
+        request.session = {
+            DEVICE_ID_SESSION_KEY: device.persistent_id
+        }
+
+        self.middleware.process_request(request)
 
-        return user
+        # Should not raise an exception.
+        pickle.dumps(request.user)
diff --git a/docs/source/conf.py b/docs/source/conf.py
index d152d2c..b7504d0 100644
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -75,7 +75,7 @@ copyright = u'2012, Peter Sagerson'
 # The short X.Y version.
 version = '0.3'
 # The full version, including alpha/beta/rc tags.
-release = '0.3.11'
+release = '0.3.13'
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
diff --git a/setup.py b/setup.py
index 9fe8be2..9f949c2 100755
--- a/setup.py
+++ b/setup.py
@@ -5,7 +5,7 @@ from setuptools import setup, find_packages
 
 setup(
     name='django-otp',
-    version='0.3.11',
+    version='0.3.13',
     description='A pluggable framework for adding two-factor authentication to Django using one-time passwords.',
     long_description=open('README.rst').read(),
     author='Peter Sagerson',

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-django-otp.git



More information about the Python-modules-commits mailing list