def test_suppliers_edit(rf, admin_user, manage_stock, stock_module): shop = factories.get_default_shop() edit_view = SupplierEditView.as_view() staff_user = factories.create_random_user("en", is_staff=True) shop.staff_members.add(staff_user) with override_settings(SHUUP_ENABLE_MULTIPLE_SUPPLIERS=True): for index, user in enumerate([admin_user, staff_user]): payload = { "base-name": "Supplier Name %d" % index, "base-description__en": "Supplier Description %d" % index, "base-type": SupplierType.INTERNAL.value, "base-stock_managed": manage_stock, "base-supplier_modules": stock_module, "base-shops": shop.pk, "base-enabled": "on", "base-logo": "", "address-name": "Address Name %d" % index, "address-email": "*****@*****.**", "address-phone": "23742578329", "address-tax_number": "ABC123", "address-street": "Streetz", "address-postal_code": "90014", "address-city": "Los Angeles", "address-region_code": "CA", "address-country": "US", } if manage_stock and not stock_module: request = apply_request_middleware(rf.post("/", payload), user=user) response = edit_view(request) response.render() assert bool( "It is not possible to manage inventory when no module is selected." in response.content.decode()) assert response.status_code == 200 else: request = apply_request_middleware(rf.post("/", payload), user=user) response = edit_view(request) assert response.status_code == 302 supplier = Supplier.objects.last() assert response.url == reverse("shuup_admin:supplier.edit", kwargs=dict(pk=supplier.pk)) assert supplier.name == payload["base-name"] assert supplier.slug == slugify(supplier.name) assert supplier.description == payload["base-description__en"] assert supplier.shops.count() == 1 assert supplier.enabled assert supplier.contact_address.name == payload["address-name"] request = apply_request_middleware(rf.get("/"), user=user) response = edit_view(request, **{"pk": supplier.pk}) assert response.status_code == 200
def test_supplier_changed_reindex_catalog(rf, admin_user): shop = factories.get_default_shop() supplier = factories.get_default_supplier(shop) supplier.stock_managed = True supplier.save() product = factories.create_product("p1", shop, supplier, default_price=Decimal("10")) supplier.adjust_stock(product.pk, 40) # add 40 to the stock ProductCatalog.index_product(product) catalog = ProductCatalog(ProductCatalogContext(purchasable_only=True)) assert product in catalog.get_products_queryset() # disable the supplier edit_view = SupplierEditView.as_view() payload = { "base-name": supplier.name, "base-description__en": "", "base-type": SupplierType.INTERNAL.value, "base-stock_managed": True, "base-supplier_modules": [supplier.supplier_modules.first().pk], "base-shops": shop.pk, "base-enabled": "", "base-logo": "", "address-name": "Address Name", "address-email": "*****@*****.**", "address-phone": "23742578329", "address-tax_number": "ABC123", "address-street": "Streetz", "address-postal_code": "90014", "address-city": "Los Angeles", "address-region_code": "CA", "address-country": "US", } request = apply_request_middleware(rf.post("/", payload), user=admin_user) response = edit_view(request, pk=supplier.pk) assert response.status_code == 302 supplier.refresh_from_db() assert not supplier.enabled # product is not available anymore assert product not in catalog.get_products_queryset()
def test_suppliers_edit(rf, admin_user): shop = factories.get_default_shop() edit_view = SupplierEditView.as_view() staff_user = factories.create_random_user("en", is_staff=True) shop.staff_members.add(staff_user) with override_settings(SHUUP_ENABLE_MULTIPLE_SUPPLIERS=True): for index, user in enumerate([admin_user, staff_user]): payload = { "base-name": "Supplier Name %d" % index, "base-description__en": "Supplier Description %d" % index, "base-type": SupplierType.INTERNAL.value, "base-module_identifier": "", "base-shops": shop.pk, "base-enabled": "on", "base-logo": "", "base-is_approved": "on", "address-name": "Address Name %d" % index, "address-email": "*****@*****.**", "address-phone": "23742578329", "address-tax_number": "ABC123", "address-street": "Streetz", "address-postal_code": "90014", "address-city": "Los Angeles", "address-region_code": "CA", "address-country": "US" } request = apply_request_middleware(rf.post("/", payload), user=user) response = edit_view(request) assert response.status_code == 302 sup = Supplier.objects.last() assert response.url == reverse("shuup_admin:supplier.edit", kwargs=dict(pk=sup.pk)) assert sup.name == payload["base-name"] assert sup.description == payload["base-description__en"] assert sup.shops.count() == 1 assert sup.enabled assert sup.is_approved assert sup.contact_address.name == payload["address-name"]
def test_supplier_create(rf, admin_user): shop = factories.get_default_shop() edit_view = SupplierEditView.as_view() request = apply_request_middleware(rf.get("/"), user=admin_user) response = edit_view(request, **{"pk": None}) assert response.status_code == 200