Exemple #1
0
    def setUp(self):
        self.cart = Cart()

        self.product = Product()
        self.product.add_product(name="Soup",
                                 price=0.65,
                                 package_type=PackageTypes.TIN.value)
        self.product.add_product(name="Bread",
                                 price=0.80,
                                 package_type=PackageTypes.LOAF.value)
        self.product.add_product(name="Milk",
                                 price=1.3,
                                 package_type=PackageTypes.BOTTLE.value)
        self.product.add_product(name="Apple", price=1.0, package_type="bag")

        self.discount = Discount()
        self.discount.add(
            product=self.product.get_product('Apple'),
            value=10,
            description="Apples have 10% off their normal price this week")

        self.discount.add(
            product=self.product.get_product('Soup'),
            value=50,
            _to=self.product.get_product('Bread'),
            _when_field="qty",
            _when_op="ge",
            _when_value="2",
            description=
            "Buy 2 tins of soup and get a loaf of bread for half price")
def test_create_product():
    name = 'Сплит-система Comfee MSAFA-07HRN1-QC2'
    data = {'price': 12_990, 'quantity': 1}

    product = Product(name, **data)

    assert product.name == name
    for key, val in data.items():
        assert getattr(product, key) == val
def test_product_manager_remove_by_id():
    db = helpers.get_db()

    manager = ProductManager(db)
    product = Product('Сплит-система Comfee MSAFA-07HRN1-QC2',
                      price=12_990,
                      quantity=1)

    manager.add(product)
    manager.remove_by_id(product.id)

    assert len(manager.get_all()) == 0
Exemple #4
0
def test_create_sale():
    product = Product('Сплит-система Comfee MSAFA-07HRN1-QC2',
                      price=12_990,
                      quantity=100)
    quantity = 10

    sale = Sale(product, quantity)

    assert sale.product_id == product.id
    assert sale.name == product.name
    assert sale.price == product.price
    assert sale.quantity == quantity
Exemple #5
0
    def _map_item(self, item):

        product = Product(
            item['name'],
            price=item['price']
        )
        product.id = item['product_id']

        sale = Sale(
            product,
            quantity=item['quantity']
        )
        sale.id = item['id']
        return sale
def test_db_delete():
    db = helpers.get_db()

    manager = ProductManager(db)
    product = Product('Сплит-система Comfee MSAFA-07HRN1-QC2',
                      price=12_990,
                      quantity=1)

    manager.add(product)
    before_deletion = manager.get_all()
    db.delete(manager.table, product.id)
    after_deletion = manager.get_all()

    assert len(before_deletion) == 1
    assert len(after_deletion) == 0
Exemple #7
0
def test_sale_manager_add():
    product = Product('Сплит-система Comfee MSAFA-07HRN1-QC2',
                      price=12_990,
                      quantity=100)
    quantity = 10

    sale = Sale(product, quantity)

    db = helpers.get_db()
    sale_manager = SaleManager(db)
    sale_manager.add(sale)

    results = helpers.extract_ids(sale_manager.get_all())

    assert len(results) == 1
    assert sale.id in results
def test_db_find_by_column():
    db = helpers.get_db()

    product_manager = ProductManager(db)

    comfee_msafa_07 = Product('Сплит-система Comfee MSAFA-07HRN1-QC2',
                              price=12_990,
                              quantity=1)
    product_manager.add(comfee_msafa_07)

    haier_hsu_09 = Product('Сплит-система Haier HSU-09HTM03/R2',
                           price=22_490,
                           quantity=24)
    product_manager.add(haier_hsu_09)

    lg_p_07 = Product('Сплит-система (инвертор) LG P07EP2',
                      price=33_990,
                      quantity=1)
    product_manager.add(lg_p_07)

    haier_as_09 = Product('Сплит-система (инвертор) Haier AS09NA6HRA-S',
                          price=27_990,
                          quantity=24)
    product_manager.add(haier_as_09)

    comfee_msafa_09 = Product(
        'Сплит-система (инвертор) Comfee MSAFA-09HRDN1-QC2F',
        price=22_990,
        quantity=2)
    product_manager.add(comfee_msafa_09)

    lg_pm_09 = Product('Сплит-система (инвертор) LG PM09SP',
                       price=34_990,
                       quantity=6)
    product_manager.add(lg_pm_09)

    comfee_msafb_12 = Product('Сплит-система Comfee MSAFB-12HRN1-QC2',
                              price=20_990,
                              quantity=1)
    product_manager.add(comfee_msafb_12)

    expected = lg_p_07

    results = helpers.extract_ids(
        db.find_by_column(product_manager.table,
                          column='name',
                          value='Сплит-система (инвертор) LG P07EP2'))

    assert expected.id in results
def test_product_manager_add():

    db = helpers.get_db()

    manager = ProductManager(db)
    product = Product('Сплит-система Comfee MSAFA-07HRN1-QC2',
                      price=12_990,
                      quantity=1)

    manager.add(product)

    items = manager.get_all()
    assert len(items) == 1
    assert product.id == items[0].id
    assert product.name == items[0].name
    assert product.price == items[0].price
    assert product.quantity == items[0].quantity
