def test_product_variant_edit_with_products_set_name_read_only(client, web2py): """ Is the name of a variant read only when it comes from a products set? """ from populate_os_tables import populate_shop_products_variants populate_shop_products_variants(web2py, populate_products_sets=True) url = '/shop_manage/product_variant_edit?spID=1&spvID=1' client.get(url) assert client.status == 200 assert 'form="MainForm" id="shop_products_variants_Name"' not in client.text
def test_product_variants_no_products_set(client, web2py): """ Is the delete message saying "disable" for products without a set? """ from populate_os_tables import populate_shop_products_variants populate_shop_products_variants(web2py) url = '/shop_manage/product_variants?spID=1' client.get(url) assert client.status == 200 assert "Do you really want to delete this variant" in client.text assert "Add" in client.text
def test_product_variant_disable(client, web2py): """ Can we disable a variant This function will disable when a variant is linked to a product set """ from populate_os_tables import populate_shop_products_variants populate_shop_products_variants(web2py, populate_products_sets=True) url = '/shop_manage/product_variant_delete?spID=1&spvID=1' client.get(url) assert client.status == 200 variant = web2py.db.shop_products_variants(1) assert variant.Enabled == False
def test_products_set_options_remove_add_and_del_when_linked_to_product( client, web2py): """ We shouldn't be able to add options when the set is linked to one or more products """ from populate_os_tables import populate_shop_products_variants populate_shop_products_variants(web2py, populate_products_sets=True) url = '/shop_manage/products_set_options?spsID=1' client.get(url) assert client.status == 200 assert "Add option" not in client.text assert 'shop_products_sets_options_delete' not in client.text
def test_product_variant_set_default(client, web2py): """ Can we set a variant is default? """ from populate_os_tables import populate_shop_products_variants populate_shop_products_variants(web2py) url = '/shop_manage/product_variant_set_default?spID=1&spvID=2' client.get(url) assert client.status == 200 variant_1 = web2py.db.shop_products_variants(1) variant_2 = web2py.db.shop_products_variants(2) assert variant_1.DefaultVariant == False assert variant_2.DefaultVariant == True
def test_product_variant_delete(client, web2py): """ Can we delete a variant? This function will delete when a variant is not linked to a product set """ from populate_os_tables import populate_shop_products_variants populate_shop_products_variants(web2py) count_variants = web2py.db(web2py.db.shop_products_variants).count() url = '/shop_manage/product_variant_delete?spID=1&spvID=1' client.get(url) assert client.status == 200 assert web2py.db( web2py.db.shop_products_variants).count() == count_variants - 1
def test_product_variants(client, web2py): """ Can we list product variants? """ from populate_os_tables import populate_shop_products_variants populate_shop_products_variants(web2py, populate_products=True) assert web2py.db(web2py.db.shop_products_variants).count() == 2 url = '/shop_manage/product_variants?spID=1' client.get(url) assert client.status == 200 variant = web2py.db.shop_products_variants(1) assert variant.Name in client.text # Check disabling the button for the default variant assert 'disabled="disabled" href="#" id="" onclick=""' in client.text
def test_product_variant_enable(client, web2py): """ Can we enable a variant """ from populate_os_tables import populate_shop_products_variants populate_shop_products_variants(web2py, populate_products_sets=True) variant = web2py.db.shop_products_variants(1) variant.Enabled = False variant.update_record() web2py.db.commit() url = '/shop_manage/product_variant_enable?spID=1&spvID=1' client.get(url) assert client.status == 200 variant = web2py.db.shop_products_variants(1) assert variant.Enabled == True
def test_product_variant_edit(client, web2py): """ Can we edit a product variant """ from populate_os_tables import populate_shop_products_variants populate_shop_products_variants(web2py, populate_products=True) assert web2py.db(web2py.db.shop_products_variants).count() == 2 url = '/shop_manage/product_variant_edit?spID=1&spvID=1' client.get(url) assert client.status == 200 data = {'id': '1', 'Name': 'Grapefruit', 'tax_rates_id': 1} client.post(url, data=data) assert client.status == 200 variant = web2py.db.shop_products_variants(1) assert variant.Name == data['Name']
def test_product_variants_with_products_set(client, web2py): """ Is the delete message saying "disable" for products with a set? """ from populate_os_tables import populate_shop_products_sets from populate_os_tables import populate_shop_products_variants populate_shop_products_sets(web2py) populate_shop_products_variants(web2py) product = web2py.db.shop_products(1) product.shop_products_sets_id = 1 product.update_record() web2py.db.commit() url = '/shop_manage/product_variants?spID=1' client.get(url) assert client.status == 200 assert "Do you really want to disable this variant" in client.text assert '<a class="btn btn-default btn-sm" href="/shop_manage/product_variant_add?spID=2" id="" style="" target="" title=""><span class="fa fa-plus"></span> Add</a>' not in client.text
def test_products_set_options_value_add_update_variants(client, web2py): """ Can we add an option value? """ from populate_os_tables import populate_shop_products_variants populate_shop_products_variants(web2py, populate_products_sets=True) count_variants = web2py.db(web2py.db.shop_products_variants).count() url = '/shop_manage/products_set_options?spsID=1' client.get(url) assert client.status == 200 data = { 'shop_products_sets_options_id': 1, 'Name': 'Banana Value', '_formname': 'shop_products_sets_options_values/None' } client.post(url, data=data) assert client.status == 200 assert web2py.db(web2py.db.shop_products_variants).count() > count_variants query = (web2py.db.shop_products_variants.Enabled == False) assert web2py.db(query).count() > 0