def setUp(self): self.shopping_cart = ShoppingCart() onepay.integration_type = onepay.IntegrationType.MOCK onepay.api_key = self.api_key_mock onepay.shared_secret = self.shared_secret_mock onepay.callback_url = None onepay.app_scheme = None
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)
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)
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)
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)
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 get_valid_cart(self): shopping_cart = ShoppingCart() shopping_cart.add(Item("item", 1, 1000)) return shopping_cart
def setUp(self): self.shopping_cart = ShoppingCart() onepay.integration_type = onepay.IntegrationType.MOCK onepay.api_key = self.api_key_mock onepay.shared_secret = self.shared_secret_mock
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)