From 671232c3a8786ce8b4ccfc168811fa747e798f7a Mon Sep 17 00:00:00 2001 From: mrroot5 Date: Mon, 6 Oct 2025 19:50:19 +0200 Subject: [PATCH 1/4] Fix deprecations warnings --- Makefile | 2 +- src/api/models.py | 4 ++-- src/api/tests.py | 18 +++++++++--------- src/commons/tests.py | 5 ----- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 28ba729..a16177c 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ test: build ${DOCKER_COMPOSE_RUN_WEB} web python manage.py test --failfast api deprecations: build migrate - ${DOCKER_COMPOSE_RUN_WEB} web python -Wa manage.py test --failfast api + ${DOCKER_COMPOSE_RUN_WEB} web python -Wa manage.py test shell: ${DOCKER_COMPOSE_RUN_WEB} web ash diff --git a/src/api/models.py b/src/api/models.py index ca7f93b..7526685 100644 --- a/src/api/models.py +++ b/src/api/models.py @@ -68,7 +68,7 @@ class WalletTransaction(models.Model): amount and client_wallet_account are the only required fields. """ - class Type(models.TextChoices): + class Type(models.IntegerChoices): ERROR = 0 TESTING = 1 DEPOSIT = 2 @@ -79,7 +79,7 @@ class Type(models.TextChoices): amount = models.DecimalField(max_digits=7, decimal_places=2) done = models.BooleanField(default=True, help_text="It check if the transaction was completed") transaction_type = models.IntegerField( - choices=Type.choices, default=Type.TESTING.value, help_text="Add or substract money" + choices=Type, default=Type.TESTING.value, help_text="Add or substract money" ) error_msg = models.CharField(max_length=250, null=True, blank=True, unique=False, help_text="Ex. Transaction error: negative balance") diff --git a/src/api/tests.py b/src/api/tests.py index 1597161..3549161 100644 --- a/src/api/tests.py +++ b/src/api/tests.py @@ -670,11 +670,11 @@ def test_create_regular_user_transactions_as_regular_user(self): "client_wallet_account": self.regular_user_wallet.id } if payload.get('amount', 0) > 0: - transaction_type = str(ClientWalletTransaction.Type.DEPOSIT.value) + transaction_type = ClientWalletTransaction.Type.DEPOSIT.value elif payload.get('amount', 0) < 0: - transaction_type = str(ClientWalletTransaction.Type.WITHDRAW.value) + transaction_type = ClientWalletTransaction.Type.WITHDRAW.value else: - transaction_type = str(ClientWalletTransaction.Type.TESTING.value) + transaction_type = ClientWalletTransaction.Type.TESTING.value response_data = { **payload, "amount": str(payload.get('amount')), @@ -734,11 +734,11 @@ def test_create_regular_user_transactions_as_staff_user(self): "client_wallet_account": self.regular_user_wallet.id } if payload.get('amount', 0) > 0: - transaction_type = str(ClientWalletTransaction.Type.DEPOSIT.value) + transaction_type = ClientWalletTransaction.Type.DEPOSIT.value elif payload.get('amount', 0) < 0: - transaction_type = str(ClientWalletTransaction.Type.WITHDRAW.value) + transaction_type = ClientWalletTransaction.Type.WITHDRAW.value else: - transaction_type = str(ClientWalletTransaction.Type.TESTING.value) + transaction_type = ClientWalletTransaction.Type.TESTING.value response_data = { **payload, "amount": str(payload.get('amount')), @@ -778,11 +778,11 @@ def test_create_staff_user_transactions_as_staff_user(self): "client_wallet_account": user_wallet.id } if payload.get('amount', 0) > 0: - transaction_type = str(ClientWalletTransaction.Type.DEPOSIT.value) + transaction_type = ClientWalletTransaction.Type.DEPOSIT.value elif payload.get('amount', 0) < 0: - transaction_type = str(ClientWalletTransaction.Type.WITHDRAW.value) + transaction_type = ClientWalletTransaction.Type.WITHDRAW.value else: - transaction_type = str(ClientWalletTransaction.Type.TESTING.value) + transaction_type = ClientWalletTransaction.Type.TESTING.value response_data = { **payload, "amount": str(payload.get('amount')), diff --git a/src/commons/tests.py b/src/commons/tests.py index 538f315..8d36661 100644 --- a/src/commons/tests.py +++ b/src/commons/tests.py @@ -5,7 +5,6 @@ Author: Adrian G Created: 2019/03/16 -Contact: mroot5@outlook.es Notes: test --keepdb https://docs.djangoproject.com/en/dev/ref/django-admin/#cmdoption-test-keepdb @@ -18,10 +17,6 @@ https://docs.djangoproject.com/en/dev/topics/testing/tools/#exceptions https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertRaises - -Terminal colors: -* Yellow: \e[33mText\e[0m -* Red: \e[32mText\e[0m """ From c2a426676ca78a3ffe9417c87940f1fde3a559c6 Mon Sep 17 00:00:00 2001 From: mrroot5 Date: Mon, 6 Oct 2025 19:51:00 +0200 Subject: [PATCH 2/4] Migration WalletTransaction.Type choices from text to integer --- ...clientwallettransaction_transaction_type.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/api/migrations/0002_alter_clientwallettransaction_transaction_type.py diff --git a/src/api/migrations/0002_alter_clientwallettransaction_transaction_type.py b/src/api/migrations/0002_alter_clientwallettransaction_transaction_type.py new file mode 100644 index 0000000..1ba9d37 --- /dev/null +++ b/src/api/migrations/0002_alter_clientwallettransaction_transaction_type.py @@ -0,0 +1,18 @@ +# Generated by Django 5.2.7 on 2025-10-06 17:09 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='clientwallettransaction', + name='transaction_type', + field=models.IntegerField(choices=[(0, 'Error'), (1, 'Testing'), (2, 'Deposit'), (3, 'Withdraw')], default=1, help_text='Add or substract money'), + ), + ] From 682d44e0b0309caa39c683674e28a401c4c2f055 Mon Sep 17 00:00:00 2001 From: mrroot5 Date: Mon, 6 Oct 2025 19:51:18 +0200 Subject: [PATCH 3/4] Added postgresql connections pool --- src/django_atomic_transactions/settings.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/django_atomic_transactions/settings.py b/src/django_atomic_transactions/settings.py index eab1b12..fcd2bb0 100644 --- a/src/django_atomic_transactions/settings.py +++ b/src/django_atomic_transactions/settings.py @@ -58,8 +58,15 @@ 'USER': os.environ.get('DJANGO_DATABASE_USER'), 'PASSWORD': os.environ.get('DJANGO_DATABASE_PASSWORD'), 'HOST': os.environ.get('DJANGO_DATABASE_HOST'), - 'PORT': os.environ.get('DJANGO_DATABASE_PORT', 5432) - } + 'PORT': os.environ.get('DJANGO_DATABASE_PORT', 5432), + 'OPTIONS': { + 'pool': { + 'min_size': 1, + 'max_size': 4, + 'timeout': 10, + } + } + }, } AUTH_PASSWORD_VALIDATORS = [ From a47f7128890ae3a1f38a1add1182279aad8a7480 Mon Sep 17 00:00:00 2001 From: mrroot5 Date: Mon, 6 Oct 2025 19:53:40 +0200 Subject: [PATCH 4/4] Bump django, update and delete dependencies. - Deleted typing_extensions, not required by installed dependencies. --- environment/requirements/requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/environment/requirements/requirements.txt b/environment/requirements/requirements.txt index 9c5999c..37920da 100644 --- a/environment/requirements/requirements.txt +++ b/environment/requirements/requirements.txt @@ -1,7 +1,7 @@ asgiref==3.10.0 backcall==0.2.0 decorator==5.2.1 -Django==4.2.25 +Django==5.2.7 django-extensions==4.1 djangorestframework==3.16.1 Faker==37.8.0 @@ -19,8 +19,8 @@ ptyprocess==0.7.0 pycodestyle==2.8.0 pyflakes==2.4.0 Pygments==2.19.2 +setuptools==80.9.0 sqlparse==0.5.3 traitlets==5.14.3 -typing_extensions==4.15.0 tzdata==2025.2 wcwidth==0.2.14