def test_product_manager_search_by_name():
    db = helpers.get_db()

    product_manager = ProductManager(db)

    comfee_msafa_07 = Product('Сплит-система Comfee MSAFA-07HRN1-QC2',
                              price=12_990,
                              quantity=1)
    product_manager.add(comfee_msafa_07)

    haier_hsu_09 = Product('Сплит-система Haier HSU-09HTM03/R2',
                           price=22_490,
                           quantity=24)
    product_manager.add(haier_hsu_09)

    lg_p_07 = Product('Сплит-система (инвертор) LG P07EP2',
                      price=33_990,
                      quantity=1)
    product_manager.add(lg_p_07)

    haier_as_09 = Product('Сплит-система (инвертор) Haier AS09NA6HRA-S',
                          price=27_990,
                          quantity=24)
    product_manager.add(haier_as_09)

    comfee_msafa_09 = Product(
        'Сплит-система (инвертор) Comfee MSAFA-09HRDN1-QC2F',
        price=22_990,
        quantity=2)
    product_manager.add(comfee_msafa_09)

    lg_pm_09 = Product('Сплит-система (инвертор) LG PM09SP',
                       price=34_990,
                       quantity=6)
    product_manager.add(lg_pm_09)

    comfee_msafb_12 = Product('Сплит-система Comfee MSAFB-12HRN1-QC2',
                              price=20_990,
                              quantity=1)
    product_manager.add(comfee_msafb_12)

    expected = [lg_p_07.id, lg_pm_09.id]
    expected.sort()

    results = helpers.extract_ids(product_manager.search_by_name('lg'))
    results.sort()

    assert expected == results
Exemple #11
0
    def products_import():
        nonlocal product_manager
        if 'import-file' not in request.files:
            redirect(url_for('index'))

        importFile = request.files['import-file']
        content = io.StringIO(importFile.read().decode("utf8"))
        reader = csv.reader(content, delimiter=';')
        for line in reader:
            if line[0] != '':
                product_manager.update(line[0],
                                       name=line[1],
                                       price=line[2],
                                       quantity=line[3])
            else:
                product_manager.add(
                    Product(line[1], price=line[2], quantity=line[3]))
        return redirect(url_for('index'))
def test_product_manager_update():
    db = helpers.get_db()

    manager = ProductManager(db)
    product = Product('Сплит-система Comfee MSAFA-07HRN1-QC2',
                      price=12_990,
                      quantity=1)

    data = {'name': 'test name', 'price': 10, 'quantity': 100}

    manager.add(product)
    manager.update(product.id, **data)

    updated_product = manager.search_by_id(product.id)

    assert updated_product.name == data['name']
    assert updated_product.price == data['price']
    assert updated_product.quantity == data['quantity']
Exemple #13
0
 def __init__(self):
     self.category = ""
     self.products = []
     self.products_sub = []
     self.product_selected = []
     self.prod_sub = []
     self.leave_main_menu = 1
     self.leave_category_choice = 1
     self.leave_choice_product = 1
     self.leave_choice_sub = 1
     self.leave_save_sub = 1
     self.first_number = 0
     self.choice_menu = ""
     self.input_product = ""
     self.product_sub = ""
     self.input_product_sub = ""
     self.base = Database()
     self.category_table = Category()
     self.product_table = Product()
     self.substitution_table = Substitution()
def test_product_manager_search_by_id():
    db = helpers.get_db()

    product_manager = ProductManager(db)

    comfee_msafa_07 = Product('Сплит-система Comfee MSAFA-07HRN1-QC2',
                              price=12_990,
                              quantity=1)
    product_manager.add(comfee_msafa_07)

    haier_hsu_09 = Product('Сплит-система Haier HSU-09HTM03/R2',
                           price=22_490,
                           quantity=24)
    product_manager.add(haier_hsu_09)

    lg_p_07 = Product('Сплит-система (инвертор) LG P07EP2',
                      price=33_990,
                      quantity=1)
    product_manager.add(lg_p_07)

    haier_as_09 = Product('Сплит-система (инвертор) Haier AS09NA6HRA-S',
                          price=27_990,
                          quantity=24)
    product_manager.add(haier_as_09)

    comfee_msafa_09 = Product(
        'Сплит-система (инвертор) Comfee MSAFA-09HRDN1-QC2F',
        price=22_990,
        quantity=2)
    product_manager.add(comfee_msafa_09)

    lg_pm_09 = Product('Сплит-система (инвертор) LG PM09SP',
                       price=34_990,
                       quantity=6)
    product_manager.add(lg_pm_09)

    comfee_msafb_12 = Product('Сплит-система Comfee MSAFB-12HRN1-QC2',
                              price=20_990,
                              quantity=1)
    product_manager.add(comfee_msafb_12)

    result = product_manager.search_by_id(lg_pm_09.id)

    assert result.id == lg_pm_09.id
