def test_package_edit_view(admin_user, rf, supplier_enabled): shop = get_default_shop() supplier = get_supplier(SimpleSupplierModule.identifier, shop=shop, stock_managed=True) supplier.enabled = supplier_enabled supplier.save() package = create_package_product(printable_gibberish(), shop, supplier) request = apply_all_middleware(rf.get("/"), user=admin_user) response = ProductPackageView.as_view()(request=request, pk=package.pk) product_ids = [] for shop_product in ShopProduct.objects.filter( suppliers=supplier, product__mode=ProductMode.NORMAL): supplier.adjust_stock(product_id=shop_product.product_id, delta=shop_product.product_id) product_ids.append(shop_product.product_id) assert response.status_code == 200 response.render() content = response.content.decode("utf-8") for product_id in product_ids: is_inside = ("Logical count: %s" % product_id) in content assert is_inside == supplier_enabled
def get_bs_object_for_view(request, view, user, object=None): """ Help function to get BeautifulSoup object from the html rendered by the edit view. Also override ``service_provider_admin_form`` here to enable ``PseudoPaymentProcessor`` """ with override_provides("service_provider_admin_form", [ "shuup.testing.service_forms.PseudoPaymentProcessorForm", "shuup.admin.modules.service_providers.forms:CustomCarrierForm", "shuup.admin.modules.service_providers.forms:CustomPaymentProcessorForm" ]): request = apply_all_middleware(request, user=user) response = view(request, pk=object.pk if object else None) if hasattr(response, "render"): response.render() assert response.status_code in [200, 302] return BeautifulSoup(response.content)
def test_package_edit_view(admin_user, rf, supplier_enabled): shop = get_default_shop() supplier = get_supplier(SimpleSupplierModule.identifier, shop=shop, stock_managed=True) supplier.enabled = supplier_enabled supplier.save() package = create_package_product(printable_gibberish(), shop, supplier) request = apply_all_middleware(rf.get("/"), user=admin_user) response = ProductPackageView.as_view()(request=request, pk=package.pk) product_ids = [] for shop_product in ShopProduct.objects.filter(suppliers=supplier, product__mode=ProductMode.NORMAL): supplier.adjust_stock(product_id=shop_product.product_id, delta=shop_product.product_id) product_ids.append(shop_product.product_id) assert response.status_code == 200 response.render() content = response.content.decode("utf-8") for product_id in product_ids: is_inside = ("Logical count: %s" % product_id) in content assert is_inside == supplier_enabled