Skip to content

Commit 018816a

Browse files
Dropped support for Python < 2.7 and Django < 1.8
These versions are not tested anymore.
1 parent a43bd5d commit 018816a

File tree

8 files changed

+36
-151
lines changed

8 files changed

+36
-151
lines changed

CHANGES

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
Changes
22
=======
3+
4+
UNRELEASED
5+
----------
6+
- Dropped compatibility for Python < 2.7 and Django < 1.8.
7+
38
0.16.10 (2017-10-02)
49
-------------------
510
- Bugfixes and internal refactorings.

djangosaml2/backends.py

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,12 @@
1818
from django.conf import settings
1919
from django.contrib import auth
2020
from django.contrib.auth.backends import ModelBackend
21-
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned, \
22-
ImproperlyConfigured
21+
from django.core.exceptions import (
22+
MultipleObjectsReturned, ImproperlyConfigured,
23+
)
2324

2425
from djangosaml2.signals import pre_user_save
2526

26-
try:
27-
from django.contrib.auth.models import SiteProfileNotAvailable
28-
except ImportError:
29-
class SiteProfileNotAvailable(Exception):
30-
pass
31-
3227

3328
logger = logging.getLogger('djangosaml2')
3429

@@ -211,24 +206,12 @@ def update_user(self, user, attributes, attribute_mapping,
211206
212207
By default it uses a mapping defined in the settings constant
213208
SAML_ATTRIBUTE_MAPPING. For each attribute, if the user object has
214-
that field defined it will be set, otherwise it will try to set
215-
it in the profile object.
209+
that field defined it will be set.
216210
"""
217211
if not attribute_mapping:
218212
return user
219213

220-
try:
221-
profile = user.get_profile()
222-
except ObjectDoesNotExist:
223-
profile = None
224-
except SiteProfileNotAvailable:
225-
profile = None
226-
# Django 1.5 custom model assumed
227-
except AttributeError:
228-
profile = user
229-
230214
user_modified = False
231-
profile_modified = False
232215
for saml_attr, django_attrs in attribute_mapping.items():
233216
attr_value_list = attributes.get(saml_attr)
234217
if not attr_value_list:
@@ -244,10 +227,6 @@ def update_user(self, user, attributes, attribute_mapping,
244227

245228
user_modified = user_modified or modified
246229

247-
elif profile is not None and hasattr(profile, attr):
248-
modified = self._set_attribute(profile, attr, attr_value_list[0])
249-
profile_modified = profile_modified or modified
250-
251230
logger.debug('Sending the pre_save signal')
252231
signal_modified = any(
253232
[response for receiver, response
@@ -260,10 +239,6 @@ def update_user(self, user, attributes, attribute_mapping,
260239
if user_modified or signal_modified or force_save:
261240
user.save()
262241

263-
if (profile is not None
264-
and (profile_modified or signal_modified or force_save)):
265-
profile.save()
266-
267242
return user
268243

269244
def _set_attribute(self, obj, attr, value):

djangosaml2/cache.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
# limitations under the License.
1515

1616
from saml2.cache import Cache
17-
from saml2.ident import code, decode
1817

1918

2019
class DjangoSessionCacheAdapter(dict):

djangosaml2/tests/__init__.py

Lines changed: 10 additions & 74 deletions
Large diffs are not rendered by default.

djangosaml2/urls.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
import django
1716
from django.conf.urls import url
1817
from djangosaml2 import views
1918

tests/settings.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,7 @@
119119
STATIC_URL = '/static/'
120120

121121

122-
AUTH_PROFILE_MODULE = 'testprofiles.TestProfile'
123-
124-
import django
125-
if django.VERSION >= (1, 7):
126-
AUTH_USER_MODEL = 'testprofiles.TestUser'
122+
AUTH_USER_MODEL = 'testprofiles.TestUser'
127123

128124
# A sample logging configuration. The only tangible logging
129125
# performed by this configuration is to send an email to

tests/testprofiles/models.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,20 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
import django
16+
from django.contrib.auth.models import AbstractUser
1717
from django.db import models
1818

19-
if django.VERSION < (1, 7):
20-
class TestProfile(models.Model):
21-
user = models.OneToOneField('auth.User')
22-
age = models.CharField(max_length=100, blank=True)
2319

24-
def process_first_name(self, first_name):
25-
self.first_name = first_name[0]
26-
else:
27-
from django.contrib.auth.models import AbstractUser
28-
class TestUser(AbstractUser):
29-
age = models.CharField(max_length=100, blank=True)
30-
def process_first_name(self, first_name):
31-
self.first_name = first_name[0]
20+
class TestUser(AbstractUser):
21+
age = models.CharField(max_length=100, blank=True)
3222

33-
class StandaloneUserModel(models.Model):
34-
"""
35-
Does not inherit from Django's base abstract user and does not define a
36-
USERNAME_FIELD.
37-
"""
38-
username = models.CharField(max_length=30, unique=True)
23+
def process_first_name(self, first_name):
24+
self.first_name = first_name[0]
25+
26+
27+
class StandaloneUserModel(models.Model):
28+
"""
29+
Does not inherit from Django's base abstract user and does not define a
30+
USERNAME_FIELD.
31+
"""
32+
username = models.CharField(max_length=30, unique=True)

tests/testprofiles/tests.py

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,13 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
import django
18-
19-
try:
20-
from django.contrib.auth import get_user_model
21-
except ImportError:
22-
from django.contrib.auth.models import User
23-
else:
24-
User = get_user_model()
25-
17+
from django.contrib.auth import get_user_model
2618
from django.contrib.auth.models import User as DjangoUserModel
27-
2819
from django.test import TestCase, override_settings
2920

3021
from djangosaml2.backends import Saml2Backend
3122

32-
if django.VERSION < (1,7):
33-
from testprofiles.models import TestProfile
23+
User = get_user_model()
3424

3525

3626
class Saml2BackendTests(TestCase):
@@ -57,19 +47,10 @@ def test_update_user(self):
5747
self.assertEqual(user.first_name, 'John')
5848
self.assertEqual(user.last_name, 'Doe')
5949

60-
# now we create a user profile and link it to the user
61-
if django.VERSION < (1, 7):
62-
profile = TestProfile.objects.create(user=user)
63-
self.assertNotEquals(profile, None)
64-
6550
attribute_mapping['saml_age'] = ('age', )
6651
attributes['saml_age'] = ('22', )
6752
backend.update_user(user, attributes, attribute_mapping)
68-
69-
if django.VERSION < (1, 7):
70-
self.assertEqual(user.get_profile().age, '22')
71-
else:
72-
self.assertEqual(user.age, '22')
53+
self.assertEqual(user.age, '22')
7354

7455
def test_update_user_callable_attributes(self):
7556
user = User.objects.create(username='john')

0 commit comments

Comments
 (0)