本文整理汇总了Python中shuup_tests.utils.SmartClient.post方法的典型用法代码示例。如果您正苦于以下问题:Python SmartClient.post方法的具体用法?Python SmartClient.post怎么用?Python SmartClient.post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shuup_tests.utils.SmartClient
的用法示例。
在下文中一共展示了SmartClient.post方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_basic_order_flow
# 需要导入模块: from shuup_tests.utils import SmartClient [as 别名]
# 或者: from shuup_tests.utils.SmartClient import post [as 别名]
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"
示例2: test_basic_order_flow_registered
# 需要导入模块: from shuup_tests.utils import SmartClient [as 别名]
# 或者: from shuup_tests.utils.SmartClient import post [as 别名]
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"
示例3: test_serialize_data
# 需要导入模块: from shuup_tests.utils import SmartClient [as 别名]
# 或者: from shuup_tests.utils.SmartClient import post [as 别名]
def test_serialize_data():
"""
Test contact dashboard views
"""
activate("en")
shop = factories.get_default_shop()
customer = factories.create_random_person("en")
user = factories.create_random_user("en")
user.set_password("1234")
user.save()
customer.user = user
customer.default_billing_address = factories.create_random_address()
customer.default_shipping_address = factories.create_random_address()
customer.save()
company = factories.create_random_company()
company.default_billing_address = factories.create_random_address()
company.default_shipping_address = factories.create_random_address()
company.save()
company.members.add(customer)
product = factories.create_product("p1", shop, factories.get_default_supplier())
for basket_customer in [customer, company]:
[factories.create_random_order(basket_customer, [product]) for order in range(3)]
client = SmartClient()
client.login(username=user.username, password="1234")
response = client.get(reverse("shuup:gdpr_customer_dashboard"))
assert response.status_code == 200
assert "My Data" in response.content.decode("utf-8")
response = client.post(reverse("shuup:gdpr_download_data"))
assert response._headers["content-disposition"][0] == "Content-Disposition"
assert response.status_code == 200
from shuup.tasks.models import Task, TaskType
from shuup.gdpr.models import GDPR_ANONYMIZE_TASK_TYPE_IDENTIFIER
response = client.post(reverse("shuup:gdpr_anonymize_account"))
assert response.status_code == 302
assert response.url.endswith(reverse("shuup:index"))
task_type = TaskType.objects.get(identifier=GDPR_ANONYMIZE_TASK_TYPE_IDENTIFIER, shop=shop)
assert Task.objects.get(type=task_type, shop=shop)
user.refresh_from_db()
assert user.is_active is False
refreshed_customer = PersonContact.objects.get(id=customer.id)
assert refreshed_customer.is_active is False
assert refreshed_customer.name == customer.name # nothing changed yet
示例4: test_gdpr_admin_settings
# 需要导入模块: from shuup_tests.utils import SmartClient [as 别名]
# 或者: from shuup_tests.utils.SmartClient import post [as 别名]
def test_gdpr_admin_settings(client, admin_user):
"""
Test that admin user can enable GDPR and add cookie categories
"""
activate("en")
shop = factories.get_default_shop()
client = SmartClient()
admin_user.set_password("admin")
admin_user.save()
client.login(username=admin_user.username, password="admin")
admin_settings_url = reverse("shuup_admin:gdpr.settings")
assert not GDPRSettings.objects.exists()
response = client.soup(admin_settings_url)
assert GDPRSettings.objects.exists()
s = GDPRSettings.objects.first()
assert s.cookie_banner_content == settings.SHUUP_GDPR_DEFAULT_BANNER_STRING
assert s.cookie_privacy_excerpt == settings.SHUUP_GDPR_DEFAULT_EXCERPT_STRING
assert GDPRCookieCategory.objects.count() == 0
page = Page.objects.create(shop=shop, available_from=now())
page.title = "test"
page.save()
# create the settings with only basic options
payload = extract_form_fields(response)
payload.update({
"base-enabled": True,
"base-privacy_policy_page": page.pk,
"base-cookie_banner_content__en": "Banner content",
"base-cookie_privacy_excerpt__en": "Cookie excerpt",
"cookie_categories-0-id": "",
"cookie_categories-0-always_active": 1,
"cookie_categories-0-name__en": "required",
"cookie_categories-0-how_is_used__en": "to work",
"cookie_categories-0-cookies": "sessionid"
})
response = client.post(admin_settings_url, data=payload)
assert response.status_code == 302
assert GDPRCookieCategory.objects.count() == 1
# add one more cookie category
payload.update({
"cookie_categories-1-id": "",
"cookie_categories-1-always_active": 1,
"cookie_categories-1-name__en": "Maybe",
"cookie_categories-1-how_is_used__en": "to spy",
"cookie_categories-1-cookies": "_ga"
})
client.post(admin_settings_url, data=payload)
assert GDPRCookieCategory.objects.count() == 2
示例5: test_register_form
# 需要导入模块: from shuup_tests.utils import SmartClient [as 别名]
# 或者: from shuup_tests.utils.SmartClient import post [as 别名]
def test_register_form(client):
activate("en")
shop = factories.get_default_shop()
gdpr_settings = GDPRSettings.get_for_shop(shop)
gdpr_settings.enabled = True
gdpr_settings.save()
# create privacy policy GDPR document
privacy_policy = ensure_gdpr_privacy_policy(shop)
redirect_target = "/index/"
client = SmartClient()
# user didn't checked the privacy policy agreement
response = client.post(reverse("shuup:registration_register"), data={
"username": "user",
"email": "[email protected]",
"password1": "1234",
"password2": "1234",
REDIRECT_FIELD_NAME: redirect_target
})
assert response.status_code == 200
assert "You must accept to this to register." in response.content.decode("utf-8")
response = client.post(reverse("shuup:registration_register"), data={
"username": "user",
"email": "[email protected]",
"password1": "1234",
"password2": "1234",
"accept_%d" % privacy_policy.id: "on",
REDIRECT_FIELD_NAME: redirect_target
})
assert response.status_code == 302
assert response.get("location")
assert response.get("location").endswith(redirect_target)
user = User.objects.first()
assert is_documents_consent_in_sync(shop, user)
ensure_gdpr_privacy_policy(shop, force_update=True)
assert not is_documents_consent_in_sync(shop, user)
示例6: test_basic_order_flow
# 需要导入模块: from shuup_tests.utils import SmartClient [as 别名]
# 或者: from shuup_tests.utils.SmartClient import post [as 别名]
def test_basic_order_flow(with_company, with_signal):
cache.clear()
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
# Make sure the address is initialized from storage
# Go back to addresses right before back to methods
c.soup(addresses_path)
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
if with_signal:
checkout_complete.connect(checkout_complete_signal, dispatch_uid="checkout_complete_signal")
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"
order = Order.objects.first()
expected_ip = "127.0.0.2" if with_signal else "127.0.0.1"
assert order.ip_address == expected_ip
if with_signal:
checkout_complete.disconnect(dispatch_uid="checkout_complete_signal")
示例7: test_consent_cookies
# 需要导入模块: from shuup_tests.utils import SmartClient [as 别名]
# 或者: from shuup_tests.utils.SmartClient import post [as 别名]
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"]
示例8: test_order_configuration
# 需要导入模块: from shuup_tests.utils import SmartClient [as 别名]
# 或者: from shuup_tests.utils.SmartClient import post [as 别名]
def test_order_configuration(rf, admin_user):
shop = get_default_shop()
# clear shop configurations
ConfigurationItem.objects.filter(shop=shop).delete()
client = SmartClient()
client.login(username="admin", password="password")
url = reverse("shuup_admin:shop.edit", kwargs={"pk": shop.pk})
response, soup = client.response_and_soup(url)
assert response.status_code == 200
length_form_field = "order_configuration-%s" % consts.ORDER_REFERENCE_NUMBER_LENGTH_FIELD
prefix_form_field = "order_configuration-%s" % consts.ORDER_REFERENCE_NUMBER_PREFIX_FIELD
length_field = soup.find("input", attrs={"id": "id_%s" % length_form_field})
prefix_field = soup.find("input", attrs={"id": "id_%s" % prefix_form_field})
assert length_field
assert prefix_field
assert length_field["value"] == str(settings.SHUUP_REFERENCE_NUMBER_LENGTH) # default value because nothing set yet
assert "value" not in prefix_field # field empty
data = get_base_form_data(shop)
data[length_form_field] = "18"
data[prefix_form_field] = "123"
response, soup = client.response_and_soup(url, data=data, method="post")
assert "is required" not in soup.prettify()
assert response.status_code == 302 # redirect after success
assert configuration.get(shop, consts.ORDER_REFERENCE_NUMBER_LENGTH_FIELD) == 18
# set global system settings
# TODO: Enable this before 1.3
# set_reference_method(rf, admin_user, OrderReferenceNumberMethod.RUNNING)
data[length_form_field] = "19"
data[prefix_form_field] = "0"
client.post(url, data=data)
assert configuration.get(shop, consts.ORDER_REFERENCE_NUMBER_LENGTH_FIELD) == 19
assert not configuration.get(shop, consts.ORDER_REFERENCE_NUMBER_PREFIX_FIELD) # None because disabled line 104, else 0
示例9: test_import_error
# 需要导入模块: from shuup_tests.utils import SmartClient [as 别名]
# 或者: from shuup_tests.utils.SmartClient import post [as 别名]
def test_import_error(admin_user):
shop = get_default_shop()
shop.staff_members.add(admin_user)
get_default_tax_class()
get_default_product_type()
get_default_sales_unit()
client = SmartClient()
client.login(username="admin", password="password")
import_path = reverse("shuup_admin:importer.import")
process_path = reverse("shuup_admin:importer.import_process")
client = SmartClient()
client.login(username="admin", password="password")
csv_content = str.encode("sku;name\n123;Teste")
data = {
"importer": "product_importer",
"shop": shop.pk,
"language": "en",
"file": SimpleUploadedFile("file.csv", csv_content, content_type="text/csv")
}
response = client.post(import_path, data=data)
assert response.status_code == 302
query_string = urlparse(response["location"]).query
query = parse_qs(query_string)
data = {
"importer": "product_importer",
"shop": shop.pk,
"language": "en",
"n": query.get("n"),
}
data = {}
process_submit_path = "%s?%s" % (process_path, query_string)
response = client.post(process_submit_path, data=data)
assert response.status_code == 302
assert "Failed to import the file." == list(response.wsgi_request._messages)[0].message
示例10: test_authenticate_form
# 需要导入模块: from shuup_tests.utils import SmartClient [as 别名]
# 或者: from shuup_tests.utils.SmartClient import post [as 别名]
def test_authenticate_form(client):
activate("en")
shop = factories.get_default_shop()
user = factories.create_random_user("en")
user.email = "[email protected]"
user.set_password("1234")
user.save()
gdpr_settings = GDPRSettings.get_for_shop(shop)
gdpr_settings.enabled = True
gdpr_settings.save()
# create privacy policy GDPR document
privacy_policy = ensure_gdpr_privacy_policy(shop)
redirect_target = "/redirect-success/"
client = SmartClient()
# user didn't check the privacy policy agreement
response = client.post(reverse("shuup:login"), data={
"username": user.email,
"password": "1234",
REDIRECT_FIELD_NAME: redirect_target
})
assert response.status_code == 200
assert "You must accept to this to authenticate." in response.content.decode("utf-8")
response = client.post(reverse("shuup:login"), data={
"username": user.email,
"password": "1234",
"accept_%d" % privacy_policy.id: "on",
REDIRECT_FIELD_NAME: redirect_target
})
assert response.status_code == 302
assert response.get("location")
assert response.get("location").endswith(redirect_target)
示例11: test_admin_set_shop_language
# 需要导入模块: from shuup_tests.utils import SmartClient [as 别名]
# 或者: from shuup_tests.utils.SmartClient import post [as 别名]
def test_admin_set_shop_language(admin_user):
original_language = get_language()
shop = factories.get_default_shop()
client = SmartClient()
admin_user.set_password("admin")
admin_user.save()
client.login(username=admin_user.username, password="admin")
with override_settings(
LANGUAGES=[
("it", "Italian"),
("fr", "French"),
("fi", "Finnish"),
("pt-br", "Portuguese (Brazil)")
],
LANGUAGE_CODE="it",
PARLER_DEFAULT_LANGUAGE_CODE = "it"
):
assert get_shop_available_languages(shop) == []
edit_url = reverse("shuup_admin:shop.edit", kwargs=dict(pk=shop.id))
payload = {
"translation_config-available_languages": ["pt-br", "fi"],
"base-public_name__it": shop.public_name,
"base-name__it": shop.name,
"base-status": "1",
"base-currency": shop.currency,
"product_list_facets-filter_products_by_category_ordering": "1",
"product_list_facets-filter_products_by_price_ordering": "1",
"product_list_facets-limit_product_list_page_size_ordering": "1",
"product_list_facets-sort_products_by_price_ordering": "1",
"product_list_facets-sort_products_by_name_ordering": "1",
"product_list_facets-sort_products_by_ascending_created_date_ordering": "1",
"product_list_facets-sort_products_by_date_created_ordering": "1",
"product_list_facets-filter_products_by_manufacturer_ordering": "1",
"product_list_facets-filter_products_by_variation_value_ordering": "1",
"order_configuration-order_reference_number_length": "20",
"order_configuration-order_reference_number_prefix": "10"
}
response = client.post(edit_url, data=payload)
assert response.status_code == 302
assert get_shop_available_languages(shop) == ["pt-br", "fi"]
activate(original_language)
示例12: test_gdpr_admin_download_data
# 需要导入模块: from shuup_tests.utils import SmartClient [as 别名]
# 或者: from shuup_tests.utils.SmartClient import post [as 别名]
def test_gdpr_admin_download_data(client, admin_user):
"""
Test that admin user can download customer data
"""
activate("en")
shop = factories.get_default_shop()
customer = factories.create_random_person("en")
product = factories.create_product("p1", shop, factories.get_default_supplier())
[factories.create_random_order(customer, [product]) for order in range(3)]
client = SmartClient()
admin_user.set_password("admin")
admin_user.save()
client.login(username=admin_user.username, password="admin")
admin_download_url = reverse("shuup_admin:gdpr.download_data", kwargs=dict(pk=customer.pk))
response = client.post(admin_download_url)
assert response.status_code == 200
assert response._headers["content-disposition"][0] == "Content-Disposition"
assert response._headers["content-disposition"][1].startswith("attachment; filename=user_data_")
示例13: test_get_installments_options_rest
# 需要导入模块: from shuup_tests.utils import SmartClient [as 别名]
# 或者: from shuup_tests.utils.SmartClient import post [as 别名]
def test_get_installments_options_rest():
patch_cielo_request()
shop = get_default_shop()
c = SmartClient()
# method not allowed
response = c.post(INSTALLMENTS_PATH)
assert response.status_code == 405
# missing parameters
response = c.get(INSTALLMENTS_PATH)
assert response.status_code == 400
# no CieloConfig for shop
response = c.get(INSTALLMENTS_PATH, {"cc_brand": CieloCardBrand.Visa})
assert response.status_code == 400
CieloConfig.objects.create(shop=shop)
# basket not valid (no products and not payment/shipping methods)
response = c.get(INSTALLMENTS_PATH, {"cc_brand": CieloCardBrand.Visa})
assert response.status_code == 400
create_default_order_statuses()
populate_if_required()
set_current_theme('shuup.themes.classic_gray')
# configures the user basket
_configure_basket(c)
# only 1 installment, because no configurations were set on CieloConfig
response = c.get(INSTALLMENTS_PATH, {"cc_brand": CieloCardBrand.Visa})
assert response.status_code == 200
# should be the order total
order_total = PRODUCT_QTNTY * PRODUCT_PRICE
total_price_str = "{0}".format(format_money(shop.create_price(order_total)))
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']
示例14: test_new_shop
# 需要导入模块: from shuup_tests.utils import SmartClient [as 别名]
# 或者: from shuup_tests.utils.SmartClient import post [as 别名]
def test_new_shop(rf, admin_user):
with override_settings(SHUUP_ENABLE_MULTIPLE_SHOPS=True):
get_default_shop()
assert Shop.objects.count() == 1
client = SmartClient()
client.login(username="admin", password="password")
client.soup(reverse("shuup_admin:shop.new"))
payload = {
"base-public_name__en": "New Shop",
"base-name__en": "New Shop",
"base-status": "1",
"base-currency": "EUR",
"base-domain": "shop2"
}
response = client.post(reverse("shuup_admin:shop.new"), data=payload)
assert response.status_code == 302
assert Shop.objects.count() == 2
shop = Shop.objects.last()
assert shop.name == "New Shop"
assert shop.domain == "shop2"
示例15: test_gdpr_admin_anonymize
# 需要导入模块: from shuup_tests.utils import SmartClient [as 别名]
# 或者: from shuup_tests.utils.SmartClient import post [as 别名]
def test_gdpr_admin_anonymize(client, admin_user):
"""
Test that admin user can anonymize contact
"""
activate("en")
factories.get_default_shop()
person = factories.create_random_person("en")
person.user = factories.create_random_user("en")
person.save()
client = SmartClient()
admin_user.set_password("admin")
admin_user.save()
client.login(username=admin_user.username, password="admin")
admin_anonymize_url = reverse("shuup_admin:gdpr.anonymize", kwargs=dict(pk=person.pk))
response = client.post(admin_anonymize_url)
assert response.status_code == 302
assert response.url.endswith(reverse("shuup_admin:contact.detail", kwargs=dict(pk=person.pk)))
anonymized_person = PersonContact.objects.get(id=person.id)
assert anonymized_person.name != person.name
assert anonymized_person.user.username != person.user.username