本文整理汇总了Python中shuup_tests.utils.SmartClient类的典型用法代码示例。如果您正苦于以下问题:Python SmartClient类的具体用法?Python SmartClient怎么用?Python SmartClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SmartClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_theme_without_default_template_dir
def test_theme_without_default_template_dir():
get_default_shop()
with override_current_theme_class(ShuupTestingTheme):
c = SmartClient()
soup = c.soup(reverse("shuup:index"))
assert "Simple base for themes to use" not in soup
assert "Welcome to test Shuup!" in soup.find("div", {"class": "page-content"}).text
示例2: test_update_injection
def test_update_injection():
shop = factories.get_default_shop()
client = SmartClient()
index_url = reverse("shuup:index")
page = ensure_gdpr_privacy_policy(shop)
shop_gdpr = GDPRSettings.get_for_shop(shop)
shop_gdpr.enabled = True
shop_gdpr.privacy_policy = page
shop_gdpr.save()
assert_update(client, index_url, False) # nothing consented in past, should not show
user = factories.create_random_user("en")
password = "test"
user.set_password(password)
user.save()
client.login(username=user.username, password=password)
assert_update(client, index_url, False) # no consent given, should not be visible
create_user_consent_for_all_documents(shop, user)
assert_update(client, index_url, False)
with reversion.create_revision():
page.save()
assert not is_documents_consent_in_sync(shop, user)
assert_update(client, index_url, True)
# consent
client.get(reverse("shuup:gdpr_policy_consent", kwargs=dict(page_id=page.pk)))
assert is_documents_consent_in_sync(shop, user)
assert_update(client, index_url, False)
示例3: test_get_installments_cc_does_not_allow_installments
def test_get_installments_cc_does_not_allow_installments():
"""
Max 9 installs with SIMPLE intereset
interest_rate = 4.00%
Credit card does not allow installments
"""
patch_cielo_request()
shop = get_default_shop()
create_default_order_statuses()
populate_if_required()
set_current_theme('shuup.themes.classic_gray')
c = SmartClient()
_configure_basket(c)
CieloConfig.objects.create(shop=shop,
max_installments=9,
installments_without_interest=3,
interest_type=InterestType.Simple,
interest_rate=Decimal(4.0))
order_total = (PRODUCT_QTNTY * PRODUCT_PRICE)
total_price_str = "{0}".format(format_money(shop.create_price(order_total)))
response = c.get(INSTALLMENTS_PATH, {"cc_brand": CieloCardBrand.Discover})
json_content = json.loads(response.content.decode("utf-8"))
assert len(json_content['installments']) == 1
assert json_content['installments'][0]['number'] == 1
assert total_price_str in json_content['installments'][0]['name']
示例4: test_theme_with_default_template_dir
def test_theme_with_default_template_dir():
get_default_shop()
with override_current_theme_class(ShuupTestingThemeWithCustomBase):
c = SmartClient()
soup = c.soup(reverse("shuup:index"))
assert "Simple base for themes to use" in soup.find("h1").text
assert "Welcome to test Shuup!" in soup.find("h1").text
示例5: test_get_installments_12x_with_simples_intereset
def test_get_installments_12x_with_simples_intereset():
"""
Max 12 installs with PRICE intereset
interest_rate = 2.30%
min_installment_amount = 30.00
"""
patch_cielo_request()
shop = get_default_shop()
create_default_order_statuses()
populate_if_required()
set_current_theme('shuup.themes.classic_gray')
c = SmartClient()
_configure_basket(c)
cielo_config = CieloConfig.objects.create(shop=shop,
max_installments=12,
installments_without_interest=2,
interest_type=InterestType.Price,
interest_rate=Decimal(2.3),
min_installment_amount=Decimal(30))
order_total = (PRODUCT_QTNTY * PRODUCT_PRICE)
installment_choices = InstallmentContext(order_total, cielo_config).get_intallments_choices()
response = c.get(INSTALLMENTS_PATH, {"cc_brand": CieloCardBrand.Visa})
json_content = json.loads(response.content.decode("utf-8"))
assert len(json_content['installments']) == len(installment_choices)
for installment in range(len(installment_choices)):
total = format_money(shop.create_price(installment_choices[installment][2]))
installment_amount = format_money(shop.create_price(installment_choices[installment][1]))
assert json_content['installments'][installment]['number'] == installment+1
assert installment_amount in json_content['installments'][installment]['name']
assert total in json_content['installments'][installment]['name']
示例6: test_get_installments_3x_no_intereset
def test_get_installments_3x_no_intereset():
"""
Max 3 installs with no intereset
"""
patch_cielo_request()
shop = get_default_shop()
create_default_order_statuses()
populate_if_required()
set_current_theme('shuup.themes.classic_gray')
c = SmartClient()
_configure_basket(c)
CieloConfig.objects.create(shop=shop,
max_installments=3,
installments_without_interest=3)
order_total = PRODUCT_QTNTY * PRODUCT_PRICE
total_price_str = "{0}".format(format_money(shop.create_price(order_total)))
response = c.get(INSTALLMENTS_PATH, {"cc_brand": CieloCardBrand.Visa})
json_content = json.loads(response.content.decode("utf-8"))
assert len(json_content['installments']) == 3
assert json_content['installments'][0]['number'] == 1
assert total_price_str in json_content['installments'][0]['name']
total_2x_no_interest = format_money(shop.create_price(order_total / Decimal(2)))
assert json_content['installments'][1]['number'] == 2
assert total_price_str in json_content['installments'][1]['name']
assert total_2x_no_interest in json_content['installments'][1]['name']
total_3x_no_interest = format_money(shop.create_price(order_total / Decimal(3)))
assert json_content['installments'][2]['number'] == 3
assert total_price_str in json_content['installments'][2]['name']
assert total_3x_no_interest in json_content['installments'][2]['name']
示例7: test_extender_renders_main_menu
def test_extender_renders_main_menu(rf):
get_default_shop()
with override_provides("front_menu_extender", ["shuup_tests.xtheme.test_extenders:TestExtender"]):
c = SmartClient()
soup = c.soup(reverse("shuup:index"))
link_texts = [a.text for a in soup.findAll("a")]
assert "Test Link to Front" in link_texts
示例8: initialize_test
def initialize_test(regular_user, person=True):
client = SmartClient()
get_default_shop()
if person:
contact = get_person_contact(regular_user)
else:
contact = get_company_contact(regular_user)
client.login(username=REGULAR_USER_USERNAME, password=REGULAR_USER_PASSWORD)
return client, contact
示例9: test_shop_remove_available_languages
def test_shop_remove_available_languages(admin_user):
shop = factories.get_default_shop()
client = SmartClient()
with override_settings(
LANGUAGES=[
("en", "English"),
("fi", "Finnish"),
],
LANGUAGE_CODE="en",
PARLER_DEFAULT_LANGUAGE_CODE = "en"
):
# there is no language set for the shop, the first one will be used
response = client.get(reverse("shuup:index"))
assert get_language() == "en"
# request js catalog file
response = client.get(reverse("shuup:js-catalog"))
assert get_language() == "en"
# when requesting admin js catalog, the language should be any of the available
client.get("shuup_admin:js-catalog")
assert get_language() == "en"
set_shop_available_languages(shop, ["fi"])
response = client.get(reverse("shuup:index"))
assert get_language() == "fi"
response = client.get(reverse("shuup:js-catalog"))
assert get_language() == "fi"
client.get("shuup_admin:js-catalog")
assert get_language() == "en"
示例10: test_consent_cookies
def test_consent_cookies():
"""
Test that the GDPR consent is generated and saved into a cooki
"""
for code, lang in settings.LANGUAGES:
activate(code)
shop = factories.get_default_shop()
client = SmartClient()
index_url = reverse("shuup:index")
response = client.get(index_url)
# create a GDPR setting for the shop
shop_gdpr = GDPRSettings.get_for_shop(shop)
shop_gdpr.cookie_banner_content = "my cookie banner content"
shop_gdpr.cookie_privacy_excerpt = "my cookie privacyexcerpt"
shop_gdpr.enabled = True
shop_gdpr.save()
# create cookie categories
required_cookie_category = GDPRCookieCategory.objects.create(
shop=shop,
always_active=True,
cookies="cookie1,cookir2,_cookie3",
name="RequiredCookies",
how_is_used="to make the site work"
)
optional_cookie_category = GDPRCookieCategory.objects.create(
shop=shop,
always_active=False,
cookies="_opt1,_opt2,_opt3",
name="OptionalCookies",
how_is_used="to spy users"
)
# create privacy policy GDPR document
privacy_policy = ensure_gdpr_privacy_policy(shop)
response = client.get(index_url)
assert settings.SHUUP_GDPR_CONSENT_COOKIE_NAME not in response.cookies
# send consent
response = client.post(reverse("shuup:gdpr_consent"), data={
"cookie_category_{}".format(required_cookie_category.id): "on",
"cookie_category_{}".format(optional_cookie_category.id): "on"
})
assert settings.SHUUP_GDPR_CONSENT_COOKIE_NAME in response.cookies
cookies_data = json.loads(response.cookies[settings.SHUUP_GDPR_CONSENT_COOKIE_NAME].value)
assert privacy_policy.id == cookies_data["documents"][0]["id"]
assert privacy_policy.url == cookies_data["documents"][0]["url"]
for cookie in required_cookie_category.cookies.split(","):
assert cookie in cookies_data["cookies"]
for cookie in optional_cookie_category.cookies.split(","):
assert cookie in cookies_data["cookies"]
示例11: test_basic_order_flow_registered
def test_basic_order_flow_registered(regular_user):
cache.clear()
create_default_order_statuses()
n_orders_pre = Order.objects.count()
populate_if_required()
get_test_script("test script", "order_received")
# paths
addresses_path = reverse("shuup:checkout", kwargs={"phase": "addresses"})
methods_path = reverse("shuup:checkout", kwargs={"phase": "methods"})
confirm_path = reverse("shuup:checkout", kwargs={"phase": "confirm"})
template_data = STEP_DATA[0]["actions"][0]["template_data"]
LANG_CODE = {
"en": "US",
"fi": "FI"
}
for lang in ["en", "fi"]:
n_outbox_pre = len(mail.outbox)
contact = get_person_contact(regular_user)
contact.language = lang
contact.save()
c = SmartClient()
c.login(username=REGULAR_USER_USERNAME, password=REGULAR_USER_PASSWORD)
product_ids = _populate_client_basket(c)
addresses_soup = c.soup(addresses_path)
address = get_address(country=LANG_CODE[lang])
inputs = fill_address_inputs(addresses_soup, address)
response = c.post(addresses_path, data=inputs)
assert response.status_code == 302 # Should redirect forth
methods_soup = c.soup(methods_path)
assert c.post(methods_path, data=extract_form_fields(methods_soup)).status_code == 302 # Should redirect forth
confirm_soup = c.soup(confirm_path)
Product.objects.get(pk=product_ids[0]).soft_delete()
assert c.post(confirm_path, data=extract_form_fields(confirm_soup)).status_code == 200 # user needs to reconfirm
data = extract_form_fields(confirm_soup)
data['product_ids'] = ','.join(product_ids[1:])
assert c.post(confirm_path, data=data).status_code == 302 # Should redirect forth
n_orders_post = Order.objects.count()
assert n_orders_post > n_orders_pre, "order was created"
assert (len(mail.outbox) == n_outbox_pre + 1), "Sending email failed"
latest_mail = mail.outbox[-1]
# mail is always sent in fallback language since user is not registered
assert latest_mail.subject == template_data[lang]["subject"], "Subject doesn't match"
assert latest_mail.body == template_data[lang]["body"], "Body doesn't match"
示例12: test_theme_with_default_template_dir
def test_theme_with_default_template_dir():
with override_settings(CACHES={
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'test_configuration_cache',
}
}):
cache.init_cache()
get_default_shop()
with override_current_theme_class(ShuupTestingThemeWithCustomBase, get_default_shop()):
c = SmartClient()
soup = c.soup(reverse("shuup:index"))
assert "Simple base for themes to use" in soup.find("h1").text
assert "Welcome to test Shuup!" in soup.find("h1").text
示例13: test_checkout_empty_basket
def test_checkout_empty_basket(rf):
create_default_order_statuses()
n_orders_pre = Order.objects.count()
populate_if_required()
c = SmartClient()
product_ids = _populate_client_basket(c)
addresses_path = reverse("shuup:checkout", kwargs={"phase": "addresses"})
addresses_soup = c.soup(addresses_path)
inputs = fill_address_inputs(addresses_soup)
for product_id in product_ids:
Product.objects.get(pk=product_id).soft_delete()
response, soup = c.response_and_soup(addresses_path, data=inputs, method="post")
assert response.status_code == 200 # Should redirect forth
assert b"Your shopping cart is empty." in soup.renderContents()
示例14: test_basic_order_flow
def test_basic_order_flow(with_company):
create_default_order_statuses()
n_orders_pre = Order.objects.count()
populate_if_required()
c = SmartClient()
product_ids = _populate_client_basket(c)
addresses_path = reverse("shuup:checkout", kwargs={"phase": "addresses"})
addresses_soup = c.soup(addresses_path)
inputs = fill_address_inputs(addresses_soup, with_company=with_company)
response = c.post(addresses_path, data=inputs)
assert response.status_code == 302 # Should redirect forth
methods_path = reverse("shuup:checkout", kwargs={"phase": "methods"})
methods_soup = c.soup(methods_path)
assert c.post(methods_path, data=extract_form_fields(methods_soup)).status_code == 302 # Should redirect forth
confirm_path = reverse("shuup:checkout", kwargs={"phase": "confirm"})
confirm_soup = c.soup(confirm_path)
Product.objects.get(pk=product_ids[0]).soft_delete()
assert c.post(confirm_path, data=extract_form_fields(confirm_soup)).status_code == 200 # user needs to reconfirm
data = extract_form_fields(confirm_soup)
data['product_ids'] = ','.join(product_ids[1:])
assert c.post(confirm_path, data=data).status_code == 302 # Should redirect forth
n_orders_post = Order.objects.count()
assert n_orders_post > n_orders_pre, "order was created"
示例15: test_shop_available_languages
def test_shop_available_languages(admin_user):
original_language = get_language()
shop = factories.get_default_shop()
client = SmartClient()
with override_settings(
LANGUAGES=[
("it", "Italian"),
("fr", "French"),
("fi", "Finnish"),
("pt", "Portuguese")
],
LANGUAGE_CODE="it",
PARLER_DEFAULT_LANGUAGE_CODE = "it"
):
# there is no language set for the shop, the first one will be used
response = client.get(reverse("shuup:index"))
assert get_language() == "it"
# set an invalid language code
with pytest.raises(ValueError):
set_shop_available_languages(shop, ["xpto"])
# limit the langauges for the shop to "fi" and "pt"
set_shop_available_languages(shop, ["fi", "pt"])
# the middleware will automatically set the language to "fi" as that is the first one available for the shop
response = client.get(reverse("shuup:index"))
assert get_language() == "fi"
# the same won't happen for any other url - the middleware will only affect front urls
client.get("shuup_admin:index")
assert get_language() == "it"
# test againt front again
client.get(reverse("shuup:index"))
assert get_language() == "fi"
# again for admin
client.get("shuup_admin:index")
assert get_language() == "it"
# remote all available languages
set_shop_available_languages(shop, [])
# this should fallback to settings.LAGUAGE_CODE
response = client.get(reverse("shuup:index"))
assert get_language() == "it"
activate(original_language)