Пример #1
0
def prod_promo():
    promo_def = {'id': 1,
                 'title': 'Apples 10% off',
                 'qualifying_product': 'apples',
                 'qualifying_qty': 1,
                 'discounted_product': 'apples',
                 'discount_percent': 10}
    return promotion.Promotion(promo_def)
Пример #2
0
def test_bad_offer():
    promo_def = {'id': 1,
                 'title': 'Apples 10% off',
                 'qualifying_product': 'Apples',
                 'qualifying_qty': 0,
                 'discounted_product': 'Apples',
                 'discount_percent': 10}
    with pytest.raises(ValueError) as e:
        promotion.Promotion(promo_def)
    assert 'Unacceptable value for qualifying_qty' in str(e)
Пример #3
0
def test_offer(qualifying_product, qualifying_qty, discounted_product,
               discount_percent):
    offer_def = {'id': 1,
                 'title': 'Apples 10% off',
                 'qualifying_product': qualifying_product,
                 'qualifying_qty': qualifying_qty,
                 'discounted_product': discounted_product,
                 'discount_percent': discount_percent}
    p = promotion.Promotion(offer_def)
    assert p.promo_id == 1
    assert p.title == 'Apples 10% off'
    assert p.qualifying_product == 'apples'
    assert p.qualifying_qty == 1
    assert p.discounted_product == 'apples'
    assert p.discount_percent == 10
Пример #4
0
def load_promotions(promotions_file_path):
    """Load promotions.

    Load promotions data that specifies discounts that can be applied
    to goods purchased.

    :param str promotions_file_path: Path to promotions file.
    :return list: List of promotion.Promotion instances.
    """
    promotions = []
    data = load_json(promotions_file_path)
    if data:
        for prod_promo in data:
            try:
                promotions.append(promotion.Promotion(prod_promo))
            except (ValueError, KeyError) as e:
                logger.log(
                    'Failed to load offer with data: '
                    f'{prod_promo} ({e})', SimpleLogger.error)
    return promotions
Пример #5
0
def promotions(promo_def):
    return [promotion.Promotion(promo_def)]