feat: added shop models
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
from decimal import Decimal
|
||||
from rest_framework.test import APITestCase as TestCase
|
||||
from shop.models import Product, ProductPrice, OrderLine, Tax
|
||||
from shop.utils import create_order_line_for_product, create_order
|
||||
|
||||
|
||||
class ShopModelsTest(TestCase):
|
||||
def setUp(self) -> None:
|
||||
self.tax = Tax.objects.create(
|
||||
code="IVA",
|
||||
value=21,
|
||||
)
|
||||
self.create_products()
|
||||
|
||||
def create_products(self):
|
||||
self.potatoes = Product.objects.create(
|
||||
name="Patatas",
|
||||
stock=Decimal("100.00"),
|
||||
unit=Product.UnitChoices.WEIGHT_KG,
|
||||
)
|
||||
self.gasoline = Product.objects.create(
|
||||
name="Gasolina",
|
||||
stock=Decimal("800.00"),
|
||||
unit=Product.UnitChoices.VOLUME_LITER,
|
||||
)
|
||||
self.usb_c = Product.objects.create(
|
||||
name="Cable USB-C",
|
||||
stock=Decimal("5.00"),
|
||||
unit=Product.UnitChoices.UNIT,
|
||||
)
|
||||
|
||||
ProductPrice.objects.create(product=self.potatoes, price=Decimal("0.80"))
|
||||
ProductPrice.objects.create(product=self.gasoline, price=Decimal("1.15"))
|
||||
ProductPrice.objects.create(product=self.usb_c, price=Decimal("9.95"))
|
||||
|
||||
def test_create_order(self):
|
||||
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(OrderLine.objects.all())
|
||||
|
||||
assert order.total == l1.total + l2.total + l3.total
|
||||
assert order.base_total == l1.base_total + l2.base_total + l3.base_total
|
||||
Reference in New Issue
Block a user