Ejemplo n.º 1
0
    def test_calculate_cart_quantity(self):
        cart = ShoppingCart()

        self.assertEqual(cart.item_quantity, 0)

        cart.add(Item("Ropa", 2, 1000))
        self.assertEqual(cart.item_quantity, 2)

        cart.add(Item("Envio", 3, 500))
        self.assertEqual(cart.item_quantity, 5)
Ejemplo n.º 2
0
    def test_can_add_items_to_cart_with_item_negative_value(self):
        cart = ShoppingCart()

        self.assertEqual(cart.total, 0)

        cart.add(Item("Ropa", 1, 200))
        self.assertEqual(cart.total, 200)

        cart.add(Item("Descuento", 1, -10))
        self.assertEqual(cart.total, 190)
Ejemplo n.º 3
0
    def test_calculate_cart_total(self):
        cart = ShoppingCart()

        self.assertEqual(cart.total, 0)

        cart.add(Item("Ropa", 1, 1000))
        self.assertEqual(cart.total, 1000)

        cart.add(Item("Envio", 1, 500))
        self.assertEqual(cart.total, 1500)
Ejemplo n.º 4
0
    def test_can_add_items_to_cart_with_item_negative_value_greater_than_total_amount(
            self):
        cart = ShoppingCart()

        self.assertEqual(cart.total, 0)

        cart.add(Item("Ropa", 1, 200))
        self.assertEqual(cart.total, 200)

        with self.assertRaisesRegex(ValueError,
                                    "Total amount cannot be less than zero."):
            cart.add(Item("Descuento", 1, -201))
def transaction():
    onepay.callback_url = request.url_root + "transaction/commit"

    shopping_cart = ShoppingCart()
    shopping_cart.add(Item("Fresh Strawberries", 1, 36000))
    shopping_cart.add(Item("Lightweight Jacket", 1, 16000))

    channel = Channel(
        request.form.get("channel")) if request.form.get("channel") else None

    result = Transaction.create(shopping_cart, channel)

    response = {
        "occ": result.occ,
        "ott": result.ott,
        "externalUniqueNumber": result.external_unique_number,
        "qrCodeAsBase64": result.qr_code_as_base64,
        "issuedAt": result.issued_at,
        "amount": shopping_cart.total
    }

    return jsonify(response)
Ejemplo n.º 6
0
 def get_valid_cart(self):
     shopping_cart = ShoppingCart()
     shopping_cart.add(Item("item", 1, 1000))
     return shopping_cart
Ejemplo n.º 7
0
    def test_shopping_cart_add_items(self):
        cart = ShoppingCart()
        cart.add(Item("Ropa", 1, 1000))
        cart.add(Item("Envio", 1, 500))

        self.assertEqual(len(cart.items), 2)