chore: formatted stuff

This commit is contained in:
2024-05-13 17:34:56 +02:00
parent a49fb5e885
commit aa80c58628
6 changed files with 51 additions and 46 deletions
+1 -1
View File
@@ -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
+10 -5
View File
@@ -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"))
)
+25 -21
View File
@@ -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")
+14
View File
@@ -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}")
+1 -6
View File
@@ -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 = []
-13
View File
@@ -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", {})