From bc5a39f1119889c5a15fe3e4fdaec6df5f3536f4 Mon Sep 17 00:00:00 2001 From: JamesBradbury Date: Tue, 11 Sep 2018 11:51:50 +0100 Subject: [PATCH 01/14] Use latest factory-boy because it works. --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 7b068025fc947ca2003b507f74f8f38f1b6d85ab Mon Sep 17 00:00:00 2001 From: JamesBradbury Date: Tue, 11 Sep 2018 18:20:34 +0100 Subject: [PATCH 02/14] Add GDAL to requirements (this might not work) --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index f60633ec..95484333 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,6 +12,7 @@ django-nose==1.4.5 djangorestframework==3.6.3 djangorestframework-gis==0.11.2 easy-thumbnails==2.4.2 +GDAL=2.2.3 gdata==2.0.18 iso8601==0.1.12 moment==0.8.2 From b4609922cdf72701e9a46b6a9df1b28a88f28617 Mon Sep 17 00:00:00 2001 From: JamesBradbury Date: Tue, 11 Sep 2018 18:21:19 +0100 Subject: [PATCH 03/14] Try specifying type_name property in factory. Remove unnecessary () --- geokey/categories/tests/model_factories.py | 2 ++ geokey/categories/tests/test_templatetags.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/geokey/categories/tests/model_factories.py b/geokey/categories/tests/model_factories.py index 47e3ad43..15a37467 100644 --- a/geokey/categories/tests/model_factories.py +++ b/geokey/categories/tests/model_factories.py @@ -70,6 +70,7 @@ class Meta: category = factory.SubFactory(CategoryFactory) status = 'active' required = False + type_name = 'Date and Time' class DateFieldFactory(factory.django.DjangoModelFactory): @@ -82,6 +83,7 @@ class Meta: category = factory.SubFactory(CategoryFactory) status = 'active' required = False + type_name = 'Date' class TimeFieldFactory(factory.django.DjangoModelFactory): diff --git a/geokey/categories/tests/test_templatetags.py b/geokey/categories/tests/test_templatetags.py index 6b2d3707..d556a854 100644 --- a/geokey/categories/tests/test_templatetags.py +++ b/geokey/categories/tests/test_templatetags.py @@ -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: @@ -86,6 +86,6 @@ def test_except_fields(self): date_fields = filter_fields.except_fields( all_fields, - (', ').join(type_names) + ', '.join(type_names) ) self.assertEqual(len(date_fields), 0) From a29bf45b26c244bc81d117953d3705c693d5aff0 Mon Sep 17 00:00:00 2001 From: JamesBradbury Date: Thu, 13 Sep 2018 16:35:31 +0100 Subject: [PATCH 04/14] Use InheritanceManager to select subclasses (half works). Rename date_fields to remaining_fields Use named association for clarity. --- geokey/categories/tests/test_templatetags.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/geokey/categories/tests/test_templatetags.py b/geokey/categories/tests/test_templatetags.py index d556a854..d4be9247 100644 --- a/geokey/categories/tests/test_templatetags.py +++ b/geokey/categories/tests/test_templatetags.py @@ -2,6 +2,7 @@ from django.test import TestCase +from geokey.categories.models import Field from geokey.categories.templatetags import filter_fields from geokey.categories.tests.model_factories import ( CategoryFactory, @@ -66,7 +67,7 @@ def test_except_fields(self): LookupFieldFactory(category=category) MultipleLookupFieldFactory(category=category) - all_fields = category.fields.all() + all_fields = Field.objects.filter(category=category).select_subclasses() type_names = [ 'Text', @@ -79,13 +80,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) From d23551fe4747926e871beb688f363b0ca104f163 Mon Sep 17 00:00:00 2001 From: JamesBradbury Date: Thu, 13 Sep 2018 18:10:03 +0100 Subject: [PATCH 05/14] Remove type_name from factories. Use InheritanceManager to query fields. Require latest django-model-utils. --- geokey/categories/tests/model_factories.py | 2 -- geokey/categories/tests/test_templatetags.py | 2 +- requirements.txt | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/geokey/categories/tests/model_factories.py b/geokey/categories/tests/model_factories.py index 15a37467..47e3ad43 100644 --- a/geokey/categories/tests/model_factories.py +++ b/geokey/categories/tests/model_factories.py @@ -70,7 +70,6 @@ class Meta: category = factory.SubFactory(CategoryFactory) status = 'active' required = False - type_name = 'Date and Time' class DateFieldFactory(factory.django.DjangoModelFactory): @@ -83,7 +82,6 @@ class Meta: category = factory.SubFactory(CategoryFactory) status = 'active' required = False - type_name = 'Date' class TimeFieldFactory(factory.django.DjangoModelFactory): diff --git a/geokey/categories/tests/test_templatetags.py b/geokey/categories/tests/test_templatetags.py index d4be9247..5e953dc1 100644 --- a/geokey/categories/tests/test_templatetags.py +++ b/geokey/categories/tests/test_templatetags.py @@ -28,7 +28,7 @@ def test_only_fields(self): LookupFieldFactory(category=category) MultipleLookupFieldFactory(category=category) - all_fields = category.fields.all() + all_fields = Field.objects.filter(category=category).select_subclasses() type_names = [ 'Text', diff --git a/requirements.txt b/requirements.txt index 95484333..b5804b26 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ 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 From babdfbcd9100e6183c271bac86a822e94370bf37 Mon Sep 17 00:00:00 2001 From: JamesBradbury Date: Fri, 14 Sep 2018 15:08:12 +0100 Subject: [PATCH 06/14] Simpler solution selecting subclasses and avoiding extra import. --- geokey/categories/tests/test_templatetags.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/geokey/categories/tests/test_templatetags.py b/geokey/categories/tests/test_templatetags.py index 5e953dc1..b8dfbf3c 100644 --- a/geokey/categories/tests/test_templatetags.py +++ b/geokey/categories/tests/test_templatetags.py @@ -2,7 +2,6 @@ from django.test import TestCase -from geokey.categories.models import Field from geokey.categories.templatetags import filter_fields from geokey.categories.tests.model_factories import ( CategoryFactory, @@ -28,7 +27,7 @@ def test_only_fields(self): LookupFieldFactory(category=category) MultipleLookupFieldFactory(category=category) - all_fields = Field.objects.filter(category=category).select_subclasses() + all_fields = category.fields.all().select_subclasses() type_names = [ 'Text', @@ -67,7 +66,7 @@ def test_except_fields(self): LookupFieldFactory(category=category) MultipleLookupFieldFactory(category=category) - all_fields = Field.objects.filter(category=category).select_subclasses() + all_fields = category.fields.all().select_subclasses() type_names = [ 'Text', From 6d47ac5405da46f3d6fd80b5124f23c2322f48a1 Mon Sep 17 00:00:00 2001 From: JamesBradbury Date: Fri, 14 Sep 2018 15:33:10 +0100 Subject: [PATCH 07/14] Ensure subclasses are selected when searching. --- geokey/contributions/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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': From 10a1f8c6268162d3220457603358f4328b94a605 Mon Sep 17 00:00:00 2001 From: JamesBradbury Date: Fri, 14 Sep 2018 15:37:58 +0100 Subject: [PATCH 08/14] Use empty dict for non-null properties. --- geokey/contributions/tests/comments/test_views.py | 2 +- geokey/contributions/tests/observations/test_models.py | 8 ++++---- geokey/contributions/tests/observations/test_views.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) 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() From 3f4794d330901ddfa52cce705aab35ee665a0cb8 Mon Sep 17 00:00:00 2001 From: JamesBradbury Date: Fri, 14 Sep 2018 16:30:40 +0100 Subject: [PATCH 09/14] Remove GDAL as it upsets Travis. --- requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index b5804b26..066c0c4d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,7 +12,6 @@ django-nose==1.4.5 djangorestframework==3.6.3 djangorestframework-gis==0.11.2 easy-thumbnails==2.4.2 -GDAL=2.2.3 gdata==2.0.18 iso8601==0.1.12 moment==0.8.2 From f6291760d037bcc2e31e46879bac9f9288c6c5f9 Mon Sep 17 00:00:00 2001 From: JamesBradbury Date: Fri, 14 Sep 2018 20:20:25 +0100 Subject: [PATCH 10/14] Require Travis to use Python 2.7.12 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e646c2af..08210365 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ services: - postgresql python: - - '2.7' + - '2.7.12' addons: postgresql: '9.4' From aa408b114370c7769f63efaf0f427285cae5397b Mon Sep 17 00:00:00 2001 From: JamesBradbury Date: Fri, 14 Sep 2018 20:21:25 +0100 Subject: [PATCH 11/14] Fix timezone warnings in tests. --- geokey/users/tests/test_admin_views.py | 11 ++++++----- geokey/users/views.py | 7 ++++--- 2 files changed, 10 insertions(+), 8 deletions(-) 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) From 4cce8f1aab95dd4bab9a06ffaa08387c856a06cc Mon Sep 17 00:00:00 2001 From: JamesBradbury Date: Fri, 14 Sep 2018 20:34:59 +0100 Subject: [PATCH 12/14] Use a python version travis actually has. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 08210365..e646c2af 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ services: - postgresql python: - - '2.7.12' + - '2.7' addons: postgresql: '9.4' From e176e83e980646461624dc48460909b4835e14b9 Mon Sep 17 00:00:00 2001 From: JamesBradbury Date: Fri, 14 Sep 2018 20:46:39 +0100 Subject: [PATCH 13/14] Use Django upto 1.11.* --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 55fbafd1edf77b3a0b7e6e9d10fc2f75b7bf37b3 Mon Sep 17 00:00:00 2001 From: JamesBradbury Date: Mon, 17 Sep 2018 10:01:47 +0100 Subject: [PATCH 14/14] Django upto 1.11.* added to requirements. --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 066c0c4d..6c3e2f17 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -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