Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision fc7747df7177f2f610c55c9709a81e7b0b618806 authored by Jochen Kupperschmidt on 03 January 2026, 00:21:02 UTC, committed by Jochen Kupperschmidt on 03 January 2026, 00:21:02 UTC
Display only language icon on CozyLAN locale selector dropdown button
1 parent 2e587a4
  • Files
  • Changes
  • 86abe66
  • /
  • tests
  • /
  • unit
  • /
  • services
  • /
  • shop
  • /
  • order
  • /
  • test_total_amount.py
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:fc7747df7177f2f610c55c9709a81e7b0b618806
directory badge
swh:1:dir:6645e6f4cf1a983cf3a3f23a682695ce58671331
content badge
swh:1:cnt:11b8a5267e9a579e335f2073300a219b0bf69f20

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
test_total_amount.py
"""
:Copyright: 2014-2025 Jochen Kupperschmidt
:License: Revised BSD (see `LICENSE` file for details)
"""

from collections.abc import Iterable
from datetime import datetime

from moneyed import EUR, Money
import pytest

from byceps.services.shop.cart.models import Cart
from byceps.services.shop.order import order_domain_service
from byceps.services.shop.order.errors import CartEmptyError
from byceps.services.shop.order.log.models import OrderLogEntry
from byceps.services.shop.order.models.checkout import IncomingOrder
from byceps.services.shop.order.models.order import Orderer
from byceps.services.shop.product.models import Product
from byceps.services.shop.shop.models import ShopID
from byceps.services.shop.storefront.models import StorefrontID
from byceps.util.result import Err, Result

from tests.helpers import generate_token


SHOP_ID = ShopID(generate_token())
STOREFRONT_ID = StorefrontID(generate_token())


@pytest.fixture(scope='module')
def product1(make_product) -> Product:
    return make_product(price=Money('49.95', EUR))


@pytest.fixture(scope='module')
def product2(make_product) -> Product:
    return make_product(price=Money('6.20', EUR))


@pytest.fixture(scope='module')
def product3(make_product) -> Product:
    return make_product(price=Money('12.53', EUR))


def test_without_any_items(orderer: Orderer):
    empty_cart = Cart(EUR)

    result = place_order(orderer, empty_cart)

    assert result == Err(CartEmptyError())


def test_with_single_item(orderer: Orderer, product1: Product):
    order = build_incoming_order(
        orderer,
        [
            (product1, 1),
        ],
    )

    assert order.total_amount == Money('49.95', EUR)


def test_with_multiple_items(
    orderer: Orderer,
    product1: Product,
    product2: Product,
    product3: Product,
):
    order = build_incoming_order(
        orderer,
        [
            (product1, 3),
            (product2, 1),
            (product3, 4),
        ],
    )

    assert order.total_amount == Money('206.17', EUR)


# helpers


def build_incoming_order(
    orderer: Orderer, products: Iterable[tuple[Product, int]]
) -> IncomingOrder:
    cart = Cart(EUR)
    for product, quantity in products:
        cart.add_item(product, quantity)

    incoming_order, _ = place_order(orderer, cart).unwrap()

    return incoming_order


def place_order(
    orderer: Orderer, cart: Cart
) -> Result[tuple[IncomingOrder, OrderLogEntry], CartEmptyError]:
    return order_domain_service.place_order(
        datetime.utcnow(), SHOP_ID, STOREFRONT_ID, orderer, cart
    )
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API