Test Failed
Push — main ( 2ac75e...34ff35 )
by Jochen
08:37
created

test_add_item_with_cart_currency()   A

Complexity

Conditions 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
"""
2
:Copyright: 2014-2022 Jochen Kupperschmidt
3
:License: Revised BSD (see `LICENSE` file for details)
4
"""
5
6
from decimal import Decimal
7
8
from moneyed import EUR, Money, USD
9
from pytest import raises
10
11
from byceps.database import generate_uuid
12
from byceps.services.shop.article.transfer.models import (
13
    Article,
14
    ArticleID,
15
    ArticleNumber,
16
    ArticleType,
17
)
18
from byceps.services.shop.cart.models import Cart
19
from byceps.services.shop.shop.transfer.models import ShopID
20
21
22
def test_add_item_with_cart_currency():
23
    cart = Cart(EUR)
24
    article = create_article()
25
26
    cart.add_item(article, 1)
27
28
    assert not cart.is_empty()
29
30
31
def test_add_item_with_different_currency():
32
    cart = Cart(USD)
33
    article = create_article()
34
35
    with raises(ValueError):
36
        cart.add_item(article, 1)
37
38
39
# helpers
40
41
42 View Code Duplication
def create_article() -> Article:
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
43
    return Article(
44
        id=ArticleID(generate_uuid()),
45
        shop_id=ShopID('any-shop'),
46
        item_number=ArticleNumber('article-123'),
47
        type_=ArticleType.other,
48
        type_params={},
49
        description='Cool thing',
50
        price=Money('1.99', EUR),
51
        tax_rate=Decimal('0.19'),
52
        available_from=None,
53
        available_until=None,
54
        total_quantity=1,
55
        quantity=1,
56
        max_quantity_per_order=1,
57
        not_directly_orderable=False,
58
        separate_order_required=False,
59
        processing_required=False,
60
    )
61