From 0d3347552b4153df711020d9569d210aa391986e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Mon, 26 Feb 2024 09:15:36 -0300 Subject: [PATCH 01/27] update requirements_dev.txt --- requirements_dev.txt | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/requirements_dev.txt b/requirements_dev.txt index 8b47c60..ebb38e7 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,16 +1,15 @@ colour-runner==0.1.1 -coveralls==3.1.0 -coverage==5.5 +coveralls==3.3.1 +coverage==6.5.0 dj-database-url==0.5.0 -factory-boy==3.2.0 -flake8-docstrings==1.6.0 -flake8-import-order==0.18.1 -flake8==3.9.2 +factory-boy==3.3.0 +flake8-docstrings==1.7.0 +flake8-import-order==0.18.2 +flake8==7.0.0 incuna-test-utils==8.0.0 -pip==22.3 -psycopg2-binary==2.8.6 -pyflakes==2.3.1 -pycodestyle==2.7.0 -setuptools==65.5.0 -twine==3.4.1 -wheel==0.36.2 +psycopg2-binary==2.9.9 +pyflakes==3.2.0 +pycodestyle==2.11.1 +setuptools==69.1.1 +twine==5.0.0 +wheel==0.42.0 From fce839f8740b4c63570fb8720592f70dca06bca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Mon, 26 Feb 2024 09:25:12 -0300 Subject: [PATCH 02/27] updating coverage to fix vulnerability --- requirements_dev.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements_dev.txt b/requirements_dev.txt index ebb38e7..bd66a85 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,6 +1,6 @@ colour-runner==0.1.1 -coveralls==3.3.1 -coverage==6.5.0 +coveralls==1.8.0 +coverage==7.4.3 dj-database-url==0.5.0 factory-boy==3.3.0 flake8-docstrings==1.7.0 From e9fb8bef3ff0380b7af31501220d8481a589e19e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Mon, 26 Feb 2024 12:17:44 -0300 Subject: [PATCH 03/27] update decimal field behaviour to match Django 3.2 --- pgcrypto/fields.py | 2 ++ pgcrypto/mixins.py | 2 +- requirements_dev.txt | 1 + tests/run.py | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pgcrypto/fields.py b/pgcrypto/fields.py index 71a3ab7..ac275ed 100644 --- a/pgcrypto/fields.py +++ b/pgcrypto/fields.py @@ -125,11 +125,13 @@ class BooleanPGPSymmetricKeyField(PGPPublicKeyFieldMixin, models.BooleanField): class DecimalPGPPublicKeyField(DecimalPGPFieldMixin, PGPPublicKeyFieldMixin, models.DecimalField): """Decimal PGP public key encrypted field for postgres.""" + encrypt_sql = PGP_PUB_ENCRYPT_SQL_WITH_NULLIF class DecimalPGPSymmetricKeyField(DecimalPGPFieldMixin, PGPSymmetricKeyFieldMixin, models.DecimalField): """Decimal PGP symmetric key encrypted field for postgres.""" + encrypt_sql = PGP_SYM_ENCRYPT_SQL_WITH_NULLIF class FloatPGPPublicKeyField(PGPPublicKeyFieldMixin, models.FloatField): diff --git a/pgcrypto/mixins.py b/pgcrypto/mixins.py index 8d4e897..04f7708 100644 --- a/pgcrypto/mixins.py +++ b/pgcrypto/mixins.py @@ -157,7 +157,7 @@ def get_decrypt_sql(self, connection): class DecimalPGPFieldMixin: """Decimal PGP encrypted field mixin for postgres.""" - cast_type = 'NUMERIC(%(max_digits)s, %(decimal_places)s)' + cast_type = 'DECIMAL(%(max_digits)s, %(decimal_places)s)' def get_cast_sql(self): """Get cast sql.""" diff --git a/requirements_dev.txt b/requirements_dev.txt index bd66a85..0c6036b 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -13,3 +13,4 @@ pycodestyle==2.11.1 setuptools==69.1.1 twine==5.0.0 wheel==0.42.0 +django>=1.11,<=3.2 diff --git a/tests/run.py b/tests/run.py index 92e8b44..7a6b024 100755 --- a/tests/run.py +++ b/tests/run.py @@ -52,6 +52,7 @@ PRIVATE_PGP_KEY=open(PRIVATE_PGP_KEY_PATH, 'r').read(), PGCRYPTO_KEY='ultrasecret', DEBUG=True, + DEFAULT_AUTO_FIELD='django.db.models.BigAutoField' ) django.setup() From feb3ffc96c8da346a05477171c139a2aada732a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Mon, 26 Feb 2024 13:04:31 -0300 Subject: [PATCH 04/27] fixing tests to work with Django 5 timezone default --- requirements.txt | 2 +- requirements_dev.txt | 1 - tests/factories.py | 8 +- tests/run.py | 3 +- tests/test_fields.py | 227 ++++++++++++++++++++++++++++--------------- 5 files changed, 157 insertions(+), 84 deletions(-) diff --git a/requirements.txt b/requirements.txt index 0350699..b390c91 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -e . -django>=1.11,<3.2 +django>=1.11,<=5.0.2 diff --git a/requirements_dev.txt b/requirements_dev.txt index 0c6036b..bd66a85 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -13,4 +13,3 @@ pycodestyle==2.11.1 setuptools==69.1.1 twine==5.0.0 wheel==0.42.0 -django>=1.11,<=3.2 diff --git a/tests/factories.py b/tests/factories.py index 76f2745..1bdf111 100644 --- a/tests/factories.py +++ b/tests/factories.py @@ -1,7 +1,9 @@ -from datetime import date, datetime +from datetime import date from decimal import Decimal import factory +from django.utils import timezone + from .models import EncryptedFKModel, EncryptedModel @@ -28,7 +30,7 @@ class EncryptedModelFactory(factory.django.DjangoModelFactory): char_pub_field = factory.Sequence('Text {}'.format) date_pgp_pub_field = date.today() - datetime_pgp_pub_field = datetime.now() + datetime_pgp_pub_field = timezone.now() decimal_pgp_pub_field = Decimal('123456.78') boolean_pgp_pub_field = True @@ -39,7 +41,7 @@ class EncryptedModelFactory(factory.django.DjangoModelFactory): char_sym_field = factory.Sequence('Text {}'.format) date_pgp_sym_field = date.today() - datetime_pgp_sym_field = datetime.now() + datetime_pgp_sym_field = timezone.now() boolean_pgp_sym_field = False fk_model = factory.SubFactory(EncryptedFKModelFactory) diff --git a/tests/run.py b/tests/run.py index 7a6b024..4613913 100755 --- a/tests/run.py +++ b/tests/run.py @@ -52,7 +52,8 @@ PRIVATE_PGP_KEY=open(PRIVATE_PGP_KEY_PATH, 'r').read(), PGCRYPTO_KEY='ultrasecret', DEBUG=True, - DEFAULT_AUTO_FIELD='django.db.models.BigAutoField' + DEFAULT_AUTO_FIELD='django.db.models.BigAutoField', + USE_TZ=True, ) django.setup() diff --git a/tests/test_fields.py b/tests/test_fields.py index 992a89d..3b93969 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -1,4 +1,4 @@ -from datetime import date, datetime +from datetime import date, datetime, timezone from decimal import Decimal from unittest.mock import MagicMock @@ -6,6 +6,7 @@ from django.conf import settings from django.db import connections, models, reset_queries from django.test import TestCase +from django.utils import timezone as tz from incuna_test_utils.utils import field_names from pgcrypto import fields @@ -398,7 +399,7 @@ def test_pgp_symmetric_key_date_form(self): def test_pgp_symmetric_key_datetime_form(self): """Assert form field and widget for `DateTimePGPSymmetricKeyField` field.""" - expected = datetime.now() + expected = tz.now() instance = EncryptedModelFactory.create(datetime_pgp_sym_field=expected) instance.refresh_from_db() # Ensure the PGSQL casting works right @@ -413,12 +414,12 @@ def test_pgp_symmetric_key_datetime_form(self): self.assertTrue( cleaned_data['datetime_pgp_sym_field'], - datetime(2016, 8, 1, 14, 0, 0) + datetime(2016, 8, 1, 14, 0, 0, tzinfo=timezone.utc) ) def test_pgp_symmetric_key_time(self): """Assert date is save with an `TimePGPSymmetricKeyField` field.""" - expected = datetime.now().time() + expected = tz.now().time() instance = EncryptedModelFactory.create(time_pgp_sym_field=expected) instance.refresh_from_db() # Ensure the PGSQL casting works right @@ -430,7 +431,7 @@ def test_pgp_symmetric_key_time(self): def test_pgp_pub_key_time(self): """Assert date is save with an `TimePGPPublicKeyField` field.""" - expected = datetime.now().time() + expected = tz.now().time() instance = EncryptedModelFactory.create(time_pgp_pub_field=expected) instance.refresh_from_db() # Ensure the PGSQL casting works right @@ -442,7 +443,7 @@ def test_pgp_pub_key_time(self): def test_pgp_symmetric_key_time_form(self): """Assert form field and widget for `TimePGPSymmetricKeyField` field.""" - expected = datetime.now().time() + expected = tz.now().time() instance = EncryptedModelFactory.create(time_pgp_sym_field=expected) instance.refresh_from_db() # Ensure the PGSQL casting works right @@ -462,7 +463,7 @@ def test_pgp_symmetric_key_time_form(self): def test_pgp_public_key_time_form(self): """Assert form field and widget for `TimePGPSymmetricKeyField` field.""" - expected = datetime.now().time() + expected = tz.now().time() instance = EncryptedModelFactory.create(time_pgp_pub_field=expected) instance.refresh_from_db() # Ensure the PGSQL casting works right @@ -722,78 +723,104 @@ def test_pgp_pub_key_date_lookups(self): def test_pgp_symmetric_key_datetime_lookups(self): """Assert lookups `DateTimePGPSymmetricKeyField` field.""" - EncryptedModelFactory.create(datetime_pgp_sym_field=datetime(2016, 7, 1, 0, 0, 0)) - EncryptedModelFactory.create(datetime_pgp_sym_field=datetime(2016, 8, 1, 0, 0, 0)) - EncryptedModelFactory.create(datetime_pgp_sym_field=datetime(2016, 9, 1, 0, 0, 0)) + EncryptedModelFactory.create( + datetime_pgp_sym_field=datetime(2016, 7, 1, 0, 0, 0, tzinfo=timezone.utc) + ) + EncryptedModelFactory.create( + datetime_pgp_sym_field=datetime(2016, 8, 1, 0, 0, 0, tzinfo=timezone.utc) + ) + EncryptedModelFactory.create( + datetime_pgp_sym_field=datetime(2016, 9, 1, 0, 0, 0, tzinfo=timezone.utc) + ) # EXACT self.assertEqual( 1, EncryptedModel.objects.filter( - datetime_pgp_sym_field__exact=datetime(2016, 8, 1, 0, 0, 0) - ).count() + datetime_pgp_sym_field__exact=datetime( + 2016, 8, 1, 0, 0, 0, tzinfo=timezone.utc + ) + ).count(), ) self.assertEqual( 0, EncryptedModel.objects.filter( - datetime_pgp_sym_field__exact=datetime(2016, 8, 1, 0, 0, 1) - ).count() + datetime_pgp_sym_field__exact=datetime( + 2016, 8, 1, 0, 0, 1, tzinfo=timezone.utc + ) + ).count(), ) # GT self.assertEqual( 1, EncryptedModel.objects.filter( - datetime_pgp_sym_field__gt=datetime(2016, 8, 1, 0, 0, 0) - ).count() + datetime_pgp_sym_field__gt=datetime( + 2016, 8, 1, 0, 0, 0, tzinfo=timezone.utc + ) + ).count(), ) self.assertEqual( 0, EncryptedModel.objects.filter( - datetime_pgp_sym_field__gt=datetime(2016, 10, 1, 0, 0, 0) - ).count() + datetime_pgp_sym_field__gt=datetime( + 2016, 10, 1, 0, 0, 0, tzinfo=timezone.utc + ) + ).count(), ) # GTE self.assertEqual( 2, EncryptedModel.objects.filter( - datetime_pgp_sym_field__gte=datetime(2016, 8, 1, 0, 0, 0) - ).count() + datetime_pgp_sym_field__gte=datetime( + 2016, 8, 1, 0, 0, 0, tzinfo=timezone.utc + ) + ).count(), ) self.assertEqual( 0, EncryptedModel.objects.filter( - datetime_pgp_sym_field__gte=datetime(2016, 10, 1, 0, 0, 0) - ).count() + datetime_pgp_sym_field__gte=datetime( + 2016, 10, 1, 0, 0, 0, tzinfo=timezone.utc + ) + ).count(), ) # LE self.assertEqual( 1, EncryptedModel.objects.filter( - datetime_pgp_sym_field__lt=datetime(2016, 8, 1, 0, 0, 0) - ).count() + datetime_pgp_sym_field__lt=datetime( + 2016, 8, 1, 0, 0, 0, tzinfo=timezone.utc + ) + ).count(), ) self.assertEqual( 0, EncryptedModel.objects.filter( - datetime_pgp_sym_field__lt=datetime(2016, 6, 1, 0, 0, 0) - ).count() + datetime_pgp_sym_field__lt=datetime( + 2016, 6, 1, 0, 0, 0, tzinfo=timezone.utc + ) + ).count(), ) # LTE self.assertEqual( 2, EncryptedModel.objects.filter( - datetime_pgp_sym_field__lte=datetime(2016, 8, 1, 0, 0, 0) - ).count() + datetime_pgp_sym_field__lte=datetime( + 2016, 8, 1, 0, 0, 0, tzinfo=timezone.utc + ) + ).count(), ) self.assertEqual( 0, EncryptedModel.objects.filter( - datetime_pgp_sym_field__lte=datetime(2016, 6, 1, 0, 0, 0) - ).count() + datetime_pgp_sym_field__lte=datetime( + 2016, 6, 1, 0, 0, 0, tzinfo=timezone.utc + ) + ).count(), ) # RANGE @@ -801,8 +828,8 @@ def test_pgp_symmetric_key_datetime_lookups(self): 3, EncryptedModel.objects.filter( datetime_pgp_sym_field__range=[ - datetime(2016, 6, 1, 0, 0, 0), - datetime(2016, 11, 1, 23, 59, 59) + datetime(2016, 6, 1, 0, 0, 0, tzinfo=timezone.utc), + datetime(2016, 11, 1, 23, 59, 59, tzinfo=timezone.utc) ] ).count() ) @@ -811,8 +838,8 @@ def test_pgp_symmetric_key_datetime_lookups(self): 2, EncryptedModel.objects.filter( datetime_pgp_sym_field__range=[ - datetime(2016, 7, 1, 0, 0, 0), - datetime(2016, 8, 1, 0, 0, 0) + datetime(2016, 7, 1, 0, 0, 0, tzinfo=timezone.utc), + datetime(2016, 8, 1, 0, 0, 0, tzinfo=timezone.utc) ] ).count() ) @@ -821,7 +848,7 @@ def test_pgp_symmetric_key_datetime_lookups(self): 0, EncryptedModel.objects.filter( datetime_pgp_sym_field__range=[ - datetime(2016, 10, 1, 0, 0, 1), + datetime(2016, 10, 1, 0, 0, 1, tzinfo=timezone.utc), None ] ).count() @@ -829,78 +856,104 @@ def test_pgp_symmetric_key_datetime_lookups(self): def test_pgp_public_key_datetime_lookups(self): """Assert lookups `DateTimePGPPublicKeyField` field.""" - EncryptedModelFactory.create(datetime_pgp_pub_field=datetime(2016, 7, 1, 0, 0, 0)) - EncryptedModelFactory.create(datetime_pgp_pub_field=datetime(2016, 8, 1, 0, 0, 0)) - EncryptedModelFactory.create(datetime_pgp_pub_field=datetime(2016, 9, 1, 0, 0, 0)) + EncryptedModelFactory.create( + datetime_pgp_pub_field=datetime(2016, 7, 1, 0, 0, 0, tzinfo=timezone.utc) + ) + EncryptedModelFactory.create( + datetime_pgp_pub_field=datetime(2016, 8, 1, 0, 0, 0, tzinfo=timezone.utc) + ) + EncryptedModelFactory.create( + datetime_pgp_pub_field=datetime(2016, 9, 1, 0, 0, 0, tzinfo=timezone.utc) + ) # EXACT self.assertEqual( 1, EncryptedModel.objects.filter( - datetime_pgp_pub_field__exact=datetime(2016, 8, 1, 0, 0, 0) - ).count() + datetime_pgp_pub_field__exact=datetime( + 2016, 8, 1, 0, 0, 0, tzinfo=timezone.utc + ) + ).count(), ) self.assertEqual( 0, EncryptedModel.objects.filter( - datetime_pgp_pub_field__exact=datetime(2016, 8, 1, 0, 0, 1) - ).count() + datetime_pgp_pub_field__exact=datetime( + 2016, 8, 1, 0, 0, 1, tzinfo=timezone.utc + ) + ).count(), ) # GT self.assertEqual( 1, EncryptedModel.objects.filter( - datetime_pgp_pub_field__gt=datetime(2016, 8, 1, 0, 0, 0) - ).count() + datetime_pgp_pub_field__gt=datetime( + 2016, 8, 1, 0, 0, 0, tzinfo=timezone.utc + ) + ).count(), ) self.assertEqual( 0, EncryptedModel.objects.filter( - datetime_pgp_pub_field__gt=datetime(2016, 10, 1, 0, 0, 0) - ).count() + datetime_pgp_pub_field__gt=datetime( + 2016, 10, 1, 0, 0, 0, tzinfo=timezone.utc + ) + ).count(), ) # GTE self.assertEqual( 2, EncryptedModel.objects.filter( - datetime_pgp_pub_field__gte=datetime(2016, 8, 1, 0, 0, 0) - ).count() + datetime_pgp_pub_field__gte=datetime( + 2016, 8, 1, 0, 0, 0, tzinfo=timezone.utc + ) + ).count(), ) self.assertEqual( 0, EncryptedModel.objects.filter( - datetime_pgp_pub_field__gte=datetime(2016, 10, 1, 0, 0, 0) - ).count() + datetime_pgp_pub_field__gte=datetime( + 2016, 10, 1, 0, 0, 0, tzinfo=timezone.utc + ) + ).count(), ) # LE self.assertEqual( 1, EncryptedModel.objects.filter( - datetime_pgp_pub_field__lt=datetime(2016, 8, 1, 0, 0, 0) - ).count() + datetime_pgp_pub_field__lt=datetime( + 2016, 8, 1, 0, 0, 0, tzinfo=timezone.utc + ) + ).count(), ) self.assertEqual( 0, EncryptedModel.objects.filter( - datetime_pgp_pub_field__lt=datetime(2016, 6, 1, 0, 0, 0) - ).count() + datetime_pgp_pub_field__lt=datetime( + 2016, 6, 1, 0, 0, 0, tzinfo=timezone.utc + ) + ).count(), ) # LTE self.assertEqual( 2, EncryptedModel.objects.filter( - datetime_pgp_pub_field__lte=datetime(2016, 8, 1, 0, 0, 0) - ).count() + datetime_pgp_pub_field__lte=datetime( + 2016, 8, 1, 0, 0, 0, tzinfo=timezone.utc + ) + ).count(), ) self.assertEqual( 0, EncryptedModel.objects.filter( - datetime_pgp_pub_field__lte=datetime(2016, 6, 1, 0, 0, 0) - ).count() + datetime_pgp_pub_field__lte=datetime( + 2016, 6, 1, 0, 0, 0, tzinfo=timezone.utc + ) + ).count(), ) # RANGE @@ -908,8 +961,8 @@ def test_pgp_public_key_datetime_lookups(self): 3, EncryptedModel.objects.filter( datetime_pgp_pub_field__range=[ - datetime(2016, 6, 1, 0, 0, 0), - datetime(2016, 11, 1, 23, 59, 59) + datetime(2016, 6, 1, 0, 0, 0, tzinfo=timezone.utc), + datetime(2016, 11, 1, 23, 59, 59, tzinfo=timezone.utc) ] ).count() ) @@ -918,8 +971,8 @@ def test_pgp_public_key_datetime_lookups(self): 2, EncryptedModel.objects.filter( datetime_pgp_pub_field__range=[ - datetime(2016, 7, 1, 0, 0, 0), - datetime(2016, 8, 1, 0, 0, 0) + datetime(2016, 7, 1, 0, 0, 0, tzinfo=timezone.utc), + datetime(2016, 8, 1, 0, 0, 0, tzinfo=timezone.utc) ] ).count() ) @@ -928,7 +981,7 @@ def test_pgp_public_key_datetime_lookups(self): 0, EncryptedModel.objects.filter( datetime_pgp_pub_field__range=[ - datetime(2016, 10, 1, 0, 0, 1), + datetime(2016, 10, 1, 0, 0, 1, tzinfo=timezone.utc), None ] ).count() @@ -1350,11 +1403,21 @@ def test_update_or_create(self): def test_aggregates(self): """Test aggregate support.""" - EncryptedModelFactory.create(datetime_pgp_sym_field=datetime(2016, 7, 1, 0, 0, 0)) - EncryptedModelFactory.create(datetime_pgp_sym_field=datetime(2016, 7, 2, 0, 0, 0)) - EncryptedModelFactory.create(datetime_pgp_sym_field=datetime(2016, 8, 1, 0, 0, 0)) - EncryptedModelFactory.create(datetime_pgp_sym_field=datetime(2016, 9, 1, 0, 0, 0)) - EncryptedModelFactory.create(datetime_pgp_sym_field=datetime(2016, 9, 2, 0, 0, 0)) + EncryptedModelFactory.create( + datetime_pgp_sym_field=datetime(2016, 7, 1, 0, 0, 0, tzinfo=timezone.utc) + ) + EncryptedModelFactory.create( + datetime_pgp_sym_field=datetime(2016, 7, 2, 0, 0, 0, tzinfo=timezone.utc) + ) + EncryptedModelFactory.create( + datetime_pgp_sym_field=datetime(2016, 8, 1, 0, 0, 0, tzinfo=timezone.utc) + ) + EncryptedModelFactory.create( + datetime_pgp_sym_field=datetime(2016, 9, 1, 0, 0, 0, tzinfo=timezone.utc) + ) + EncryptedModelFactory.create( + datetime_pgp_sym_field=datetime(2016, 9, 2, 0, 0, 0, tzinfo=timezone.utc) + ) total_2016 = self.model.objects.aggregate( count=models.Count('datetime_pgp_sym_field') @@ -1364,8 +1427,8 @@ def test_aggregates(self): total_july = self.model.objects.filter( datetime_pgp_sym_field__range=[ - datetime(2016, 7, 1, 0, 0, 0), - datetime(2016, 7, 30, 23, 59, 59) + datetime(2016, 7, 1, 0, 0, 0, tzinfo=timezone.utc), + datetime(2016, 7, 30, 23, 59, 59, tzinfo=timezone.utc) ] ).aggregate( count=models.Count('datetime_pgp_sym_field') @@ -1380,13 +1443,17 @@ def test_aggregates(self): ) self.assertEqual(5, total_2016['count']) - self.assertEqual(datetime(2016, 7, 1, 0, 0, 0), total_2016['min']) - self.assertEqual(datetime(2016, 9, 2, 0, 0, 0), total_2016['max']) + self.assertEqual( + datetime(2016, 7, 1, 0, 0, 0, tzinfo=timezone.utc), total_2016["min"] + ) + self.assertEqual( + datetime(2016, 9, 2, 0, 0, 0, tzinfo=timezone.utc), total_2016["max"] + ) total_july = self.model.objects.filter( datetime_pgp_sym_field__range=[ - datetime(2016, 7, 1, 0, 0, 0), - datetime(2016, 7, 30, 23, 59, 59) + datetime(2016, 7, 1, 0, 0, 0, tzinfo=timezone.utc), + datetime(2016, 7, 30, 23, 59, 59, tzinfo=timezone.utc) ] ).aggregate( count=models.Count('datetime_pgp_sym_field'), @@ -1395,8 +1462,12 @@ def test_aggregates(self): ) self.assertEqual(2, total_july['count']) - self.assertEqual(datetime(2016, 7, 1, 0, 0, 0), total_july['min']) - self.assertEqual(datetime(2016, 7, 2, 0, 0, 0), total_july['max']) + self.assertEqual( + datetime(2016, 7, 1, 0, 0, 0, tzinfo=timezone.utc), total_july["min"] + ) + self.assertEqual( + datetime(2016, 7, 2, 0, 0, 0, tzinfo=timezone.utc), total_july["max"] + ) def test_distinct(self): """Test distinct support.""" @@ -1467,8 +1538,8 @@ def test_annotate(self): def test_get_col(self): """Test get_col for related alias.""" - related = EncryptedDateTime.objects.create(value=datetime.now()) - related_again = EncryptedDateTime.objects.create(value=datetime.now()) + related = EncryptedDateTime.objects.create(value=tz.now()) + related_again = EncryptedDateTime.objects.create(value=tz.now()) RelatedDateTime.objects.create(related=related, related_again=related_again) From c67a1bb893cd7ab9ff8cf247a5b1a672837dc950 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Mon, 26 Feb 2024 17:16:37 -0300 Subject: [PATCH 05/27] setup github actions and database setup --- .github/workflows/test.yml | 39 ++++++++++++++++++++++++++++++++++++++ tests/db_setup.py | 13 +++++++++++++ tests/run.py | 16 ++++++++++++++-- 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/test.yml create mode 100644 tests/db_setup.py diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..bb95402 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,39 @@ +name: Tests + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.12"] + services: + postgres: + image: postgres + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: postgres + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements_dev.txt --upgrade + pip install -r requirements.txt --upgrade + - name: Run tests + run: | + make test diff --git a/tests/db_setup.py b/tests/db_setup.py new file mode 100644 index 0000000..d4f69f1 --- /dev/null +++ b/tests/db_setup.py @@ -0,0 +1,13 @@ +import psycopg2 + + +def create_dbs(db_config, databases): + """Set up the databases for test.""" + connection = psycopg2.connect(**db_config) + connection.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT) + cursor = connection.cursor() + for database in databases: + cursor.execute(f"DROP DATABASE IF EXISTS {database}") + cursor.execute(f"CREATE DATABASE {database}") + cursor.close() + connection.close() diff --git a/tests/run.py b/tests/run.py index 4613913..38a19e9 100755 --- a/tests/run.py +++ b/tests/run.py @@ -8,6 +8,18 @@ from colour_runner.django_runner import ColourRunnerMixin from django.conf import settings from django.test.runner import DiscoverRunner +from tests import db_setup + +default_db_config = { + 'dbname': 'postgres', + 'user': 'postgres', + 'password': 'postgres', + 'host': 'localhost', + 'port': 5432, +} + +db_setup.create_dbs(default_db_config, + databases=('pgcrypto_fields', 'pgcrypto_fields_diff')) BASEDIR = os.path.dirname(os.path.dirname(__file__)) PUBLIC_PGP_KEY_PATH = os.path.abspath( @@ -24,7 +36,7 @@ ) diff_keys = dj_database_url.config( - default='postgres://localhost/pgcrypto_fields_diff' + default='postgres://postgres:postgres@localhost/pgcrypto_fields_diff' ) # Cannot chain onto the config() call due to error @@ -37,7 +49,7 @@ settings.configure( DATABASES={ 'default': dj_database_url.config( - default='postgres://localhost/pgcrypto_fields' + default='postgres://postgres:postgres@localhost/pgcrypto_fields' ), 'diff_keys': diff_keys, }, From 6406b34b5cb4ed893a90fd79ff4995d2a343a05c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Mon, 26 Feb 2024 17:31:41 -0300 Subject: [PATCH 06/27] adding docker-compose for test database --- .gitignore | 3 +++ docker-compose.yml | 11 +++++++++++ 2 files changed, 14 insertions(+) create mode 100644 docker-compose.yml diff --git a/.gitignore b/.gitignore index 8ef313b..9521e7c 100644 --- a/.gitignore +++ b/.gitignore @@ -48,6 +48,9 @@ coverage.xml *.log local_settings.py +# pyenv +.python-version + # virtualenv .venv/ venv/ diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..315a78b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +version: '3' +services: + postgres: + image: postgres + ports: + - 5432:5432 + restart: unless-stopped + environment: + - POSTGRES_DB=postgres + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres From 43e0c31983fe84066e1433d19984e423a85b80b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Mon, 26 Feb 2024 17:32:32 -0300 Subject: [PATCH 07/27] adding 3.10 and 3.11 python versions on test --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bb95402..ae5ec69 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,12 +3,12 @@ name: Tests on: [push] jobs: - build: + test: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.12"] + python-version: ["3.10", "3.11", "3.12"] services: postgres: image: postgres From ef75a635a7f0909271023c09bfcdcf884114da4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Mon, 26 Feb 2024 18:28:33 -0300 Subject: [PATCH 08/27] adding support to JSONField --- pgcrypto/fields.py | 12 +++++ tests/factories.py | 3 ++ tests/models.py | 3 ++ tests/test_fields.py | 116 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 134 insertions(+) diff --git a/pgcrypto/fields.py b/pgcrypto/fields.py index ac275ed..7fc4a5b 100644 --- a/pgcrypto/fields.py +++ b/pgcrypto/fields.py @@ -156,3 +156,15 @@ class TimePGPSymmetricKeyField(PGPSymmetricKeyFieldMixin, models.TimeField): """Float PGP symmetric key encrypted field for postgres.""" encrypt_sql = PGP_SYM_ENCRYPT_SQL_WITH_NULLIF cast_type = 'TIME' + + +class JSONPGPPublicKeyField(PGPPublicKeyFieldMixin, models.JSONField): + """JSON PGP public key encrypted field for postgres.""" + encrypt_sql = PGP_PUB_ENCRYPT_SQL_WITH_NULLIF + cast_type = 'jsonb' + + +class JSONPGPSymmetricKeyField(PGPSymmetricKeyFieldMixin, models.JSONField): + """Float PGP symmetric key encrypted field for postgres.""" + encrypt_sql = PGP_SYM_ENCRYPT_SQL_WITH_NULLIF + cast_type = 'jsonb' diff --git a/tests/factories.py b/tests/factories.py index 1bdf111..b59f58e 100644 --- a/tests/factories.py +++ b/tests/factories.py @@ -44,6 +44,9 @@ class EncryptedModelFactory(factory.django.DjangoModelFactory): datetime_pgp_sym_field = timezone.now() boolean_pgp_sym_field = False + json_pgp_pub_field = {"key": "value"} + json_pgp_sym_field = {"key": "value"} + fk_model = factory.SubFactory(EncryptedFKModelFactory) class Meta: diff --git a/tests/models.py b/tests/models.py index 52f1565..67697f0 100644 --- a/tests/models.py +++ b/tests/models.py @@ -59,6 +59,9 @@ class EncryptedModel(models.Model): float_pgp_sym_field = fields.FloatPGPSymmetricKeyField(blank=True, null=True) boolean_pgp_sym_field = fields.BooleanPGPSymmetricKeyField(blank=True, null=True) + json_pgp_pub_field = fields.JSONPGPPublicKeyField(blank=True, null=True) + json_pgp_sym_field = fields.JSONPGPSymmetricKeyField(blank=True, null=True) + fk_model = models.ForeignKey( EncryptedFKModel, blank=True, null=True, on_delete=models.CASCADE ) diff --git a/tests/test_fields.py b/tests/test_fields.py index 3b93969..a80d255 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -106,6 +106,8 @@ def test_fields(self): 'float_pgp_sym_field', 'boolean_pgp_pub_field', 'boolean_pgp_sym_field', + 'json_pgp_pub_field', + 'json_pgp_sym_field', 'fk_model', ) self.assertCountEqual(fields, expected) @@ -1617,3 +1619,117 @@ def test_write_to_diff_keys(self): instance.hmac_field, expected ) + + def test_json_pgp_pub_field(self): + """Test JSONPGPPublicKeyField.""" + expected = {'a': 1, 'b': '2', 'c': [1, 2, 3]} + EncryptedModelFactory.create(json_pgp_pub_field=expected) + + instance = EncryptedModel.objects.get() + + self.assertIsInstance( + instance.json_pgp_pub_field, + dict + ) + + self.assertEqual( + instance.json_pgp_pub_field, + expected + ) + + items = EncryptedModel.objects.filter(json_pgp_pub_field__a=1) + + self.assertEqual( + 1, + len(items) + ) + + items = EncryptedModel.objects.filter(json_pgp_pub_field__c__contains=2) + + self.assertEqual( + 1, + len(items) + ) + + items = EncryptedModel.objects.filter(json_pgp_pub_field__b=2) + + self.assertEqual( + 0, + len(items) + ) + + def test_json_pgp_sym_field(self): + """Test JsonPGPSymmetricKeyField.""" + expected = {'a': 1, 'b': '2', 'c': [1, 2, 3]} + EncryptedModelFactory.create(json_pgp_sym_field=expected) + + instance = EncryptedModel.objects.get() + + self.assertIsInstance( + instance.json_pgp_sym_field, + dict + ) + + self.assertEqual( + instance.json_pgp_sym_field, + expected + ) + + items = EncryptedModel.objects.filter(json_pgp_sym_field__a=1) + + self.assertEqual( + 1, + len(items) + ) + + items = EncryptedModel.objects.filter(json_pgp_sym_field__c__contains=2) + + self.assertEqual( + 1, + len(items) + ) + + items = EncryptedModel.objects.filter(json_pgp_sym_field__b=2) + + self.assertEqual( + 0, + len(items) + ) + + def test_pgp_public_key_json_form(self): + """Assert form field and widget for `JSONPGPSymmetricKeyField` field.""" + expected = {'a': 1, 'b': '2', 'c': [1, 2, 3]} + instance = EncryptedModelFactory.create(json_pgp_pub_field=expected) + + payload = { + 'json_pgp_pub_field': expected + } + + form = EncryptedForm(payload, instance=instance) + self.assertTrue(form.is_valid()) + + cleaned_data = form.cleaned_data + + self.assertTrue( + cleaned_data['json_pgp_pub_field'], + expected + ) + + def test_pgp_symmetric_key_json_form(self): + """Assert form field and widget for `JSONPGPSymmetricKeyField` field.""" + expected = {'a': 1, 'b': '2', 'c': [1, 2, 3]} + instance = EncryptedModelFactory.create(json_pgp_sym_field=expected) + + payload = { + 'json_pgp_sym_field': expected + } + + form = EncryptedForm(payload, instance=instance) + self.assertTrue(form.is_valid()) + + cleaned_data = form.cleaned_data + + self.assertTrue( + cleaned_data['json_pgp_sym_field'], + expected + ) From 5cfaae014f0b825ce0e0b1bea42abaf4dbc67ab3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Mon, 26 Feb 2024 18:46:52 -0300 Subject: [PATCH 09/27] setting 3.2 as Django minimal version --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index b390c91..728ba56 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -e . -django>=1.11,<=5.0.2 +django>=3.2,<=5.0.2 From 8de97a926d5beb2b331f3f912ec52bef4c1f2bb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 27 Feb 2024 08:02:34 -0300 Subject: [PATCH 10/27] Update actions/setup-python to v5 --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ae5ec69..aa69743 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,7 +26,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Install dependencies From f1fffb0744a9a0796c2103fdf57e623b4b6382a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 27 Feb 2024 08:16:52 -0300 Subject: [PATCH 11/27] adding coverage to test workflow and create lint job --- .github/workflows/test.yml | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index aa69743..871a0c4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,14 +1,29 @@ -name: Tests +name: On push on: [push] jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python 3.12 + uses: actions/setup-python@v5 + with: + python-version: '3.12' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements_dev.txt --upgrade + pip install -r requirements.txt --upgrade + - name: Run tests + run: | + make lint test: - runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.10", "3.11", "3.12"] + python-version: ['3.10', '3.11', '3.12'] services: postgres: image: postgres @@ -37,3 +52,9 @@ jobs: - name: Run tests run: | make test + - name: Create coverage report + run: | + make test-coverage + - name: Upload coverage report + run: | + make test-coveralls From 63d11be5d1d31346be78aa2c611c62aa9281cda8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 27 Feb 2024 08:18:03 -0300 Subject: [PATCH 12/27] add list as requirement for test --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 871a0c4..a3e4620 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,6 +21,7 @@ jobs: make lint test: runs-on: ubuntu-latest + needs: lint strategy: matrix: python-version: ['3.10', '3.11', '3.12'] From 2b498afccc1ae1865a254c3c85b3fbe81b9acb11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 27 Feb 2024 08:19:08 -0300 Subject: [PATCH 13/27] remove lint from make test --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ba0403d..5a7613b 100644 --- a/Makefile +++ b/Makefile @@ -69,7 +69,7 @@ build: clean-build ## Builds source and wheel package release: ## Package and upload a release twine upload dist/* -test: clean-build lint ## Run tests quickly with the default Python +test: clean-build ## Run tests quickly with the default Python ./tests/run.py test-coverage: ## Check code coverage quickly with the default Python From 1f1ba690170e30dc61a3dd23ef2a1629f8c9a434 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 27 Feb 2024 08:26:12 -0300 Subject: [PATCH 14/27] adding django to test matrix and removing coveralls --- .github/workflows/test.yml | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a3e4620..e0397c9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,9 +13,8 @@ jobs: python-version: '3.12' - name: Install dependencies run: | - python -m pip install --upgrade pip - pip install -r requirements_dev.txt --upgrade - pip install -r requirements.txt --upgrade + pip install -r requirements_dev.txt + pip install -r requirements.txt - name: Run tests run: | make lint @@ -25,6 +24,7 @@ jobs: strategy: matrix: python-version: ['3.10', '3.11', '3.12'] + django-version: ['django>=3.2,<5.0', 'django>=5.0', '--upgrade --pre django'] services: postgres: image: postgres @@ -47,15 +47,9 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | - python -m pip install --upgrade pip - pip install -r requirements_dev.txt --upgrade - pip install -r requirements.txt --upgrade + pip install -e . + pip install -r requirements_dev.txt + pip install {{ matrix.django-version }} - name: Run tests run: | make test - - name: Create coverage report - run: | - make test-coverage - - name: Upload coverage report - run: | - make test-coveralls From 3e32f704158d7fea3454abddf0bc954b908e62c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 27 Feb 2024 08:28:39 -0300 Subject: [PATCH 15/27] fixing typo on gh action --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e0397c9..54779de 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -49,7 +49,7 @@ jobs: run: | pip install -e . pip install -r requirements_dev.txt - pip install {{ matrix.django-version }} + pip install ${{ matrix.django-version }} - name: Run tests run: | make test From 69d5e8fe7e750c48f96504a26b292aad38fcf049 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 27 Feb 2024 08:31:16 -0300 Subject: [PATCH 16/27] adding quotes to django version --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 54779de..fa3da30 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -49,7 +49,7 @@ jobs: run: | pip install -e . pip install -r requirements_dev.txt - pip install ${{ matrix.django-version }} + pip install '${{ matrix.django-version }}' - name: Run tests run: | make test From bb61d14df3b8431d725dced30b4a6b875f172845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 27 Feb 2024 08:53:24 -0300 Subject: [PATCH 17/27] Revert "adding quotes to django version" This reverts commit 69d5e8fe7e750c48f96504a26b292aad38fcf049. --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fa3da30..54779de 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -49,7 +49,7 @@ jobs: run: | pip install -e . pip install -r requirements_dev.txt - pip install '${{ matrix.django-version }}' + pip install ${{ matrix.django-version }} - name: Run tests run: | make test From 7bbda572753c475ce85927b5b0cf9feb402e255a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 27 Feb 2024 08:53:38 -0300 Subject: [PATCH 18/27] Revert "fixing typo on gh action" This reverts commit 3e32f704158d7fea3454abddf0bc954b908e62c4. --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 54779de..e0397c9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -49,7 +49,7 @@ jobs: run: | pip install -e . pip install -r requirements_dev.txt - pip install ${{ matrix.django-version }} + pip install {{ matrix.django-version }} - name: Run tests run: | make test From 192a1dbf7205bee3e9f63a548e8bc6bca10e567b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 27 Feb 2024 08:53:40 -0300 Subject: [PATCH 19/27] Revert "adding django to test matrix and removing coveralls" This reverts commit 1f1ba690170e30dc61a3dd23ef2a1629f8c9a434. --- .github/workflows/test.yml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e0397c9..a3e4620 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,8 +13,9 @@ jobs: python-version: '3.12' - name: Install dependencies run: | - pip install -r requirements_dev.txt - pip install -r requirements.txt + python -m pip install --upgrade pip + pip install -r requirements_dev.txt --upgrade + pip install -r requirements.txt --upgrade - name: Run tests run: | make lint @@ -24,7 +25,6 @@ jobs: strategy: matrix: python-version: ['3.10', '3.11', '3.12'] - django-version: ['django>=3.2,<5.0', 'django>=5.0', '--upgrade --pre django'] services: postgres: image: postgres @@ -47,9 +47,15 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | - pip install -e . - pip install -r requirements_dev.txt - pip install {{ matrix.django-version }} + python -m pip install --upgrade pip + pip install -r requirements_dev.txt --upgrade + pip install -r requirements.txt --upgrade - name: Run tests run: | make test + - name: Create coverage report + run: | + make test-coverage + - name: Upload coverage report + run: | + make test-coveralls From f956acc00e48db0374c3f4a07a1473221f9f55ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 27 Feb 2024 08:53:41 -0300 Subject: [PATCH 20/27] Revert "remove lint from make test" This reverts commit 2b498afccc1ae1865a254c3c85b3fbe81b9acb11. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 5a7613b..ba0403d 100644 --- a/Makefile +++ b/Makefile @@ -69,7 +69,7 @@ build: clean-build ## Builds source and wheel package release: ## Package and upload a release twine upload dist/* -test: clean-build ## Run tests quickly with the default Python +test: clean-build lint ## Run tests quickly with the default Python ./tests/run.py test-coverage: ## Check code coverage quickly with the default Python From 13595251102084d01cb851ef94204e9ee7b43984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 27 Feb 2024 08:53:43 -0300 Subject: [PATCH 21/27] Revert "add list as requirement for test" This reverts commit 63d11be5d1d31346be78aa2c611c62aa9281cda8. --- .github/workflows/test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a3e4620..871a0c4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,7 +21,6 @@ jobs: make lint test: runs-on: ubuntu-latest - needs: lint strategy: matrix: python-version: ['3.10', '3.11', '3.12'] From 1af0cdd75c57dc3f8e6e0331ebb57ec78933cdaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 27 Feb 2024 08:53:45 -0300 Subject: [PATCH 22/27] Revert "adding coverage to test workflow and create lint job" This reverts commit f1fffb0744a9a0796c2103fdf57e623b4b6382a6. --- .github/workflows/test.yml | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 871a0c4..aa69743 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,29 +1,14 @@ -name: On push +name: Tests on: [push] jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Set up Python 3.12 - uses: actions/setup-python@v5 - with: - python-version: '3.12' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements_dev.txt --upgrade - pip install -r requirements.txt --upgrade - - name: Run tests - run: | - make lint test: + runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.10', '3.11', '3.12'] + python-version: ["3.10", "3.11", "3.12"] services: postgres: image: postgres @@ -52,9 +37,3 @@ jobs: - name: Run tests run: | make test - - name: Create coverage report - run: | - make test-coverage - - name: Upload coverage report - run: | - make test-coveralls From 9710f11ed0ee1fe17b1defaaf200503d28715599 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 27 Feb 2024 08:54:32 -0300 Subject: [PATCH 23/27] adding python 3.9 to matrix --- .github/workflows/test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index aa69743..bc61ee3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,11 +4,10 @@ on: [push] jobs: test: - runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.10", "3.11", "3.12"] + python-version: ["3.9", "3.10", "3.11", "3.12"] services: postgres: image: postgres From 30383dbe2b99e2b2312961e086f04e63c077f19d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 27 Feb 2024 09:01:30 -0300 Subject: [PATCH 24/27] adding django version to matrix --- .github/workflows/test.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bc61ee3..f55fe69 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: Tests +name: On push on: [push] @@ -7,7 +7,11 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.9", "3.10", "3.11", "3.12"] + python-version: ['3.9', '3.10', '3.11', '3.12'] + django-version: ['django>=3.2,<4.0', 'django>=4.0,<5.0', 'django>=5.0', '--upgrade --pre django'] + exclude: + - python-version: '3.9' + django-version: ['django>=5.0', '--upgrade --pre django'] services: postgres: image: postgres @@ -31,8 +35,9 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install -r requirements_dev.txt --upgrade - pip install -r requirements.txt --upgrade + pip install -e . + pip install -r requirements_dev.txt + pip install '${{ matrix.django-version }}' - name: Run tests run: | make test From 9af5664c61b0f00cdf02995e35a9cf17c901f9bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 27 Feb 2024 09:11:14 -0300 Subject: [PATCH 25/27] debugging import error --- .github/workflows/test.yml | 8 +++++--- tests/run.py | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f55fe69..84449d0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,11 +7,13 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.9', '3.10', '3.11', '3.12'] - django-version: ['django>=3.2,<4.0', 'django>=4.0,<5.0', 'django>=5.0', '--upgrade --pre django'] + # python-version: ['3.9', '3.10', '3.11', '3.12'] + # django-version: ['django>=3.2,<4.0', 'django>=4.0,<5.0', 'django>=5.0'] + python-version: ['3.12'] + django-version: ['django>=5.0'] exclude: - python-version: '3.9' - django-version: ['django>=5.0', '--upgrade --pre django'] + django-version: ['django>=5.0'] services: postgres: image: postgres diff --git a/tests/run.py b/tests/run.py index 38a19e9..860703e 100755 --- a/tests/run.py +++ b/tests/run.py @@ -8,6 +8,10 @@ from colour_runner.django_runner import ColourRunnerMixin from django.conf import settings from django.test.runner import DiscoverRunner + +print("Current directory:", os.getcwd()) +print("Contents of the directory:", os.listdir(os.getcwd())) + from tests import db_setup default_db_config = { From f1c7faee1e36e07172a3f4be17a38242cb3bdada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 27 Feb 2024 09:17:26 -0300 Subject: [PATCH 26/27] debugging import error --- tests/run.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/run.py b/tests/run.py index 860703e..f307e72 100755 --- a/tests/run.py +++ b/tests/run.py @@ -11,6 +11,7 @@ print("Current directory:", os.getcwd()) print("Contents of the directory:", os.listdir(os.getcwd())) +print("Contents of the directory of run.py:", os.listdir(os.chdir(os.path.dirname(os.path.abspath(__file__))))) from tests import db_setup From 1340897c22edab84205386e25863bc4a6a36eacc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Tue, 27 Feb 2024 09:23:55 -0300 Subject: [PATCH 27/27] debugging import error --- tests/run.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/run.py b/tests/run.py index f307e72..0e86db0 100755 --- a/tests/run.py +++ b/tests/run.py @@ -13,7 +13,7 @@ print("Contents of the directory:", os.listdir(os.getcwd())) print("Contents of the directory of run.py:", os.listdir(os.chdir(os.path.dirname(os.path.abspath(__file__))))) -from tests import db_setup +from db_setup import create_dbs default_db_config = { 'dbname': 'postgres', @@ -23,7 +23,7 @@ 'port': 5432, } -db_setup.create_dbs(default_db_config, +create_dbs(default_db_config, databases=('pgcrypto_fields', 'pgcrypto_fields_diff')) BASEDIR = os.path.dirname(os.path.dirname(__file__))