示例#1
0
def products():
    return {
        'soup': product.Product('soup', 65, 'tin'),
        'bread': product.Product('bread', 80, 'loaf'),
        'milk': product.Product('milk', 130, 'bottle'),
        'apples': product.Product('apples', 100, 'bag'),
    }
示例#2
0
def load_products(products_file_path):
    """Load product definitions.

    Load product definition data describing the products this program will
    accept including product names, units and price.

    :param str products_file_path: Path to goods file.
    :return dict: Dictionary of product.Product instances.
    """
    products = {}
    data = load_json(products_file_path)
    if data is None:
        logger.log('No stock found in product data')
    else:
        # Build products list
        for prod in data:
            try:
                p = product.Product(prod['name'], prod['price'], prod['unit'],
                                    prod['active'])
                if p.active:
                    products[p.name] = p
            except ValueError as e:
                logger.log(f'Failed to load a product with data: {prod} ({e})',
                           SimpleLogger.error)
    return products
示例#3
0
def test_apply_offer_pounds(prod_promo):
    prod = product.Product('apples', 100, 'bag')
    prod_promo.discount_percent = 100
    prod.apply_promotion(prod_promo)
    assert prod.discounted_price == 0
    assert prod.discount_amount == 100
    assert 'Apples 10% off: -£1.00' in prod.discount_message
示例#4
0
def test_apply_promo(prod_promo):
    prod = product.Product('apples', 100, 'bag')
    prod.apply_promotion(prod_promo)
    assert prod._promotion is prod_promo
    assert prod.has_promotion is True
    assert prod.discounted_price == 90
    assert prod.discount_amount == 10
    assert 'Apples 10% off: -10p' in prod.discount_message
示例#5
0
def test_clear_promo(prod_promo):
    prod = product.Product('apples', 100, 'bag')
    prod.apply_promotion(prod_promo)
    assert prod._promotion is prod_promo
    prod.clear_promotion()
    assert not prod.has_promotion
    assert prod.discounted_price == 100
    assert prod.discount_amount == 0
    assert prod.discount_message is None
示例#6
0
def test_prod(name, price, unit):
    prod = product.Product(name, price, unit)
    assert prod.name == 'appels'
    assert prod.price == 100
    assert prod.unit == 'bag'