~homeworkprod/byceps

48d0a3e77b0f6b4f47c8cb6fd98023bac28a7de3 — Jochen Kupperschmidt 1 year, 5 months ago b1b56f4
Pass storefront ID instead of shop ID for order placement

The order number sequence is obtained via the storefront instead of the
shop now.
M byceps/blueprints/shop/order/views.py => byceps/blueprints/shop/order/views.py +4 -4
@@ 115,7 115,7 @@ def order():
    orderer = form.get_orderer(g.current_user.id)

    try:
        order = _place_order(shop.id, orderer, cart)
        order = _place_order(storefront.id, orderer, cart)
    except order_service.OrderFailed:
        flash_error('Die Bestellung ist fehlgeschlagen.')
        return order_form(form)


@@ 222,7 222,7 @@ def order_single(article_id):
    cart = _create_cart_from_article_compilation(article_compilation)

    try:
        order = _place_order(shop.id, orderer, cart)
        order = _place_order(storefront.id, orderer, cart)
    except order_service.OrderFailed:
        flash_error('Die Bestellung ist fehlgeschlagen.')
        return order_form(form)


@@ 261,8 261,8 @@ def _create_cart_from_article_compilation(
    return cart


def _place_order(shop_id, orderer, cart):
    order, event = order_service.place_order(shop_id, orderer, cart)
def _place_order(storefront_id, orderer, cart):
    order, event = order_service.place_order(storefront_id, orderer, cart)

    order_email_service.send_email_for_incoming_order_to_orderer(order.id)


M byceps/services/shop/order/service.py => byceps/services/shop/order/service.py +7 -4
@@ 22,6 22,8 @@ from ..sequence import service as sequence_service
from ..shop.models import Shop
from ..shop import service as shop_service
from ..shop.transfer.models import ShopID
from ..storefront import service as storefront_service
from ..storefront.transfer.models import StorefrontID

from .models.order import Order as DbOrder
from .models.order_event import OrderEvent as DbOrderEvent


@@ 42,17 44,18 @@ class OrderFailed(Exception):


def place_order(
    shop_id: ShopID,
    storefront_id: StorefrontID,
    orderer: Orderer,
    cart: Cart,
    *,
    created_at: Optional[datetime] = None,
) -> Tuple[Order, ShopOrderPlaced]:
    """Place an order for one or more articles."""
    shop = shop_service.get_shop(shop_id)
    storefront = storefront_service.get_storefront(storefront_id)
    shop = shop_service.get_shop(storefront.shop_id)

    order_number_sequence = sequence_service.find_order_number_sequence_for_shop(
        shop.id
    order_number_sequence = sequence_service.find_order_number_sequence(
        storefront.order_number_sequence_id
    )
    order_number = sequence_service.generate_order_number(
        order_number_sequence.id

M byceps/services/shop/sequence/service.py => byceps/services/shop/sequence/service.py +0 -23
@@ 171,29 171,6 @@ def find_order_number_sequences_for_shop(
    return _find_number_sequences(shop_id, Purpose.order)


def find_order_number_sequence_for_shop(
    shop_id: ShopID,
) -> Optional[NumberSequence]:
    """Return the order number sequence for that shop, or `None` if
    the sequence is not defined or the shop does not exist.
    """
    return _find_number_sequence(shop_id, Purpose.order)


def _find_number_sequence(
    shop_id: ShopID, purpose: Purpose
) -> Optional[NumberSequence]:
    sequence = DbNumberSequence.query \
        .filter_by(shop_id=shop_id) \
        .filter_by(_purpose=purpose.name) \
        .one_or_none()

    if sequence is None:
        return None

    return _db_entity_to_number_sequence(sequence)


def _find_number_sequences(
    shop_id: ShopID, purpose: Purpose
) -> List[NumberSequence]:

M tests/integration/blueprints/admin/shop/conftest.py => tests/integration/blueprints/admin/shop/conftest.py +29 -0
@@ 5,11 5,40 @@

import pytest

from byceps.services.shop.sequence import service as sequence_service
from byceps.services.shop.shop import service as shop_service
from byceps.services.shop.storefront import service as storefront_service


@pytest.fixture(scope='module')
def shop(email_config):
    shop = shop_service.create_shop('shop-01', 'Some Shop', email_config.id)

    yield shop

    shop_service.delete_shop(shop.id)


@pytest.fixture(scope='module')
def order_number_sequence_id(shop) -> None:
    sequence_id = sequence_service.create_order_number_sequence(
        shop.id, 'ORDER-'
    )

    yield sequence_id

    sequence_service.delete_order_number_sequence(sequence_id)


@pytest.fixture(scope='module')
def storefront(shop, order_number_sequence_id) -> None:
    storefront = storefront_service.create_storefront(
        f'{shop.id}-storefront',
        shop.id,
        order_number_sequence_id,
        closed=False,
    )

    yield storefront

    storefront_service.delete_storefront(storefront.id)

M tests/integration/blueprints/admin/shop/order/test_order_export.py => tests/integration/blueprints/admin/shop/order/test_order_export.py +23 -6
@@ 16,6 16,7 @@ from byceps.services.shop.cart.models import Cart
from byceps.services.shop.order.models.orderer import Orderer
from byceps.services.shop.order import service as order_service
from byceps.services.shop.sequence import service as sequence_service
from byceps.services.shop.storefront import service as storefront_service

from tests.helpers import (
    create_permissions,


@@ 123,20 124,36 @@ def orderer(make_user):


@pytest.fixture
def order_number_sequence(shop) -> None:
def order_number_sequence_id(shop) -> None:
    sequence_id = sequence_service.create_order_number_sequence(
        shop.id, 'LR-08-B', value=26
    )
    yield

    yield sequence_id

    sequence_service.delete_order_number_sequence(sequence_id)


@pytest.fixture
def order(shop, order_number_sequence, cart, orderer):
def storefront(shop, order_number_sequence_id) -> None:
    storefront = storefront_service.create_storefront(
        f'{shop.id}-storefront',
        shop.id,
        order_number_sequence_id,
        closed=False,
    )

    yield storefront

    storefront_service.delete_storefront(storefront.id)


@pytest.fixture
def order(storefront, cart, orderer):
    created_at = datetime(2015, 2, 26, 12, 26, 24)  # UTC

    order, _ = order_service.place_order(
        shop.id, orderer, cart, created_at=created_at
        storefront.id, orderer, cart, created_at=created_at
    )

    yield order


@@ 145,7 162,7 @@ def order(shop, order_number_sequence, cart, orderer):


@freeze_time('2015-04-15 07:54:18')  # UTC
def test_serialize_existing_order(admin_app, shop, order, admin_user):
def test_serialize_existing_order(admin_app, order, admin_user):
    filename = 'testfixtures/shop/order_export.xml'
    with codecs.open(filename, encoding='iso-8859-1') as f:
        expected = f.read().rstrip()


@@ 162,7 179,7 @@ def test_serialize_existing_order(admin_app, shop, order, admin_user):


@freeze_time('2015-04-15 07:54:18')  # UTC
def test_serialize_unknown_order(admin_app, shop, admin_user):
def test_serialize_unknown_order(admin_app, admin_user):
    unknown_order_id = '00000000-0000-0000-0000-000000000000'

    url = f'/admin/shop/orders/{unknown_order_id}/export'

M tests/integration/blueprints/admin/shop/order/test_views.py => tests/integration/blueprints/admin/shop/order/test_views.py +16 -24
@@ 18,7 18,6 @@ from byceps.services.shop.order.transfer.models import (
    PaymentMethod,
    PaymentState,
)
from byceps.services.shop.sequence import service as sequence_service
from byceps.services.user import command_service as user_command_service

from testfixtures.shop_order import create_orderer


@@ 36,15 35,6 @@ from tests.integration.services.shop.helpers import (


@pytest.fixture(scope='module')
def order_number_sequence(shop) -> None:
    sequence_id = sequence_service.create_order_number_sequence(
        shop.id, 'order-'
    )
    yield
    sequence_service.delete_order_number_sequence(sequence_id)


@pytest.fixture(scope='module')
def admin(make_user):
    admin = make_user('ShopOrderAdmin')



@@ 106,16 96,17 @@ def test_cancel_before_paid(
    order_email_service_mock,
    order_canceled_signal_send_mock,
    admin_app,
    shop,
    storefront,
    article1,
    order_number_sequence,
    admin,
    orderer,
):
    article_before = article1

    quantified_articles_to_order = {(article_before, 3)}
    placed_order = place_order(shop.id, orderer, quantified_articles_to_order)
    placed_order = place_order(
        storefront.id, orderer, quantified_articles_to_order
    )
    order_before = get_order(placed_order.id)

    assert article_before.quantity == 5


@@ 159,16 150,17 @@ def test_cancel_before_paid_without_sending_email(
    order_email_service_mock,
    order_canceled_signal_send_mock,
    admin_app,
    shop,
    storefront,
    article2,
    order_number_sequence,
    admin,
    orderer,
):
    article_before = article2

    quantified_articles_to_order = {(article_before, 3)}
    placed_order = place_order(shop.id, orderer, quantified_articles_to_order)
    placed_order = place_order(
        storefront.id, orderer, quantified_articles_to_order
    )

    url = f'/admin/shop/orders/{placed_order.id}/cancel'
    form_data = {


@@ 200,12 192,11 @@ def test_mark_order_as_paid(
    order_email_service_mock,
    order_paid_signal_send_mock,
    admin_app,
    shop,
    order_number_sequence,
    storefront,
    admin,
    orderer,
):
    placed_order = place_order(shop.id, orderer, [])
    placed_order = place_order(storefront.id, orderer, [])
    order_before = get_order(placed_order.id)

    assert_payment_is_open(order_before)


@@ 246,16 237,17 @@ def test_cancel_after_paid(
    order_paid_signal_send_mock,
    order_canceled_signal_send_mock,
    admin_app,
    shop,
    storefront,
    article3,
    order_number_sequence,
    admin,
    orderer,
):
    article_before = article3

    quantified_articles_to_order = {(article_before, 3)}
    placed_order = place_order(shop.id, orderer, quantified_articles_to_order)
    placed_order = place_order(
        storefront.id, orderer, quantified_articles_to_order
    )
    order_before = get_order(placed_order.id)

    assert article_before.quantity == 5


@@ 313,13 305,13 @@ def create_article(shop_id, item_number, quantity):
    )


def place_order(shop_id, orderer, quantified_articles):
def place_order(storefront_id, orderer, quantified_articles):
    cart = Cart()

    for article, quantity_to_order in quantified_articles:
        cart.add_item(article, quantity_to_order)

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

    return order


M tests/integration/blueprints/site/shop/orders/test_views.py => tests/integration/blueprints/site/shop/orders/test_views.py +1 -1
@@ 132,7 132,7 @@ def order(storefront1, user1):
    orderer = create_orderer(user1)
    cart = Cart()

    order, _ = order_service.place_order(storefront1.shop_id, orderer, cart)
    order, _ = order_service.place_order(storefront1.id, orderer, cart)

    yield order


M tests/integration/services/shop/conftest.py => tests/integration/services/shop/conftest.py +26 -9
@@ 8,6 8,7 @@ import pytest
from byceps.services.shop.cart.models import Cart
from byceps.services.shop.sequence import service as sequence_service
from byceps.services.shop.shop import service as shop_service
from byceps.services.shop.storefront import service as storefront_service
from byceps.services.user import command_service as user_command_service

from testfixtures.shop_order import create_orderer


@@ 23,6 24,31 @@ def shop(email_config):


@pytest.fixture
def order_number_sequence_id(shop) -> None:
    sequence_id = sequence_service.create_order_number_sequence(
        shop.id, 'order-'
    )

    yield sequence_id

    sequence_service.delete_order_number_sequence(sequence_id)


@pytest.fixture
def storefront(shop, order_number_sequence_id) -> None:
    storefront = storefront_service.create_storefront(
        f'{shop.id}-storefront',
        shop.id,
        order_number_sequence_id,
        closed=False,
    )

    yield storefront

    storefront_service.delete_storefront(storefront.id)


@pytest.fixture
def orderer():
    user = create_user_with_detail('Besteller')
    yield create_orderer(user)


@@ 32,12 58,3 @@ def orderer():
@pytest.fixture
def empty_cart() -> Cart:
    return Cart()


@pytest.fixture
def order_number_sequence_id(shop) -> None:
    sequence_id = sequence_service.create_order_number_sequence(
        shop.id, 'order-'
    )
    yield sequence_id
    sequence_service.delete_order_number_sequence(sequence_id)

M tests/integration/services/shop/order/actions/base.py => tests/integration/services/shop/order/actions/base.py +2 -2
@@ 13,12 13,12 @@ def get_tickets_for_order(order):
    return ticket_service.find_tickets_created_by_order(order.order_number)


def place_order(shop_id, orderer, articles_with_quantity):
def place_order(storefront_id, orderer, articles_with_quantity):
    cart = Cart()
    for article, quantity in articles_with_quantity:
        cart.add_item(article, quantity)

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

    return order


M tests/integration/services/shop/order/actions/test_create_ticket_bundles.py => tests/integration/services/shop/order/actions/test_create_ticket_bundles.py +2 -3
@@ 14,8 14,7 @@ from .base import get_tickets_for_order, mark_order_as_paid, place_order
def test_create_ticket_bundles(
    admin_app,
    party,
    shop,
    order_number_sequence_id,
    storefront,
    article,
    ticket_category,
    admin_user,


@@ 29,7 28,7 @@ def test_create_ticket_bundles(
    )

    articles_with_quantity = [(article, bundle_quantity)]
    order = place_order(shop.id, orderer, articles_with_quantity)
    order = place_order(storefront.id, orderer, articles_with_quantity)

    tickets_before_paid = get_tickets_for_order(order)
    assert len(tickets_before_paid) == 0

M tests/integration/services/shop/order/actions/test_create_tickets.py => tests/integration/services/shop/order/actions/test_create_tickets.py +2 -3
@@ 14,8 14,7 @@ from .base import get_tickets_for_order, mark_order_as_paid, place_order
def test_create_tickets(
    admin_app,
    party,
    shop,
    order_number_sequence_id,
    storefront,
    article,
    ticket_category,
    admin_user,


@@ 28,7 27,7 @@ def test_create_tickets(
    )

    articles_with_quantity = [(article, ticket_quantity)]
    order = place_order(shop.id, orderer, articles_with_quantity)
    order = place_order(storefront.id, orderer, articles_with_quantity)

    tickets_before_paid = get_tickets_for_order(order)
    assert len(tickets_before_paid) == 0

M tests/integration/services/shop/order/email/base.py => tests/integration/services/shop/order/email/base.py +2 -2
@@ 10,7 10,7 @@ from testfixtures.shop_order import create_orderer


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



@@ 21,7 21,7 @@ def place_order_with_items(
            cart.add_item(article, quantity)

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

    return order

M tests/integration/services/shop/order/email/test_email_on_order_canceled.py => tests/integration/services/shop/order/email/test_email_on_order_canceled.py +28 -5
@@ 11,6 11,7 @@ import pytest
from byceps.services.shop.order.email import service as order_email_service
from byceps.services.shop.order import service as order_service
from byceps.services.shop.sequence import service as sequence_service
from byceps.services.shop.storefront import service as storefront_service
from byceps.services.snippet import service as snippet_service
from byceps.services.user import command_service as user_command_service



@@ 26,29 27,51 @@ def customer(admin_app):
        'Versager', email_address='versager@users.test'
    )
    user_id = user.id

    yield user

    user_command_service.delete_account(user_id, user_id, 'clean up')


@pytest.fixture
def order(shop, customer, order_admin):
    order_number_sequence_id = sequence_service.create_order_number_sequence(
def order_number_sequence_id(shop) -> None:
    sequence_id = sequence_service.create_order_number_sequence(
        shop.id, 'AC-14-B', value=16
    )

    yield sequence_id

    sequence_service.delete_order_number_sequence(sequence_id)


@pytest.fixture
def storefront(shop, order_number_sequence_id) -> None:
    storefront = storefront_service.create_storefront(
        f'{shop.id}-storefront',
        shop.id,
        order_number_sequence_id,
        closed=False,
    )

    yield storefront

    storefront_service.delete_storefront(storefront.id)


@pytest.fixture
def order(storefront, customer, order_admin):
    email_footer_snippet_id = create_email_footer_snippet(
        shop.id, order_admin.id
        storefront.shop_id, order_admin.id
    )

    created_at = datetime(2014, 11, 5, 23, 32, 9)

    order = place_order_with_items(shop.id, customer, created_at, [])
    order = place_order_with_items(storefront.id, customer, created_at, [])

    yield order

    snippet_service.delete_snippet(email_footer_snippet_id)
    order_service.delete_order(order.id)
    sequence_service.delete_order_number_sequence(order_number_sequence_id)


@patch('byceps.email.send')

M tests/integration/services/shop/order/email/test_email_on_order_paid.py => tests/integration/services/shop/order/email/test_email_on_order_paid.py +28 -5
@@ 12,6 12,7 @@ from byceps.services.shop.order.email import service as order_email_service
from byceps.services.shop.order import service as order_service
from byceps.services.shop.order.transfer.models import PaymentMethod
from byceps.services.shop.sequence import service as sequence_service
from byceps.services.shop.storefront import service as storefront_service
from byceps.services.snippet import service as snippet_service
from byceps.services.user import command_service as user_command_service



@@ 27,29 28,51 @@ def customer(admin_app):
        'Vorbild', email_address='vorbild@users.test'
    )
    user_id = user.id

    yield user

    user_command_service.delete_account(user_id, user_id, 'clean up')


@pytest.fixture
def order(shop, customer, order_admin):
    order_number_sequence_id = sequence_service.create_order_number_sequence(
def order_number_sequence_id(shop) -> None:
    sequence_id = sequence_service.create_order_number_sequence(
        shop.id, 'AC-14-B', value=21
    )

    yield sequence_id

    sequence_service.delete_order_number_sequence(sequence_id)


@pytest.fixture
def storefront(shop, order_number_sequence_id) -> None:
    storefront = storefront_service.create_storefront(
        f'{shop.id}-storefront',
        shop.id,
        order_number_sequence_id,
        closed=False,
    )

    yield storefront

    storefront_service.delete_storefront(storefront.id)


@pytest.fixture
def order(storefront, customer, order_admin):
    email_footer_snippet_id = create_email_footer_snippet(
        shop.id, order_admin.id
        storefront.shop_id, order_admin.id
    )

    created_at = datetime(2014, 9, 23, 18, 40, 53)

    order = place_order_with_items(shop.id, customer, created_at, [])
    order = place_order_with_items(storefront.id, customer, created_at, [])

    yield order

    snippet_service.delete_snippet(email_footer_snippet_id)
    order_service.delete_order(order.id)
    sequence_service.delete_order_number_sequence(order_number_sequence_id)


@patch('byceps.email.send')

M tests/integration/services/shop/order/email/test_email_on_order_placed.py => tests/integration/services/shop/order/email/test_email_on_order_placed.py +32 -9
@@ 13,6 13,7 @@ from byceps.services.shop.article import service as article_service
from byceps.services.shop.order.email import service as order_email_service
from byceps.services.shop.order import service as order_service
from byceps.services.shop.sequence import service as sequence_service
from byceps.services.shop.storefront import service as storefront_service
from byceps.services.snippet import service as snippet_service
from byceps.services.user import command_service as user_command_service



@@ 31,11 32,38 @@ def customer(admin_app):
        'Interessent', email_address='interessent@users.test'
    )
    user_id = user.id

    yield user

    user_command_service.delete_account(user_id, user_id, 'clean up')


@pytest.fixture
def order_number_sequence_id(shop) -> None:
    sequence_id = sequence_service.create_order_number_sequence(
        shop.id, 'AC-14-B', value=252
    )

    yield sequence_id

    sequence_service.delete_order_number_sequence(sequence_id)


@pytest.fixture
def storefront(shop, order_number_sequence_id) -> None:
    storefront = storefront_service.create_storefront(
        f'{shop.id}-storefront',
        shop.id,
        order_number_sequence_id,
        closed=False,
    )

    yield storefront

    storefront_service.delete_storefront(storefront.id)


@pytest.fixture
def article1(shop):
    article = create_article(
        shop.id,


@@ 68,16 96,12 @@ def article2(shop):


@pytest.fixture
def order(shop, article1, article2, customer, order_admin):
    order_number_sequence_id = sequence_service.create_order_number_sequence(
        shop.id, 'AC-14-B', value=252
    )

def order(storefront, article1, article2, customer, order_admin):
    email_payment_instructions_snippet_id = create_email_payment_instructions_snippet(
        shop.id, order_admin.id
        storefront.shop_id, order_admin.id
    )
    email_footer_snippet_id = create_email_footer_snippet(
        shop.id, order_admin.id
        storefront.shop_id, order_admin.id
    )

    created_at = datetime(2014, 8, 15, 20, 7, 43)


@@ 88,7 112,7 @@ def order(shop, article1, article2, customer, order_admin):
    ]

    order = place_order_with_items(
        shop.id, customer, created_at, items_with_quantity
        storefront.id, customer, created_at, items_with_quantity
    )

    yield order


@@ 96,7 120,6 @@ def order(shop, article1, article2, customer, order_admin):
    snippet_service.delete_snippet(email_payment_instructions_snippet_id)
    snippet_service.delete_snippet(email_footer_snippet_id)
    order_service.delete_order(order.id)
    sequence_service.delete_order_number_sequence(order_number_sequence_id)


@patch('byceps.email.send')

M tests/integration/services/shop/order/models/test_order_total_amount.py => tests/integration/services/shop/order/models/test_order_total_amount.py +8 -11
@@ 40,18 40,16 @@ def article3(shop):
    article_service.delete_article(article_id)


def test_without_any_items(party_app, shop, order_number_sequence_id, orderer):
    order = place_order(shop.id, orderer, [])
def test_without_any_items(party_app, storefront, orderer):
    order = place_order(storefront.id, orderer, [])

    assert order.total_amount == Decimal('0.00')

    order_service.delete_order(order.id)


def test_with_single_item(
    party_app, shop, order_number_sequence_id, orderer, article1
):
    order = place_order(shop.id, orderer, [
def test_with_single_item(party_app, storefront, orderer, article1):
    order = place_order(storefront.id, orderer, [
        (article1, 1),
    ])



@@ 62,14 60,13 @@ def test_with_single_item(

def test_with_multiple_items(
    party_app,
    shop,
    order_number_sequence_id,
    storefront,
    orderer,
    article1,
    article2,
    article3,
):
    order = place_order(shop.id, orderer, [
    order = place_order(storefront.id, orderer, [
        (article1, 3),
        (article2, 1),
        (article3, 4),


@@ 96,11 93,11 @@ def create_article(shop_id, number, price):
    )


def place_order(shop_id, orderer, articles):
def place_order(storefront_id, orderer, articles):
    cart = Cart()
    for article, quantity in articles:
        cart.add_item(article, quantity)

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

    return order

M tests/integration/services/shop/order/test_ordered_articles_service.py => tests/integration/services/shop/order/test_ordered_articles_service.py +4 -11
@@ 12,7 12,6 @@ from byceps.services.shop.order import ordered_articles_service
from byceps.services.shop.order.models.order import Order as DbOrder
from byceps.services.shop.order import service as order_service
from byceps.services.shop.order.transfer.models import PaymentState
from byceps.services.shop.sequence import service as sequence_service

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



@@ 25,7 24,7 @@ def article(shop):
    article_service.delete_article(article_id)


def test_count_ordered_articles(admin_app, shop, article, orderer):
def test_count_ordered_articles(admin_app, storefront, article, orderer):
    expected = {
        PaymentState.open: 12,
        PaymentState.canceled_before_paid: 7,


@@ 33,10 32,6 @@ def test_count_ordered_articles(admin_app, shop, article, orderer):
        PaymentState.canceled_after_paid: 6,
    }

    order_number_sequence_id = sequence_service.create_order_number_sequence(
        shop.id, 'ABC-01-B'
    )

    order_ids = set()
    for article_quantity, payment_state in [
        (4, PaymentState.open),


@@ 48,7 43,7 @@ def test_count_ordered_articles(admin_app, shop, article, orderer):
        (7, PaymentState.open),
    ]:
        order = place_order(
            shop.id,
            storefront.id,
            orderer,
            article,
            article_quantity,


@@ 65,17 60,15 @@ def test_count_ordered_articles(admin_app, shop, article, orderer):
    for order_id in order_ids:
        order_service.delete_order(order_id)

    sequence_service.delete_order_number_sequence(order_number_sequence_id)


# helpers


def place_order(shop_id, orderer, article, article_quantity):
def place_order(storefront_id, orderer, article, article_quantity):
    cart = Cart()
    cart.add_item(article, article_quantity)

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

    return order


M tests/integration/services/shop/order/test_service_mark_order_as_paid.py => tests/integration/services/shop/order/test_service_mark_order_as_paid.py +2 -2
@@ 14,8 14,8 @@ from byceps.util.iterables import find


@pytest.fixture
def order(admin_app, shop, order_number_sequence_id, orderer, empty_cart):
    order, _ = order_service.place_order(shop.id, orderer, empty_cart)
def order(admin_app, storefront, orderer, empty_cart):
    order, _ = order_service.place_order(storefront.id, orderer, empty_cart)
    yield order
    order_service.delete_order(order.id)


M tests/integration/services/shop/order/test_service_orders_placed_by_user.py => tests/integration/services/shop/order/test_service_orders_placed_by_user.py +36 -15
@@ 9,6 9,7 @@ from byceps.services.shop.cart.models import Cart
from byceps.services.shop.order import service as order_service
from byceps.services.shop.sequence import service as sequence_service
from byceps.services.shop.shop import service as shop_service
from byceps.services.shop.storefront import service as storefront_service
from byceps.services.user import command_service as user_command_service

from testfixtures.shop_order import create_orderer as _create_orderer


@@ 18,27 19,41 @@ from tests.integration.services.shop.helpers import create_shop


@pytest.fixture
def shop1(email_config):
def storefront1(email_config):
    shop = create_shop('first-nice-shop')
    order_number_sequence_id = sequence_service.create_order_number_sequence(
        shop.id, 'LF-02-B'
    )
    storefront = storefront_service.create_storefront(
        f'{shop.id}-storefront',
        shop.id,
        order_number_sequence_id,
        closed=False,
    )

    yield shop
    yield storefront

    storefront_service.delete_storefront(storefront.id)
    sequence_service.delete_order_number_sequence(order_number_sequence_id)
    shop_service.delete_shop(shop.id)


@pytest.fixture
def shop2(email_config):
def storefront2(email_config):
    shop = create_shop('second-nice-shop')
    order_number_sequence_id = sequence_service.create_order_number_sequence(
        shop.id, 'LF-03-B'
    )
    storefront = storefront_service.create_storefront(
        f'{shop.id}-storefront',
        shop.id,
        order_number_sequence_id,
        closed=False,
    )

    yield shop
    yield storefront

    storefront_service.delete_storefront(storefront.id)
    sequence_service.delete_order_number_sequence(order_number_sequence_id)
    shop_service.delete_shop(shop.id)



@@ 46,7 61,9 @@ def shop2(email_config):
@pytest.fixture
def orderer1(admin_app):
    orderer = create_orderer('Orderer1')

    yield orderer

    user_id = orderer.user_id
    user_command_service.delete_account(user_id, user_id, 'clean up')



@@ 54,25 71,29 @@ def orderer1(admin_app):
@pytest.fixture
def orderer2(admin_app):
    orderer = create_orderer('Orderer2')

    yield orderer

    user_id = orderer.user_id
    user_command_service.delete_account(user_id, user_id, 'clean up')


def test_get_orders_placed_by_user(admin_app, shop1, shop2, orderer1, orderer2):
    order1 = place_order(shop1.id, orderer1)
    order2 = place_order(shop1.id, orderer2)  # different user
    order3 = place_order(shop1.id, orderer1)
    order4 = place_order(shop1.id, orderer1)
    order5 = place_order(shop2.id, orderer1)  # different shop
def test_get_orders_placed_by_user(
    admin_app, storefront1, storefront2, orderer1, orderer2
):
    order1 = place_order(storefront1.id, orderer1)
    order2 = place_order(storefront1.id, orderer2)  # different user
    order3 = place_order(storefront1.id, orderer1)
    order4 = place_order(storefront1.id, orderer1)
    order5 = place_order(storefront2.id, orderer1)  # different shop

    orders_orderer1_shop1 = get_orders_by_user(orderer1, shop1.id)
    orders_orderer1_shop1 = get_orders_by_user(orderer1, storefront1.shop_id)
    assert orders_orderer1_shop1 == [order4, order3, order1]

    orders_orderer2_shop1 = get_orders_by_user(orderer2, shop1.id)
    orders_orderer2_shop1 = get_orders_by_user(orderer2, storefront1.shop_id)
    assert orders_orderer2_shop1 == [order2]

    orders_orderer1_shop2 = get_orders_by_user(orderer1, shop2.id)
    orders_orderer1_shop2 = get_orders_by_user(orderer1, storefront2.shop_id)
    assert orders_orderer1_shop2 == [order5]

    for order in order1, order2, order3, order4, order5:


@@ 87,10 108,10 @@ def create_orderer(screen_name):
    return _create_orderer(user)


def place_order(shop_id, orderer):
def place_order(storefront_id, orderer):
    cart = Cart()

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

    return order