本文整理汇总了Python中shoop.testing.factories.get_default_supplier函数的典型用法代码示例。如果您正苦于以下问题:Python get_default_supplier函数的具体用法?Python get_default_supplier怎么用?Python get_default_supplier使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_default_supplier函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_frontend_order_state
def get_frontend_order_state(contact, valid_lines=True):
"""
Get a dict structure mirroring what the frontend JavaScript would submit.
:type contact: Contact|None
"""
translation.activate("en")
shop = get_default_shop()
tax = Tax.objects.create(code="test_code", rate=decimal.Decimal("0.20"), name="Default")
tax_class = TaxClass.objects.create(identifier="test_tax_class", name="Default")
rule = TaxRule.objects.create(tax=tax)
rule.tax_classes.add(tax_class)
rule.save()
product = create_product(
sku=printable_gibberish(),
supplier=get_default_supplier(),
shop=shop
)
product.tax_class = tax_class
product.save()
if valid_lines:
lines = [
{"id": "x", "type": "product", "product": {"id": product.id}, "quantity": "32", "baseUnitPrice": 50},
{"id": "y", "type": "other", "sku": "hello", "text": "A greeting", "quantity": 1, "unitPrice": "5.5"},
{"id": "z", "type": "text", "text": "This was an order!", "quantity": 0},
]
else:
unshopped_product = create_product(sku=printable_gibberish(), supplier=get_default_supplier())
not_visible_product = create_product(
sku=printable_gibberish(),
supplier=get_default_supplier(),
shop=shop
)
not_visible_shop_product = not_visible_product.get_shop_instance(shop)
not_visible_shop_product.visible = False
not_visible_shop_product.save()
lines = [
{"id": "x", "type": "product"}, # no product?
{"id": "x", "type": "product", "product": {"id": unshopped_product.id}}, # not in this shop?
{"id": "y", "type": "product", "product": {"id": -product.id}}, # invalid product?
{"id": "z", "type": "other", "quantity": 1, "unitPrice": "q"}, # what's that price?
{"id": "rr", "type": "product", "quantity": 1, "product": {"id": not_visible_product.id}} # not visible
]
state = {
"customer": {"id": contact.id if contact else None},
"lines": lines,
"methods": {
"shippingMethod": {"id": get_default_shipping_method().id},
"paymentMethod": {"id": get_default_payment_method().id},
},
"shop": {
"selected": {
"id": shop.id,
"name": shop.name,
"currency": shop.currency,
"priceIncludeTaxes": shop.prices_include_tax
}
}
}
return state
示例2: seed_default
def seed_default(self):
migrator = MigrateCommand()
migrator.stdout = self.stdout
migrator.handle(database="default", verbosity=1, noinput=True, app_label=None, migration_name=None)
if not Shop.objects.exists():
Shop.objects.create(name="B2B", identifier="b2b", status=ShopStatus.ENABLED)
try:
tax_class = TaxClass.objects.create(identifier="default", tax_rate=0)
except:
tax_class = TaxClass.objects.create(identifier="default")
PaymentMethod.objects.create(identifier="default", name="Invoice", tax_class=tax_class)
PaymentMethod.objects.create(identifier="bank_xfer", name="Bank Transfer", tax_class=tax_class)
PaymentMethod.objects.create(identifier="cash", name="Cash (Pickup Only)", tax_class=tax_class)
ShippingMethod.objects.create(identifier="default", name="Post Parcel", tax_class=tax_class)
ShippingMethod.objects.create(identifier="pickup", name="Pickup at Helsinki Store", tax_class=tax_class)
create_default_order_statuses()
get_default_supplier()
ProductType.objects.create(identifier="default")
SalesUnit.objects.create(identifier="pcs", short_name="pcs", name="pieces")
print("Seeded basic shop information")
if not User.objects.filter(is_superuser=True).exists():
User.objects.create_superuser(
username="admin",
email="[email protected]",
password="admin",
)
print("Superuser created: admin / admin")
示例3: test_package
def test_package():
shop = get_default_shop()
supplier = get_default_supplier()
package_product = create_product("PackageParent", shop=shop, supplier=supplier)
assert not package_product.get_package_child_to_quantity_map()
children = [create_product("PackageChild-%d" % x, shop=shop, supplier=supplier) for x in range(4)]
package_def = {child: 1 + i for (i, child) in enumerate(children)}
package_product.make_package(package_def)
assert package_product.mode == ProductMode.PACKAGE_PARENT
package_product.save()
sp = package_product.get_shop_instance(shop)
assert not list(sp.get_orderability_errors(supplier=supplier, quantity=1, customer=AnonymousContact()))
with pytest.raises(ValueError): # Test re-packaging fails
package_product.make_package(package_def)
# Check that OrderCreator can deal with packages
source = BasketishOrderSource()
source.lines.append(SourceLine(
type=OrderLineType.PRODUCT,
product=package_product,
supplier=get_default_supplier(),
quantity=10,
unit_price=TaxlessPrice(10),
))
source.shop = get_default_shop()
source.status = get_initial_order_status()
creator = OrderCreator(request=None)
order = creator.create_order(source)
pids_to_quantities = order.get_product_ids_and_quantities()
for child, quantity in six.iteritems(package_def):
assert pids_to_quantities[child.pk] == 10 * quantity
示例4: test_order_source_parentage
def test_order_source_parentage(rf, admin_user):
source = seed_source(admin_user)
product = get_default_product()
source.add_line(
type=OrderLineType.PRODUCT,
product=product,
supplier=get_default_supplier(),
quantity=1,
base_unit_price=source.create_price(10),
line_id="parent"
)
source.add_line(
type=OrderLineType.OTHER,
text="Child Line",
sku="KIDKIDKID",
quantity=1,
base_unit_price=source.create_price(5),
parent_line_id="parent"
)
request = apply_request_middleware(rf.get("/"))
creator = OrderCreator(request)
order = Order.objects.get(pk=creator.create_order(source).pk)
kid_line = order.lines.filter(sku="KIDKIDKID").first()
assert kid_line
assert kid_line.parent_line.product_id == product.pk
示例5: test_order_creator
def test_order_creator(rf, admin_user):
source = seed_source(admin_user)
source.add_line(
type=OrderLineType.PRODUCT,
product=get_default_product(),
supplier=get_default_supplier(),
quantity=1,
base_unit_price=source.create_price(10),
)
source.add_line(
type=OrderLineType.OTHER,
quantity=1,
base_unit_price=source.create_price(10),
require_verification=True,
)
request = apply_request_middleware(rf.get("/"))
creator = OrderCreator(request)
order = creator.create_order(source)
assert get_data_dict(source.billing_address) == get_data_dict(order.billing_address)
assert get_data_dict(source.shipping_address) == get_data_dict(order.shipping_address)
assert source.customer == order.customer
assert source.payment_method == order.payment_method
assert source.shipping_method == order.shipping_method
assert order.pk
示例6: test_basket_shipping_error
def test_basket_shipping_error(rf):
StoredBasket.objects.all().delete()
shop = get_default_shop()
supplier = get_default_supplier()
shipped_product = create_product(
printable_gibberish(), shop=shop, supplier=supplier, default_price=50,
shipping_mode=ShippingMode.SHIPPED
)
unshipped_product = create_product(
printable_gibberish(), shop=shop, supplier=supplier, default_price=50,
shipping_mode=ShippingMode.NOT_SHIPPED
)
request = rf.get("/")
request.session = {}
request.shop = shop
apply_request_middleware(request)
basket = get_basket(request)
# With a shipped product but no shipping methods, we oughta get an error
basket.add_product(supplier=supplier, shop=shop, product=shipped_product, quantity=1)
assert any(ve.code == "no_common_shipping" for ve in basket.get_validation_errors())
basket.clear_all()
# But with an unshipped product, we should not
basket.add_product(supplier=supplier, shop=shop, product=unshipped_product, quantity=1)
assert not any(ve.code == "no_common_shipping" for ve in basket.get_validation_errors())
示例7: _get_frontend_order_state
def _get_frontend_order_state(shop, contact):
tax = Tax.objects.create(code="test_code", rate=decimal.Decimal("0.20"), name="Default")
tax_class = TaxClass.objects.create(identifier="test_tax_class", name="Default")
rule = TaxRule.objects.create(tax=tax)
rule.tax_classes.add(tax_class)
rule.save()
product = create_product(
sku=printable_gibberish(),
supplier=get_default_supplier(),
shop=shop
)
product.tax_class = tax_class
product.save()
lines = [
{"id": "x", "type": "product", "product": {"id": product.id}, "quantity": "32", "baseUnitPrice": 50}
]
state = {
"customer": {"id": contact.id if contact else None},
"lines": lines,
"methods": {
"shippingMethod": {"id": get_shipping_method(shop=shop).id},
"paymentMethod": {"id": get_payment_method(shop=shop).id},
},
"shop": {
"selected": {
"id": shop.id,
"name": shop.safe_translation_getter("name"),
"currency": shop.currency,
"priceIncludeTaxes": shop.prices_include_tax
}
}
}
return state
示例8: test_percentage_campaign
def test_percentage_campaign(rf):
request, shop, group = initialize_test(rf, False)
price = shop.create_price
basket = get_basket(request)
supplier = get_default_supplier()
# create a basket rule that requires atleast value of 200
rule = BasketTotalAmountCondition.objects.create(value="200")
product_price = "200"
discount_percentage = "0.1"
expected_discounted_price = price(product_price) - (price(product_price) * Decimal(discount_percentage))
product = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price=product_price)
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
campaign = BasketCampaign.objects.create(
shop=shop, public_name="test", name="test", discount_percentage=discount_percentage, active=True
)
campaign.conditions.add(rule)
campaign.save()
assert len(basket.get_final_lines()) == 2
assert basket.product_count == 1
assert basket.total_price == expected_discounted_price
示例9: test_form_populate_initial_data
def test_form_populate_initial_data(rf, admin_user):
shop = get_default_shop()
supplier = get_default_supplier()
initial_discount_amount = 20
campaign = BasketCampaign.objects.create(shop=shop)
BasketDiscountAmount.objects.create(campaign=campaign, discount_amount=initial_discount_amount)
# Test that correct initial value is returned for non-many-to-many field
product_amount_initial = 10
product_amount_condition = BasketTotalProductAmountCondition(product_count=product_amount_initial)
product_amount_condition.save()
campaign.conditions.add(product_amount_condition)
products_count_initial = 5
for i in range(products_count_initial):
create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price="20")
products_initial = Product.objects.all()[:products_count_initial]
assert len(products_initial) == products_count_initial
# Test that correct initial value is returned for many-to-many field
products_in_basket_condition = ProductsInBasketCondition.objects.create()
products_in_basket_condition.values = products_initial
products_in_basket_condition.save()
campaign.conditions.add(products_in_basket_condition)
assert len(campaign.conditions.all()) == 2
assert campaign.effects.count() == 1
request=apply_request_middleware(rf.get("/"), user=admin_user)
form = BasketCampaignForm(request=request, instance=campaign)
assert form.fields["basket_product_condition"].initial == product_amount_initial
assert set(form.fields["basket_products_condition"].initial) == set([p.pk for p in products_initial])
assert form.fields["discount_amount_effect"].initial == initial_discount_amount
示例10: test_basket_campaign_module_case1
def test_basket_campaign_module_case1(rf):
request, shop, group = initialize_test(rf, False)
price = shop.create_price
basket = get_basket(request)
supplier = get_default_supplier()
single_product_price = "50"
discount_amount_value = "10"
# create basket rule that requires 2 products in basket
basket_rule1 = BasketTotalProductAmountCondition.objects.create(value="2")
product = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price=single_product_price)
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
basket.save()
assert basket.product_count == 1
campaign = BasketCampaign.objects.create(
shop=shop, public_name="test", name="test", discount_amount_value=discount_amount_value, active=True)
campaign.conditions.add(basket_rule1)
campaign.save()
assert len(basket.get_final_lines()) == 1 # case 1
assert basket.total_price == price(single_product_price) # case 1
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
basket.save()
assert len(basket.get_final_lines()) == 2 # case 1
assert basket.product_count == 2
assert basket.total_price == (price(single_product_price) * basket.product_count - price(discount_amount_value))
assert OrderLineType.DISCOUNT in [l.type for l in basket.get_final_lines()]
示例11: get_order_and_source
def get_order_and_source(admin_user):
# create original source to tamper with
source = BasketishOrderSource(get_default_shop())
source.status = get_initial_order_status()
source.billing_address = MutableAddress.objects.create(name="Original Billing")
source.shipping_address = MutableAddress.objects.create(name="Original Shipping")
source.customer = get_person_contact(admin_user)
source.payment_method = get_default_payment_method()
source.shipping_method = get_default_shipping_method()
source.add_line(
type=OrderLineType.PRODUCT,
product=get_default_product(),
supplier=get_default_supplier(),
quantity=1,
base_unit_price=source.create_price(10),
)
source.add_line(
type=OrderLineType.OTHER,
quantity=1,
base_unit_price=source.create_price(10),
require_verification=True,
)
assert len(source.get_lines()) == 2
source.creator = admin_user
creator = OrderCreator()
order = creator.create_order(source)
return order, source
示例12: __init__
def __init__(self, image_dir):
self.image_dir = image_dir
self.supplier = get_default_supplier()
self.sales_unit = SalesUnit.objects.first()
self.tax_class = TaxClass.objects.first()
self.product_type = ProductType.objects.first()
self.shop = Shop.objects.first()
示例13: test_tracking_codes
def test_tracking_codes():
product = get_default_product()
supplier = get_default_supplier()
order = create_order_with_product(
product,
supplier=supplier,
quantity=1,
taxless_base_unit_price=10,
tax_rate=decimal.Decimal("0.5")
)
_add_product_to_order(order, "duck-tape-1", 3, order.shop, supplier)
_add_product_to_order(order, "water-1", 2, order.shop, supplier)
order.cache_prices()
order.check_all_verified()
order.save()
# Create shipment with tracking code for every product line.
product_lines = order.lines.exclude(product_id=None)
assert len(product_lines) == 3
for line in product_lines:
shipment = order.create_shipment(supplier, {line.product: line.quantity})
if line.quantity != 3:
shipment.tracking_code = "123FI"
shipment.save()
tracking_codes = order.get_tracking_codes()
code_count = (len(product_lines)-1) # We skipped that one
assert len(tracking_codes) == code_count
assert len([tracking_code for tracking_code in tracking_codes if tracking_code == "123FI"]) == code_count
示例14: test_best_selling_products_with_multiple_orders
def test_best_selling_products_with_multiple_orders():
context = get_jinja_context()
supplier = get_default_supplier()
shop = get_default_shop()
n_products = 2
price = 10
product_1 = create_product("test-sku-1", supplier=supplier, shop=shop)
product_2 = create_product("test-sku-2", supplier=supplier, shop=shop)
create_order_with_product(product_1, supplier, quantity=1, taxless_base_unit_price=price, shop=shop)
create_order_with_product(product_2, supplier, quantity=1, taxless_base_unit_price=price, shop=shop)
cache.clear()
# Two initial products sold
assert product_1 in general.get_best_selling_products(context, n_products=n_products)
assert product_2 in general.get_best_selling_products(context, n_products=n_products)
product_3 = create_product("test-sku-3", supplier=supplier, shop=shop)
create_order_with_product(product_3, supplier, quantity=2, taxless_base_unit_price=price, shop=shop)
cache.clear()
# Third product sold in greater quantity
assert product_3 in general.get_best_selling_products(context, n_products=n_products)
create_order_with_product(product_1, supplier, quantity=4, taxless_base_unit_price=price, shop=shop)
create_order_with_product(product_2, supplier, quantity=4, taxless_base_unit_price=price, shop=shop)
cache.clear()
# Third product outsold by first two products
assert product_3 not in general.get_best_selling_products(context, n_products=n_products)
示例15: test_protected_fields
def test_protected_fields():
activate("en")
shop = Shop.objects.create(
name="testshop",
identifier="testshop",
status=ShopStatus.ENABLED,
public_name="test shop",
domain="derp",
currency="EUR"
)
assert shop.name == "testshop"
assert shop.currency == "EUR"
shop_form = ShopBaseForm(instance=shop, languages=settings.LANGUAGES)
assert not shop_form._get_protected_fields() # No protected fields just yet, right?
data = get_form_data(shop_form, prepared=True)
shop_form = ShopBaseForm(data=data, instance=shop, languages=settings.LANGUAGES)
_test_cleanliness(shop_form)
shop_form.save()
# Now let's make it protected!
create_product(printable_gibberish(), shop=shop, supplier=get_default_supplier())
order = create_random_order(customer=create_random_person(), shop=shop)
assert order.shop == shop
# And try again...
data["currency"] = "XBT" # Bitcoins!
shop_form = ShopBaseForm(data=data, instance=shop, languages=settings.LANGUAGES)
assert shop_form._get_protected_fields() # So protected!
_test_cleanliness(shop_form)
shop = shop_form.save()
assert shop.currency == "EUR" # But the shop form ignored the change . . .