~homeworkprod/byceps

ref: 07761e715bf19496d75d7f4f69c494a80d57b8fd byceps/tests/integration/services/shop/order/email/helpers.py -rw-r--r-- 998 bytes
07761e71 — Jochen Kupperschmidt Make permission, locale arguments to current user factories optional 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
"""
: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:
    return session_service.get_authenticated_current_user(user)


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