本文整理汇总了Python中shuup.testing.factories.get_default_payment_method函数的典型用法代码示例。如果您正苦于以下问题:Python get_default_payment_method函数的具体用法?Python get_default_payment_method怎么用?Python get_default_payment_method使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_default_payment_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_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
示例3: 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"]
示例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_basket
def test_basket(rf, storage):
StoredBasket.objects.all().delete()
quantities = [3, 12, 44, 23, 65]
shop = get_default_shop()
get_default_payment_method() # Can't create baskets without payment methods
supplier = get_default_supplier()
products_and_quantities = []
for quantity in quantities:
product = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price=50)
products_and_quantities.append((product, quantity))
is_database = (storage == "shuup.front.basket.storage:DatabaseBasketStorage")
with override_settings(SHUUP_BASKET_STORAGE_CLASS_SPEC=storage):
for product, q in products_and_quantities:
request = rf.get("/")
request.session = {}
request.shop = shop
apply_request_middleware(request)
basket = get_basket(request)
assert basket == request.basket
assert basket.product_count == 0
line = basket.add_product(supplier=supplier, shop=shop, product=product, quantity=q)
basket.shipping_method = get_shipping_method(shop=shop) # For shippable product
assert line.quantity == q
assert basket.get_lines()
assert basket.get_product_ids_and_quantities().get(product.pk) == q
assert basket.product_count == q
basket.save()
delattr(request, "basket")
basket = get_basket(request)
assert basket.get_product_ids_and_quantities().get(product.pk) == q
if is_database:
product_ids = set(StoredBasket.objects.last().products.values_list("id", flat=True))
assert product_ids == set([product.pk])
if is_database:
stats = StoredBasket.objects.all().aggregate(
n=Sum("product_count"),
tfs=Sum("taxful_total_price_value"),
tls=Sum("taxless_total_price_value"),
)
assert stats["n"] == sum(quantities)
if shop.prices_include_tax:
assert stats["tfs"] == sum(quantities) * 50
else:
assert stats["tls"] == sum(quantities) * 50
basket.finalize()
示例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: 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
示例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: 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)
示例13: 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
示例14: test_model_form_partially_translated
def test_model_form_partially_translated(rf, admin_user):
with override_settings(**{"LANGUAGES": (("en", "en"), ("fi", "fi"), ("ja", "ja")),
"PARLER_DEFAULT_LANGUAGE_CODE": "en"}):
activate("en")
get_default_shop()
request = apply_request_middleware(rf.get("/"), user=admin_user)
test_name_en = "Test shop"
payment_method = get_default_payment_method()
payment_method.name = test_name_en
payment_method.save()
form = PaymentMethodForm(instance=payment_method, request=request, languages=settings.LANGUAGES)
data = get_form_data(form, prepared=True)
assert data.get("name__en") == test_name_en
assert not data.get("name__fi")
form = PaymentMethodForm(data=data, instance=payment_method, request=request, languages=settings.LANGUAGES)
form.full_clean()
assert form.is_valid() and not form.errors
payment_method = form.save()
# Add description for Finnish and and name in Finnish should be required
data["description__fi"] = "Some description"
form = PaymentMethodForm(data=data, instance=payment_method, request=request, languages=settings.LANGUAGES)
form.full_clean()
assert not form.is_valid() and form.errors
test_name_fi = "Some method name in finnish"
data["name__fi"] = test_name_fi
form = PaymentMethodForm(data=data, instance=payment_method, request=request, languages=settings.LANGUAGES)
form.full_clean()
assert form.is_valid() and not form.errors
payment_method = form.save()
assert payment_method.name == test_name_en, "Object in English"
activate("fi")
payment_method.set_current_language("fi")
assert payment_method.name == test_name_fi, "Object in Finnish"
activate("ja")
payment_method.set_current_language("ja")
assert payment_method.name == test_name_en, "Should fallback to English"
# Check that no sneaky translations is not created for Japan
with pytest.raises(ObjectDoesNotExist):
translation = payment_method.get_translation("ja")
translation.refresh_from_db() # Just in case if the translation object comes from cache or something
# Empty finnish translations and see if Finnish starts fallbacks too
data["name__fi"] = data["description__fi"] = ""
form = PaymentMethodForm(data=data, instance=payment_method, request=request, languages=settings.LANGUAGES)
form.full_clean()
assert form.is_valid() and not form.errors
form.save()
# Check that no sneaky translations is not created for Finnish
with pytest.raises(ObjectDoesNotExist):
translation = payment_method.get_translation("fi")
translation.refresh_from_db() # Just in case if the translation object comes from cache or something
示例15: test_unsaved_contact
def test_unsaved_contact(admin_user):
payment_method = get_default_payment_method()
_assign_component_for_service(payment_method, [PersonContact.get_default_group()])
person = PersonContact(name="Kalle")
source = _get_source_for_contact(admin_user, payment_method)
source.customer = person
assert not person.pk and not source.customer.pk
_test_service_availability(source, payment_method, False)