Exemplo n.º 1
0
    def setUp(self) -> None:
        self.sauce = Product("001", "Curry sauce", 1.95)
        self.pizza = Product("002", "Pizza", 5.99)
        self.shirt = Product("003", "Men's T-Shirt", 25.00)

        self.rule_total = PromotionalRule(
            name="If you spend over €30, you get 10 percent off your purchase.",
            discount_type="TOTAL",
            product=None,
            target_quantity=30,
            measure="PERCENTAGE",
            discount_amount=10,
        )

        self.rule_pizza = PromotionalRule(
            name=
            "If you buy 2 or more pizzas, the price for each drops to €3.99.",
            discount_type="PRODUCT",
            product=self.pizza,
            target_quantity=2,
            measure="CURRENCY",
            discount_amount=2,
        )

        self.rule_pizza_second = PromotionalRule(
            name=
            "If you buy 3 or more pizzas, the price for each drops to €2.99.",
            discount_type="PRODUCT",
            product=self.pizza,
            target_quantity=3,
            measure="CURRENCY",
            discount_amount=3,
        )

        self.rule_one_shirt_discount = PromotionalRule(
            name="If you buy T-Shirt, you are awesome!",
            discount_type="PRODUCT",
            product=self.shirt,
            target_quantity=1,
            measure="PERCENTAGE",
            discount_amount=25,
        )

        self.clean_instance = Checkout([])
Exemplo n.º 2
0
 def list(self) -> List[Product]:
     result = self._entries
     return [Product.from_dict(entry) for entry in result]
Exemplo n.º 3
0
 def create(self, code, name, price) -> Product:
     adict = {"code": code, "name": name, "price": price}
     product_entity = Product.from_dict(adict)
     self._entries.append(adict)
     return product_entity
Exemplo n.º 4
0
 def find_by_code(self, code):
     for entry in self._entries:
         if entry["code"] == code:
             return Product.from_dict(entry)
Exemplo n.º 5
0
 def create(self, code: str, name: str, price: float) -> IProduct:
     return Product(code="001", name="Lizard", price=25.99)
Exemplo n.º 6
0
 def find_by_code(self, code: str) -> IProduct:
     return Product(code="001", name="Lizard", price=25.99)
 def setUp(self) -> None:
     self.product = Product(code="001", name="Lizard", price=25.99)
Exemplo n.º 8
0
from ca.exceptions import PromotionalRuleError
from ca.entities.product import Product
from ca.entities.promotional_rule import PromotionalRule
import unittest
from ca.repositories.interfaces import IPromotionalRuleRepository
from ca.use_cases.promotional_rule.create_promotional_rule_use_case import (
    CreatePromotionalRuleUseCase, )

fake_product = Product("001", "Pizza", 90)
fake_promo_rule = PromotionalRule(
    name="Test promo rule",
    discount_type="TOTAL",
    product=fake_product,
    target_quantity=1,
    measure="PERCENTAGE",
    discount_amount=10,
)


class FakePromotionalRuleRepoCreate(IPromotionalRuleRepository):
    def create(self, name: str, discount_type, product, target_quantity,
               measure, discount_amount) -> PromotionalRule:
        return fake_promo_rule

    def list(self):
        return []


class FakePromotionalRuleRepoList(IPromotionalRuleRepository):
    def create(self, name: str, discount_type, product, target_quantity,
               measure, discount_amount) -> PromotionalRule:
Exemplo n.º 9
0
    def test_product_init(self):
        product = Product(code="001", name="Lizard", price=25.99)

        self.assertEqual(product.code, "001")
        self.assertEqual(product.name, "Lizard")
        self.assertEqual(product.price, 25.99)
Exemplo n.º 10
0
    def test_products_equality(self):
        adict = {"code": "001", "name": "Lizard", "price": 25.99}
        product1 = Product.from_dict(adict)
        product2 = Product.from_dict(adict)

        self.assertEqual(product1, product2)
Exemplo n.º 11
0
 def test_product_create_from_dict(self):
     adict = {"code": "001", "name": "Lizard", "price": 25.99}
     product = Product.from_dict(adict)
     self.assertEqual(product.code, "001")
     self.assertEqual(product.name, "Lizard")
     self.assertEqual(product.price, 25.99)
 def setUp(self):
     self.repo = MemoryPromotionalRuleRepository()
     self.product = Product("001", "Pizza", 90)
 def test_create_product(self):
     adict = {"code": "001", "name": "Lizard", "price": 25.99}
     test_product = self.repo.create(**adict)
     self.assertEqual(test_product, Product.from_dict(adict))