diff --git a/.travis.yml b/.travis.yml index e646c2af..906e8cac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ addons: - postgresql-9.4-postgis-2.3 env: - - DJANGO='>=1.8.19,<1.9' + - DJANGO='>=1.8.19,<1.12' virtualenv: system_site_packages: true diff --git a/geokey/categories/tests/test_templatetags.py b/geokey/categories/tests/test_templatetags.py index 6b2d3707..b8dfbf3c 100644 --- a/geokey/categories/tests/test_templatetags.py +++ b/geokey/categories/tests/test_templatetags.py @@ -27,7 +27,7 @@ def test_only_fields(self): LookupFieldFactory(category=category) MultipleLookupFieldFactory(category=category) - all_fields = category.fields.all() + all_fields = category.fields.all().select_subclasses() type_names = [ 'Text', @@ -47,7 +47,7 @@ def test_only_fields(self): date_fields = filter_fields.only_fields( all_fields, - (', ').join(type_names) + ', '.join(type_names) ) self.assertEqual(len(date_fields), len(type_names)) for field in date_fields: @@ -66,7 +66,7 @@ def test_except_fields(self): LookupFieldFactory(category=category) MultipleLookupFieldFactory(category=category) - all_fields = category.fields.all() + all_fields = category.fields.all().select_subclasses() type_names = [ 'Text', @@ -79,13 +79,13 @@ def test_except_fields(self): ] for type_name in type_names: - date_fields = filter_fields.except_fields(all_fields, type_name) - self.assertEqual(len(date_fields), len(type_names) - 1) - for field in date_fields: + remaining_fields = filter_fields.except_fields(all_fields, type_name) + self.assertEqual(len(remaining_fields), len(type_names) - 1) + for field in remaining_fields: self.assertNotEqual(field.type_name, type_name) date_fields = filter_fields.except_fields( - all_fields, - (', ').join(type_names) + fields=all_fields, + type_names=', '.join(type_names) ) self.assertEqual(len(date_fields), 0) diff --git a/geokey/contributions/models.py b/geokey/contributions/models.py index be0cd2f9..fe90e7ce 100644 --- a/geokey/contributions/models.py +++ b/geokey/contributions/models.py @@ -280,7 +280,7 @@ def update_count(self): def create_search_index(self): search_index = [] - for field in self.category.fields.all(): + for field in self.category.fields.all().select_subclasses(): value = None if self.properties and field.key in self.properties.keys(): if field.fieldtype == 'TextField': diff --git a/geokey/contributions/tests/comments/test_views.py b/geokey/contributions/tests/comments/test_views.py index bbf8aa1e..21200d20 100644 --- a/geokey/contributions/tests/comments/test_views.py +++ b/geokey/contributions/tests/comments/test_views.py @@ -95,7 +95,7 @@ def test_create_reviewcomment_with_admin(self): self.assertEqual(ref.status, 'review') def test_create_reviewcomment_to_empty_obs_with_admin(self): - self.contribution.properties = None + self.contribution.properties = {} self.contribution.save() url = reverse('api:project_comments', kwargs={ diff --git a/geokey/contributions/tests/observations/test_models.py b/geokey/contributions/tests/observations/test_models.py index 5f613c35..4f20748a 100644 --- a/geokey/contributions/tests/observations/test_models.py +++ b/geokey/contributions/tests/observations/test_models.py @@ -206,7 +206,7 @@ def test_update_display_field_empty_properties(self): 'project': category.project, 'category': category, 'display_field': None, - 'properties': None + 'properties': {} }) observation.update_display_field() @@ -226,7 +226,7 @@ def test_update_display_field_no_display_field(self): 'project': category.project, 'category': category, 'display_field': None, - 'properties': None + 'properties': {} }) observation.update_display_field() @@ -275,7 +275,7 @@ def test_update_expiry_field_empty_properties(self): 'project': category.project, 'category': category, 'expiry_field': None, - 'properties': None + 'properties': {} }) observation.update_expiry_field() @@ -295,7 +295,7 @@ def test_update_expiry_field_no_expiry_field(self): 'project': category.project, 'category': category, 'expiry_field': None, - 'properties': None + 'properties': {} }) observation.update_expiry_field() diff --git a/geokey/contributions/tests/observations/test_views.py b/geokey/contributions/tests/observations/test_views.py index ca4c2546..7a052950 100644 --- a/geokey/contributions/tests/observations/test_views.py +++ b/geokey/contributions/tests/observations/test_views.py @@ -72,7 +72,7 @@ def test_approve_pending_with_admin(self): ) def test_approve_pending_with_admin_empty_properties(self): - self.observation.properties = None + self.observation.properties = {} self.observation.status = 'pending' self.observation.save() diff --git a/geokey/users/tests/test_admin_views.py b/geokey/users/tests/test_admin_views.py index 97f4e43d..88452230 100644 --- a/geokey/users/tests/test_admin_views.py +++ b/geokey/users/tests/test_admin_views.py @@ -16,6 +16,7 @@ from django.contrib.sites.shortcuts import get_current_site from django.contrib.messages import get_messages, WARNING from django.contrib.messages.storage.fallback import FallbackStorage +from django.utils import timezone from nose.tools import raises from oauth2_provider.models import AccessToken @@ -1547,9 +1548,9 @@ def setUp(self): self.user_no_contributions = UserFactory.create(**{'display_name': 'delete_test_no_contribs_user'}) self.user_with_contributions = UserFactory.create(**{'display_name': 'delete_test_contribs_user', 'email': 'veryspecific@email.address.hh', - 'date_joined': '2016-12-15 14:22:24.632764', - 'last_login': '2018-01-01 10:00:00.000001'}) - token_expiry = datetime.now() + timedelta(hours=1) + 'date_joined': '2016-12-15 14:22:24.632764Z', + 'last_login': '2018-01-01 10:00:00.000001Z'}) + token_expiry = timezone.now() + timedelta(hours=1) app = ApplicationFactory.create() self.access_token_contribs = AccessToken.objects.get_or_create(**{'user': self.user_with_contributions, 'expires': token_expiry, @@ -1628,9 +1629,9 @@ def test_user_details_removed(self): result_user = User.objects.get_or_create(id=user_id)[0] self.assertEqual(result_user.display_name[:12], 'Deleted user') self.assertEqual(result_user.email[-17:], 'deleteduser.email') - self.assertEqual(result_user.date_joined.strftime('%Y-%m-%d %H:%M:%S.%f'), '2018-04-01 11:11:11.111111') + self.assertEqual(result_user.date_joined.strftime('%Y-%m-%d %H:%M:%S'), '2018-04-01 11:11:11') self.assertAlmostEqual(datetime.strftime(result_user.last_login, '%Y-%m-%d %H:%M'), - datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M')) + datetime.strftime(timezone.now(), '%Y-%m-%d %H:%M')) self.assertFalse(result_user.is_active, msg="User should no longer be active.") access_tokens = AccessToken.objects.filter(user=result_user) diff --git a/geokey/users/views.py b/geokey/users/views.py index 369d7011..226df74d 100644 --- a/geokey/users/views.py +++ b/geokey/users/views.py @@ -1,8 +1,9 @@ """Views for users.""" from datetime import datetime from json import loads as json_loads - +from dateutil.tz import tzoffset from django.contrib.auth import logout +from django.utils import timezone from django.views.generic import TemplateView, CreateView from django.shortcuts import redirect from django.core.exceptions import ValidationError @@ -626,8 +627,8 @@ def post(self, request): random_password = ''.join(random.choice(ascii_lowercase) for _ in range(15)) user.email = random_numbers + '@' + 'deleteduser.email' user.display_name = 'Deleted user ' + random_numbers - user.date_joined = datetime.strptime('2018-04-01 11:11:11.111111', '%Y-%m-%d %H:%M:%S.%f') - user.last_login = datetime.now() + user.date_joined = datetime(2018, 4, 1, 11, 11, 11, tzinfo=tzoffset(None, 0)) + user.last_login = timezone.now() logout(request) user.is_active = False user.reset_password(password=random_password) diff --git a/requirements-dev.txt b/requirements-dev.txt index 7d2fc25f..7c420088 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,3 +1,3 @@ Django>=1.8.19,<1.9 -factory-boy==2.10.0 +factory-boy==2.11.1 django-debug-toolbar==1.7 diff --git a/requirements.txt b/requirements.txt index f60633ec..6c3e2f17 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,10 @@ -Django>=1.8.19,<1.9 +Django>=1.8.19,<1.12 django-aggregate-if==0.5 django-allauth==0.33.0 django-braces==1.11.0 django-crontab==0.7.1 django-hstore==1.4.2 -django-model-utils==2.6.1 +django-model-utils==3.1.2 django-oauth-toolkit==0.12.0 django-pgjson==0.3.1 django-simple-history==1.8.2