~homeworkprod/byceps

ref: ac29a0cb50e2ef450d4e5ebd33419ed490c96e4f byceps/tests/integration/services/shop/order/email/helpers.py -rw-r--r-- 1.1 KiB
ac29a0cb — Jochen Kupperschmidt Add session locale selector (and indicator) to CozyLAN site 11 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
:Copyright: 2006-2021 Jochen Kupperschmidt
:License: Revised BSD (see `LICENSE` file for details)
"""

from byceps.services.authentication.session.models.current_user import (
    CurrentUser,
)
from byceps.services.authentication.session import service as session_service
from byceps.services.shop.cart.models import Cart
from byceps.services.shop.order import service as order_service

from tests.integration.services.shop.helpers import create_orderer


def get_current_user_for_user(user) -> CurrentUser:
    permissions = set()
    locale = None

    return session_service.get_authenticated_current_user(
        user, permissions, locale
    )


def place_order_with_items(
    storefront_id, user, created_at=None, items_with_quantity=None
):
    orderer = create_orderer(user)

    cart = Cart()

    if items_with_quantity is not None:
        for article, quantity in items_with_quantity:
            cart.add_item(article, quantity)

    order, _ = order_service.place_order(
        storefront_id, orderer, cart, created_at=created_at
    )

    return order