feat: added creation endpoints

This commit is contained in:
2024-03-25 00:23:03 +01:00
parent 6b04fe7e23
commit 43338ceeec
16 changed files with 287 additions and 97 deletions
+21 -18
View File
@@ -1,6 +1,6 @@
from decimal import Decimal
from rest_framework.test import APITestCase as TestCase
from shop.models import Product, ProductPrice, OrderLine, Tax, Customer
from shop.models import Product, ProductPrice, Tax, Customer
from shop.utils import create_order_line_for_product, create_order
@@ -45,25 +45,8 @@ class ShopModelsTest(TestCase):
country="Tatooine",
)
l1 = create_order_line_for_product(
self.potatoes,
quantity=Decimal("1.5"),
tax=self.tax,
)
l2 = create_order_line_for_product(
self.gasoline,
quantity=Decimal("40"),
tax=self.tax,
)
l3 = create_order_line_for_product(
self.usb_c,
quantity=Decimal("1.00"),
tax=self.tax,
)
order = create_order(
customer=self.customer,
lines=OrderLine.objects.all(),
billing_address=self.customer.address,
billing_city=self.customer.city,
billing_state=self.customer.state,
@@ -71,5 +54,25 @@ class ShopModelsTest(TestCase):
billing_country=self.customer.country,
)
l1 = create_order_line_for_product(
self.potatoes,
quantity=Decimal("1.5"),
tax=self.tax,
order=order,
)
l2 = create_order_line_for_product(
self.gasoline,
quantity=Decimal("40"),
tax=self.tax,
order=order,
)
l3 = create_order_line_for_product(
self.usb_c,
quantity=Decimal("1.00"),
tax=self.tax,
order=order,
)
order.calculate_total_from_lines()
assert order.total == l1.total + l2.total + l3.total
assert order.base_total == l1.base_total + l2.base_total + l3.base_total