本文整理汇总了Python中shuup.testing.factories.get_default_shipping_method函数的典型用法代码示例。如果您正苦于以下问题:Python get_default_shipping_method函数的具体用法?Python get_default_shipping_method怎么用?Python get_default_shipping_method使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_default_shipping_method函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_update_line_quantity
def test_update_line_quantity(admin_user, settings):
configure(settings)
shop = factories.get_default_shop()
basket = factories.get_basket()
factories.get_default_payment_method()
factories.get_default_shipping_method()
shop_product = factories.get_default_shop_product()
shop_product.default_price = TaxfulPrice(1, shop.currency)
shop_product.save()
client = _get_client(admin_user)
# add shop product
payload = {
'shop_product': shop_product.id
}
response = client.post('/api/shuup/basket/{}-{}/add/'.format(shop.pk, basket.key), payload)
assert response.status_code == status.HTTP_200_OK
response_data = json.loads(response.content.decode("utf-8"))
assert len(response_data["items"]) == 1
payload = {
"line_id": response_data["items"][0]["line_id"],
"quantity": 5
}
response = client.post('/api/shuup/basket/{}-{}/update_quantity/'.format(shop.pk, basket.key), payload)
assert response.status_code == status.HTTP_200_OK
response_data = json.loads(response.content.decode("utf-8"))
assert len(response_data["items"]) == 1
assert response_data["items"][0]["shop_product"] == shop_product.pk
assert float(response_data["items"][0]["quantity"]) == 5
assert float(response_data["total_price"]) == 5
basket.refresh_from_db()
assert Basket.objects.first().data["lines"][0]["quantity"] == 5
示例2: test_add_variation_product_to_basket
def test_add_variation_product_to_basket(admin_user, settings):
configure(settings)
shop = factories.get_default_shop()
basket = factories.get_basket()
factories.get_default_payment_method()
factories.get_default_shipping_method()
parent = factories.create_product("ComplexVarParent", shop=shop, supplier=factories.get_default_supplier())
sizes = [("%sL" % ("X" * x)) for x in range(4)]
for size in sizes:
child = factories.create_product("ComplexVarChild-%s" % size, shop=shop, supplier=factories.get_default_supplier())
child.link_to_parent(parent, variables={"size": size})
parent_shop_product = parent.get_shop_instance(shop)
parent_shop_product.refresh_from_db()
client = _get_client(admin_user)
# add parent shop product
payload = {
'shop_product': parent_shop_product.id
}
response = client.post('/api/shuup/basket/{}-{}/add/'.format(shop.pk, basket.key), payload)
assert response.status_code == status.HTTP_400_BAD_REQUEST
# add children shop product
children_shop_product = parent_shop_product.product.variation_children.first().get_shop_instance(shop)
payload = {
'shop_product': children_shop_product.pk,
}
response = client.post('/api/shuup/basket/{}-{}/add/'.format(shop.pk, basket.key), payload)
assert response.status_code == status.HTTP_200_OK
response_data = json.loads(response.content.decode("utf-8"))
assert len(response_data["items"]) == 1
assert not response_data["validation_errors"]
示例3: test_add_product_to_basket
def test_add_product_to_basket(admin_user, settings):
configure(settings)
shop = factories.get_default_shop()
basket = factories.get_basket()
factories.get_default_payment_method()
factories.get_default_shipping_method()
shop_product = factories.get_default_shop_product()
shop_product.default_price = TaxfulPrice(1, shop.currency)
shop_product.save()
client = _get_client(admin_user)
# add shop product
payload = {
'shop_product': shop_product.id
}
response = client.post('/api/shuup/basket/{}-{}/add/'.format(shop.pk, basket.key), payload)
assert response.status_code == status.HTTP_200_OK
response_data = json.loads(response.content.decode("utf-8"))
assert len(response_data["items"]) == 1
assert response_data["items"][0]["shop_product"] == shop_product.pk
assert not response_data["validation_errors"]
assert float(response_data["total_price"]) == 1
# add product
payload = {
'product': shop_product.product.pk,
'shop': shop.pk
}
response = client.post('/api/shuup/basket/{}-{}/add/'.format(shop.pk, basket.key), payload)
assert response.status_code == status.HTTP_200_OK
response_data = json.loads(response.content.decode("utf-8"))
assert len(response_data["items"]) == 1
assert not response_data["validation_errors"]
assert float(response_data["total_price"]) == 2
示例4: test_set_shipping_address
def test_set_shipping_address(admin_user):
shop = factories.get_default_shop()
basket = factories.get_basket()
factories.get_default_payment_method()
factories.get_default_shipping_method()
client = _get_client(admin_user)
addr1 = factories.get_address()
addr1.save()
# use existing address
payload = {
'id': addr1.id
}
response = client.post('/api/shuup/basket/{}-{}/set_shipping_address/'.format(shop.pk, basket.key), payload)
assert response.status_code == status.HTTP_200_OK
response_data = json.loads(response.content.decode("utf-8"))
shipping_addr = response_data["shipping_address"]
assert shipping_addr["id"] == addr1.id
assert shipping_addr["prefix"] == addr1.prefix
assert shipping_addr["name"] == addr1.name
assert shipping_addr["postal_code"] == addr1.postal_code
assert shipping_addr["street"] == addr1.street
assert shipping_addr["city"] == addr1.city
assert shipping_addr["country"] == addr1.country
# create a new address
address_data = {
'name': 'name',
'prefix': 'prefix',
'postal_code': 'postal_code',
'street': 'street',
'city': 'city',
'country': 'BR'
}
response = client.post('/api/shuup/basket/{}-{}/set_shipping_address/'.format(shop.pk, basket.key), address_data)
assert response.status_code == status.HTTP_200_OK
response_data = json.loads(response.content.decode("utf-8"))
shipping_addr = response_data["shipping_address"]
assert shipping_addr["id"] == addr1.id+1
assert shipping_addr["prefix"] == address_data["prefix"]
assert shipping_addr["name"] == address_data["name"]
assert shipping_addr["postal_code"] == address_data["postal_code"]
assert shipping_addr["street"] == address_data["street"]
assert shipping_addr["city"] == address_data["city"]
assert shipping_addr["country"] == address_data["country"]
# get the basket and check the address
response = client.get('/api/shuup/basket/{}-{}/'.format(shop.pk, basket.key))
assert response.status_code == status.HTTP_200_OK
response_data = json.loads(response.content.decode("utf-8"))
shipping_addr = response_data["shipping_address"]
assert shipping_addr["id"] == addr1.id+1
assert shipping_addr["prefix"] == address_data["prefix"]
assert shipping_addr["name"] == address_data["name"]
assert shipping_addr["postal_code"] == address_data["postal_code"]
assert shipping_addr["street"] == address_data["street"]
assert shipping_addr["city"] == address_data["city"]
assert shipping_addr["country"] == address_data["country"]
示例5: seed_source
def seed_source(user):
source = BasketishOrderSource(get_default_shop())
billing_address = get_address()
shipping_address = get_address(name="Shippy Doge")
source.status = get_initial_order_status()
source.billing_address = billing_address
source.shipping_address = shipping_address
source.customer = get_person_contact(user)
source.payment_method = get_default_payment_method()
source.shipping_method = get_default_shipping_method()
assert source.payment_method_id == get_default_payment_method().id
assert source.shipping_method_id == get_default_shipping_method().id
return source
示例6: test_create_order
def test_create_order(admin_user, settings, target_customer):
configure(settings)
shop = factories.get_default_shop()
basket = factories.get_basket()
factories.create_default_order_statuses()
shop_product = factories.get_default_shop_product()
shop_product.default_price = TaxfulPrice(1, shop.currency)
shop_product.save()
client = _get_client(admin_user)
# add shop product
payload = {
'shop_product': shop_product.id
}
if target_customer == "other":
target = factories.create_random_person()
payload["customer_id"] = target.pk
else:
target = get_person_contact(admin_user)
response = client.post('/api/shuup/basket/{}-{}/add/'.format(shop.pk, basket.key), payload)
assert response.status_code == status.HTTP_200_OK
response_data = json.loads(response.content.decode("utf-8"))
assert len(response_data["items"]) == 1
response = client.post('/api/shuup/basket/{}-{}/create_order/'.format(shop.pk, basket.key), payload)
assert response.status_code == status.HTTP_400_BAD_REQUEST
response_data = json.loads(response.content.decode("utf-8"))
assert "errors" in response_data
factories.get_default_payment_method()
factories.get_default_shipping_method()
response = client.post('/api/shuup/basket/{}-{}/create_order/'.format(shop.pk, basket.key), payload)
assert response.status_code == status.HTTP_201_CREATED
response_data = json.loads(response.content.decode("utf-8"))
basket.refresh_from_db()
assert basket.finished
order = Order.objects.get(reference_number=response_data["reference_number"])
assert order.status == OrderStatus.objects.get_default_initial()
assert order.payment_status == PaymentStatus.NOT_PAID
assert order.shipping_status == ShippingStatus.NOT_SHIPPED
assert not order.payment_method
assert not order.shipping_method
assert float(order.taxful_total_price_value) == 1
assert order.customer == target
assert order.orderer == get_person_contact(admin_user)
assert order.creator == admin_user
assert not order.billing_address
assert not order.shipping_address
示例7: test_abandoned_baskets
def test_abandoned_baskets(admin_user, settings):
configure(settings)
shop = factories.get_default_shop()
factories.get_default_payment_method()
factories.get_default_shipping_method()
basket1 = factories.get_basket()
shop_product = factories.get_default_shop_product()
shop_product.default_price = TaxfulPrice(1, shop.currency)
shop_product.save()
client = _get_client(admin_user)
# add shop product
payload = {'shop_product': shop_product.id}
response = client.post('/api/shuup/basket/{}-{}/add/'.format(shop.pk, basket1.key), payload)
assert response.status_code == status.HTTP_200_OK
response_data = json.loads(response.content.decode("utf-8"))
assert len(response_data["items"]) == 1
assert response_data["items"][0]["shop_product"] == shop_product.pk
assert not response_data["validation_errors"]
assert float(response_data["total_price"]) == 1
assert Basket.objects.count() == 1
response = client.get("/api/shuup/basket/abandoned/?shop={}&days_ago=0¬_updated_in_hours=0".format(shop.pk))
response_data = json.loads(response.content.decode("utf-8"))
assert len(response_data) == 1
basket_data = response_data[0]
assert basket_data["id"] == basket1.id
basket2 = factories.get_basket()
response = client.post('/api/shuup/basket/{}-{}/add/'.format(shop.pk, basket2.key), payload)
assert response.status_code == status.HTTP_200_OK
response_data = json.loads(response.content.decode("utf-8"))
assert len(response_data["items"]) == 1
assert response_data["items"][0]["shop_product"] == shop_product.pk
assert not response_data["validation_errors"]
assert float(response_data["total_price"]) == 1
assert Basket.objects.count() == 2
response = client.get("/api/shuup/basket/abandoned/?shop={}&days_ago=0¬_updated_in_hours=0".format(shop.pk))
response_data = json.loads(response.content.decode("utf-8"))
assert len(response_data) == 2
basket_data = response_data[1]
assert basket_data["id"] == basket2.id
# there is no shop with this id thus it should return 404
response = client.get("/api/shuup/basket/abandoned/?shop=2&days_ago=0¬_updated_in_hours=0")
assert response.status_code == status.HTTP_404_NOT_FOUND
示例8: test_single_page_checkout_with_login_and_register
def test_single_page_checkout_with_login_and_register(browser, live_server, settings):
# initialize
product_name = "Test Product"
get_default_shop()
pm = get_default_payment_method()
sm = get_default_shipping_method()
product = create_orderable_product(product_name, "test-123", price=100)
OrderStatus.objects.create(
identifier="initial",
role=OrderStatusRole.INITIAL,
name="initial",
default=True
)
# Initialize test and go to front page
browser = initialize_front_browser_test(browser, live_server)
wait_until_condition(browser, lambda x: x.is_text_present("Welcome to Default!"))
navigate_to_checkout(browser, product)
# Let's assume that after addresses the checkout is normal
wait_until_condition(browser, lambda x: x.is_text_present("Checkout Method"))
test_username = "test_username"
test_email = "[email protected]"
test_password = "test_password"
register_test(browser, live_server, test_username, test_email, test_password)
login_and_finish_up_the_checkout(browser, live_server, test_username, test_email, test_password)
示例9: 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
示例10: get_order_and_source
def get_order_and_source(admin_user, product):
# 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=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
示例11: seed_source
def seed_source(user, shop):
source = BasketishOrderSource(shop)
source.status = get_initial_order_status()
source.customer = get_person_contact(user)
source.payment_method = get_default_payment_method()
source.shipping_method = get_default_shipping_method()
return source
示例12: create_simple_order
def create_simple_order(request, creator, customer):
billing_address = get_address().to_immutable()
shipping_address = get_address(name="Shippy Doge").to_immutable()
shipping_address.save()
shop = request.shop
order = Order(
creator=creator,
customer=customer,
shop=shop,
payment_method=get_default_payment_method(),
shipping_method=get_default_shipping_method(),
billing_address=billing_address,
shipping_address=shipping_address,
order_date=now(),
status=get_initial_order_status(),
currency=shop.currency,
prices_include_tax=shop.prices_include_tax,
)
order.full_clean()
order.save()
order.cache_prices()
order.check_all_verified()
order.save()
return order
示例13: test_coupon
def test_coupon(browser, live_server, settings):
activate("en")
# initialize
cache.clear()
shop = get_default_shop()
get_default_payment_method()
get_default_shipping_method()
first_category = Category.objects.create(
identifier="cat-1", status=CategoryStatus.VISIBLE, name="First Category")
first_category.shops.add(shop)
_populate_products_form_data(CATEGORY_PRODUCT_DATA, shop, first_category)
# initialize test and go to front page
browser = initialize_front_browser_test(browser, live_server)
_add_product_to_basket_from_category(live_server, browser, first_category, shop)
_activate_basket_campaign_through_coupon(browser, first_category, shop)
示例14: test_add_product_to_basket_with_custom_shop_product_fields
def test_add_product_to_basket_with_custom_shop_product_fields(admin_user, settings):
product_name = "Product Name"
shop_product_name = "SHOP Product Name"
configure(settings)
shop = factories.get_default_shop()
basket = factories.get_basket()
factories.get_default_payment_method()
factories.get_default_shipping_method()
shop_product = factories.get_default_shop_product()
shop_product.default_price = TaxfulPrice(1, shop.currency)
shop_product.save()
shop_product.product.name = product_name
shop_product.product.save()
client = _get_client(admin_user)
payload = {
'product': shop_product.product.pk,
'shop': shop.pk
}
response = client.post('/api/shuup/basket/{}-{}/add/'.format(shop.pk, basket.key), payload)
assert response.status_code == status.HTTP_200_OK
response_data = json.loads(response.content.decode("utf-8"))
assert len(response_data["items"]) == 1
assert response_data["items"][0]["shop_product"] == shop_product.pk
assert response_data["items"][0]["text"] == product_name
# set shop product name
shop_product.product.name = shop_product_name
shop_product.product.save()
# add product
payload = {
'product': shop_product.product.pk,
'shop': shop.pk
}
response = client.post('/api/shuup/basket/{}-{}/add/'.format(shop.pk, basket.key), payload)
assert response.status_code == status.HTTP_200_OK
response_data = json.loads(response.content.decode("utf-8"))
assert len(response_data["items"]) == 1
assert response_data["items"][0]["text"] == shop_product_name
示例15: seed_source
def seed_source(user, extra_addr=True):
source = BasketishOrderSource(get_default_shop())
billing_address = get_address()
shipping_address = get_address(name="Shippy Doge")
if extra_addr:
billing_address.extra = ExtraMutableAddress.from_data(EXTRA_MUTABLE_ADDRESS_1)
if extra_addr:
shipping_address.extra = ExtraMutableAddress.from_data(EXTRA_MUTABLE_ADDRESS_2)
source.status = get_initial_order_status()
source.billing_address = billing_address
source.shipping_address = shipping_address
source.customer = get_person_contact(user)
source.payment_method = get_default_payment_method()
source.shipping_method = get_default_shipping_method()
assert source.payment_method_id == get_default_payment_method().id
assert source.shipping_method_id == get_default_shipping_method().id
return source