Exemple #15
0
    def product_save(product_id):
        nonlocal product_saved

        name = request.form['name']
        price = request.form['price']
        quantity = request.form['quantity']

        empty_id = str(uuid.UUID(int=0))
        if product_id == empty_id:
            product = Product(name, price=price, quantity=quantity)
            product_manager.add(product)
            product_id = product.id
        else:
            product_manager.update(product_id,
                                   name=name,
                                   price=price,
                                   quantity=quantity)

        product_saved = True
        return redirect(url_for('product_edit', product_id=product_id))
def test_db_update_with_object():
    db = helpers.get_db()

    manager = ProductManager(db)
    product = Product('Сплит-система Comfee MSAFA-07HRN1-QC2',
                      price=12_990,
                      quantity=1)

    manager.add(product)

    product.name = 'test name'
    product.price = 10
    product.quantity = 100

    db.update(manager.table, product)

    updated_product = manager.search_by_id(product.id)

    assert updated_product.name == product.name
    assert updated_product.price == product.price
    assert updated_product.quantity == product.quantity
Exemple #17
0
 def setUp(self):
     self.product = Product()
Exemple #18
0
 def setUp(self):
     self.discount = Discount()
     self.product = Product()
     self.product.add_product(name="Grape", price=1.0, package_type=PackageTypes.TIN.value)
     self.product.add_product(name="Milk", price=2.0, package_type=PackageTypes.BOTTLE.value)
Exemple #19
0
# coding=utf-8

from utils import PackageTypes
from app.product import Product
from app.discount import Discount
from app.cart import Cart

if __name__ == '__main__':
    items = Product()
    items.add_product(name="Soup",
                      price=0.65,
                      package_type=PackageTypes.TIN.value)
    items.add_product(name="Bread",
                      price=0.80,
                      package_type=PackageTypes.LOAF.value)
    items.add_product(name="Milk",
                      price=1.3,
                      package_type=PackageTypes.BOTTLE.value)
    items.add_product(name="Apple",
                      price=1.0,
                      package_type=PackageTypes.BAG.value)

    print("---- Products list")
    print(items.get_list_items())

    discount = Discount()
    discount.add(
        product=items.get_product('Apple'),
        value=10,
        description="Apples have 10% off their normal price this week")
def test_product_manager_sorting():
    db = helpers.get_db()

    product_manager = ProductManager(db)

    product_a = Product('АА', price=10, quantity=1)

    product_b = Product('БА', price=1, quantity=100)

    product_c = Product('ВА', price=100, quantity=10)

    product_manager.add(product_b)
    product_manager.add(product_a)
    product_manager.add(product_c)

    sorting_name_asc = {'column': 'name', 'order': 'ASC'}
    sorting_name_desc = {'column': 'name', 'order': 'DESC'}
    sorting_price_asc = {'column': 'price', 'order': 'ASC'}
    sorting_price_desc = {'column': 'price', 'order': 'DESC'}
    sorting_quantity_asc = {'column': 'quantity', 'order': 'ASC'}
    sorting_quantity_desc = {'column': 'quantity', 'order': 'DESC'}

    expected_name_asc = [product_a.id, product_b.id, product_c.id]
    expected_name_desc = [product_c.id, product_b.id, product_a.id]
    expected_price_asc = [product_b.id, product_a.id, product_c.id]
    expected_price_desc = [product_c.id, product_a.id, product_b.id]
    expected_quantity_asc = [product_a.id, product_c.id, product_b.id]
    expected_quantity_desc = [product_b.id, product_c.id, product_a.id]

    items = helpers.extract_ids(product_manager.get_all(sorting_name_asc))
    assert expected_name_asc == items
    items = helpers.extract_ids(
        product_manager.search_by_name('А', sorting_name_asc))
    assert expected_name_asc == items

    items = helpers.extract_ids(product_manager.get_all(sorting_name_desc))
    assert expected_name_desc == items
    items = helpers.extract_ids(
        product_manager.search_by_name('А', sorting_name_desc))
    assert expected_name_desc == items

    items = helpers.extract_ids(product_manager.get_all(sorting_price_asc))
    assert expected_price_asc == items
    items = helpers.extract_ids(
        product_manager.search_by_name('А', sorting_price_asc))
    assert expected_price_asc == items

    items = helpers.extract_ids(product_manager.get_all(sorting_price_desc))
    assert expected_price_desc == items
    items = helpers.extract_ids(
        product_manager.search_by_name('А', sorting_price_desc))
    assert expected_price_desc == items

    items = helpers.extract_ids(product_manager.get_all(sorting_quantity_asc))
    assert expected_quantity_asc == items
    items = helpers.extract_ids(
        product_manager.search_by_name('А', sorting_quantity_asc))
    assert expected_quantity_asc == items

    items = helpers.extract_ids(product_manager.get_all(sorting_quantity_desc))
    assert expected_quantity_desc == items
    items = helpers.extract_ids(
        product_manager.search_by_name('А', sorting_quantity_desc))
    assert expected_quantity_desc == items