diff --git a/requirements.txt b/requirements.txt index 2ba11cf..91aa45f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -celery==5.2.7 +celery==5.4.0 django==5.0.3 django-cors-headers==3.13.0 django-cryptography==1.1 diff --git a/shop/api/v1/viewsets.py b/shop/api/v1/viewsets.py index 31b5804..c17af6d 100644 --- a/shop/api/v1/viewsets.py +++ b/shop/api/v1/viewsets.py @@ -107,13 +107,13 @@ class OrderLineViewSet(ModelViewSet): def perform_create(self, serializer): with transaction.atomic(): - order = get_object_or_404(Order, uuid=self.kwargs.get('order_id')) - product = serializer.validated_data.get('product') + order = get_object_or_404(Order, uuid=self.kwargs.get("order_id")) + product = serializer.validated_data.get("product") price = product.prices.last() tax = price.tax.value - quantity = serializer.validated_data.get('quantity') + quantity = serializer.validated_data.get("quantity") base_total = quantity * price.price - taxes = base_total * (tax / Decimal('100')) + taxes = base_total * (tax / Decimal("100")) total = base_total + taxes instance = serializer.save( @@ -139,4 +139,9 @@ class OrderLineViewSet(ModelViewSet): order.save() def get_queryset(self): - return super().get_queryset().select_related('order').filter(order__uuid=self.kwargs.get("order_id")) + return ( + super() + .get_queryset() + .select_related("order") + .filter(order__uuid=self.kwargs.get("order_id")) + ) diff --git a/shop/tests/test_api_orders.py b/shop/tests/test_api_orders.py index 7bd525b..b3b7f1c 100644 --- a/shop/tests/test_api_orders.py +++ b/shop/tests/test_api_orders.py @@ -61,11 +61,11 @@ class TestOrdersAPI(APITestCase, TestUserAuthenticationMixin): "shipping_country": self.customer.country, "shipping_zip": self.customer.zip, "contact_phone": "612345678", - } + }, ) assert response.status_code == status.HTTP_201_CREATED - pk = response.data.get('uuid') + pk = response.data.get("uuid") response = self.client.get(f"/api/v1/shop/orders/{pk}/") assert response.status_code == status.HTTP_200_OK @@ -88,34 +88,36 @@ class TestOrdersAPI(APITestCase, TestUserAuthenticationMixin): "shipping_country": self.customer.country, "shipping_zip": self.customer.zip, "contact_phone": "612345678", - } + }, ) assert response.status_code == status.HTTP_201_CREATED - pk = response.data.get('uuid') + pk = response.data.get("uuid") response = self.client.get(f"/api/v1/shop/orders/{pk}/") assert response.status_code == status.HTTP_200_OK - assert Decimal(response.data.get('base_total')) == Decimal('0.00') - assert Decimal(response.data.get('total')) == Decimal('0.00') + assert Decimal(response.data.get("base_total")) == Decimal("0.00") + assert Decimal(response.data.get("total")) == Decimal("0.00") response = self.client.post( f"/api/v1/shop/orders/{pk}/lines/", { "product": self.product.pk, "quantity": "5", - } + }, ) assert response.status_code == status.HTTP_201_CREATED response = self.client.get(f"/api/v1/shop/orders/{pk}/lines/") - assert len(response.data.get('results')) == 1 + assert len(response.data.get("results")) == 1 response = self.client.get(f"/api/v1/shop/orders/{pk}/") assert response.status_code == status.HTTP_200_OK - assert Decimal(response.data.get('base_total')) == Decimal('6.00') - assert Decimal(response.data.get('total')) == Decimal('6.00') + (Decimal('6.00') * Decimal('0.21')) + assert Decimal(response.data.get("base_total")) == Decimal("6.00") + assert Decimal(response.data.get("total")) == Decimal("6.00") + ( + Decimal("6.00") * Decimal("0.21") + ) def test_create_delete_order_with_lines(self): self.login() @@ -136,18 +138,18 @@ class TestOrdersAPI(APITestCase, TestUserAuthenticationMixin): "shipping_country": self.customer.country, "shipping_zip": self.customer.zip, "contact_phone": "612345678", - } + }, ) assert response.status_code == status.HTTP_201_CREATED - pk = response.data.get('uuid') + pk = response.data.get("uuid") response = self.client.get(f"/api/v1/shop/orders/{pk}/") assert response.status_code == status.HTTP_200_OK # Assert order is created with 0.00€ - assert Decimal(response.data.get('base_total')) == Decimal('0.00') - assert Decimal(response.data.get('total')) == Decimal('0.00') + assert Decimal(response.data.get("base_total")) == Decimal("0.00") + assert Decimal(response.data.get("total")) == Decimal("0.00") # Create order line response = self.client.post( @@ -155,21 +157,23 @@ class TestOrdersAPI(APITestCase, TestUserAuthenticationMixin): { "product": self.product.pk, "quantity": "5", - } + }, ) - line_pk = response.data.get('id') + line_pk = response.data.get("id") assert response.status_code == status.HTTP_201_CREATED response = self.client.get(f"/api/v1/shop/orders/{pk}/lines/") - assert len(response.data.get('results')) == 1 + assert len(response.data.get("results")) == 1 response = self.client.get(f"/api/v1/shop/orders/{pk}/") assert response.status_code == status.HTTP_200_OK # Assert order totals are set - assert Decimal(response.data.get('base_total')) == Decimal('6.00') - assert Decimal(response.data.get('total')) == Decimal('6.00') + (Decimal('6.00') * Decimal('0.21')) + assert Decimal(response.data.get("base_total")) == Decimal("6.00") + assert Decimal(response.data.get("total")) == Decimal("6.00") + ( + Decimal("6.00") * Decimal("0.21") + ) # Delete line response = self.client.delete(f"/api/v1/shop/orders/{pk}/lines/{line_pk}/") @@ -179,5 +183,5 @@ class TestOrdersAPI(APITestCase, TestUserAuthenticationMixin): assert response.status_code == status.HTTP_200_OK # Assert order totals are 0.00 - assert Decimal(response.data.get('base_total')) == Decimal('0.00') - assert Decimal(response.data.get('total')) == Decimal('0.00') + assert Decimal(response.data.get("base_total")) == Decimal("0.00") + assert Decimal(response.data.get("total")) == Decimal("0.00") diff --git a/tpv/tests/test_redsys.py b/tpv/tests/test_redsys.py index c315838..ade09ca 100644 --- a/tpv/tests/test_redsys.py +++ b/tpv/tests/test_redsys.py @@ -5,11 +5,14 @@ from django.urls import reverse from rest_framework import status from rest_framework.test import APITestCase from django.conf import settings +from django.utils import timezone from tpv.models import PaymentTransaction from tpv.redsys import RedsysClient from tpv.settings import ERROR_CODES +from tpv.utils import validate_expiry_date + class TestRedsysTPV(APITestCase): def test_redsys_client(self): @@ -179,3 +182,14 @@ class TestRedsysTPV(APITestCase): reverse("tpv:ko", kwargs={"transaction": transaction.hash}) ) assert response.status_code == status.HTTP_200_OK + + def test_expiry_date(self): + now = timezone.now() + previous_year = str(now.year - 1).rjust(2, "0") + current_month = str(now.month).rjust(2, "0") + current_year = str(now.year)[-2:] + + assert not validate_expiry_date("042024") + assert not validate_expiry_date(f"{previous_year}{current_month}") + + assert validate_expiry_date(f"{current_year}{current_month}") diff --git a/users/urls.py b/users/urls.py index e4abd46..77659d6 100644 --- a/users/urls.py +++ b/users/urls.py @@ -1,12 +1,7 @@ from django.urls import path -from users.views import login, register, reset_password app_name = "users" -urlpatterns = [ - path("login", login, name="login"), - path("sign-up", register, name="register"), - path("reset-password", reset_password, name="reset_password"), -] +urlpatterns = [] diff --git a/users/views.py b/users/views.py index 8d0b5ab..e69de29 100644 --- a/users/views.py +++ b/users/views.py @@ -1,13 +0,0 @@ -from django.shortcuts import render - - -def login(request): - return render(request, "users/login.html", {}) - - -def register(request): - return render(request, "users/register.html", {}) - - -def reset_password(request): - return render(request, "users/reset_password.html", {})