本文整理汇总了Python中shuup_tests.utils.SmartClient.response_and_soup方法的典型用法代码示例。如果您正苦于以下问题:Python SmartClient.response_and_soup方法的具体用法?Python SmartClient.response_and_soup怎么用?Python SmartClient.response_and_soup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shuup_tests.utils.SmartClient
的用法示例。
在下文中一共展示了SmartClient.response_and_soup方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_notify_on_company_created
# 需要导入模块: from shuup_tests.utils import SmartClient [as 别名]
# 或者: from shuup_tests.utils.SmartClient import response_and_soup [as 别名]
def test_notify_on_company_created(regular_user, allow_company_registration):
if "shuup.front.apps.customer_information" not in settings.INSTALLED_APPS:
pytest.skip("shuup.front.apps.customer_information required in installed apps")
if "shuup.notify" not in settings.INSTALLED_APPS:
pytest.skip("shuup.notify required in installed apps")
configuration.set(None, "allow_company_registration", allow_company_registration)
step = Step(
cond_op=StepConditionOperator.NONE,
actions=[
AddNotification({
"message": {"constant": "It Works. {{ customer_email }}"},
"message_identifier": {"constant": "company_created"},
})
],
next=StepNext.STOP
)
script = Script(
event_identifier=CompanyAccountCreated.identifier, name="Test Script", enabled=True, shop=get_default_shop())
script.set_steps([step])
script.save()
assert not Notification.objects.filter(identifier="company_created").exists()
assert get_person_contact(regular_user)
assert not get_company_contact(regular_user)
client = SmartClient()
client.login(username=REGULAR_USER_USERNAME, password=REGULAR_USER_PASSWORD)
company_edit_url = reverse("shuup:company_edit")
if allow_company_registration:
client.soup(company_edit_url)
data = _default_company_data()
data.update(_default_address_data("billing"))
data.update(_default_address_data("shipping"))
response, soup = client.response_and_soup(company_edit_url, data, "post")
assert response.status_code == 302
assert get_company_contact(regular_user)
assert Notification.objects.filter(identifier="company_created").count() == 1
notification = Notification.objects.filter(identifier="company_created").first()
assert notification
assert data["contact-email"] in notification.message
# New save should not add new notifications
response, soup = client.response_and_soup(company_edit_url, data, "post")
assert response.status_code == 302
assert Notification.objects.filter(identifier="company_created").count() == 1
script.delete()
else:
response = client.get(company_edit_url)
assert reverse("shuup:customer_edit") in response.url
assert Notification.objects.filter(identifier="company_created").count() == 0
示例2: test_company_tax_number_limitations
# 需要导入模块: from shuup_tests.utils import SmartClient [as 别名]
# 或者: from shuup_tests.utils.SmartClient import response_and_soup [as 别名]
def test_company_tax_number_limitations(regular_user):
get_default_shop()
person = get_person_contact(regular_user)
assert not get_company_contact(regular_user)
client = SmartClient()
client.login(username=REGULAR_USER_USERNAME, password=REGULAR_USER_PASSWORD)
company_edit_url = reverse("shuup:company_edit")
soup = client.soup(company_edit_url)
data = default_company_data()
data.update(default_address_data("billing"))
data.update(default_address_data("shipping"))
response, soup = client.response_and_soup(company_edit_url, data, "post")
assert response.status_code == 302
assert get_company_contact(regular_user)
# re-save should work properly
response, soup = client.response_and_soup(company_edit_url, data, "post")
assert response.status_code == 302
client.logout()
# another company tries to use same tax number
new_user_password = "derpy"
new_user_username = "derpy"
user = User.objects.create_user(new_user_username, "[email protected]", new_user_password)
person = get_person_contact(user=user)
assert not get_company_contact(user)
client = SmartClient()
client.login(username=new_user_username, password=new_user_password)
company_edit_url = reverse("shuup:company_edit")
soup = client.soup(company_edit_url)
data = default_company_data()
data.update(default_address_data("billing"))
data.update(default_address_data("shipping"))
response, soup = client.response_and_soup(company_edit_url, data, "post")
assert response.status_code == 200 # this time around, nothing was saved.
assert not get_company_contact(user) # company contact yet
# change tax number
data["contact-tax_number"] = "111111"
response, soup = client.response_and_soup(company_edit_url, data, "post")
assert response.status_code == 302 # this time around, nothing was saved.
assert get_company_contact(user) # company contact yet
# go back to normal and try to get tax number approved
data["contact-tax_number"] = "111110"
response, soup = client.response_and_soup(company_edit_url, data, "post")
assert response.status_code == 200 # this time around, nothing was saved.
示例3: test_order_configuration
# 需要导入模块: from shuup_tests.utils import SmartClient [as 别名]
# 或者: from shuup_tests.utils.SmartClient import response_and_soup [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
示例4: test_staff_authentication
# 需要导入模块: from shuup_tests.utils import SmartClient [as 别名]
# 或者: from shuup_tests.utils.SmartClient import response_and_soup [as 别名]
def test_staff_authentication():
shop = factories.get_shop(True, "USD", enabled=True)
staff_user = factories.create_random_user(is_staff=True)
staff_user.set_password("randpw")
staff_user.save()
staff_user.groups = [factories.get_default_permission_group()]
shop.staff_members.add(staff_user)
assert staff_user in [staff for staff in shop.staff_members.all()]
assert shop.status == ShopStatus.ENABLED
client = SmartClient()
url = reverse("shuup_admin:dashboard")
client.login(username=staff_user.username, password="randpw")
response, soup = client.response_and_soup(url)
assert response.status_code == 200
shop.status = ShopStatus.DISABLED
shop.save()
response, soup = client.response_and_soup(url)
assert response.status_code == 400
assert "There is no active shop available" in soup.text
示例5: test_checkout_empty_basket
# 需要导入模块: from shuup_tests.utils import SmartClient [as 别名]
# 或者: from shuup_tests.utils.SmartClient import response_and_soup [as 别名]
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()
示例6: test_shop_and_supplier_info
# 需要导入模块: from shuup_tests.utils import SmartClient [as 别名]
# 或者: from shuup_tests.utils.SmartClient import response_and_soup [as 别名]
def test_shop_and_supplier_info():
activate("en")
shop = factories.get_shop(True, "USD", enabled=True, name="Shop.com")
supplier = factories.get_default_supplier()
staff_user = factories.create_random_user(is_staff=True)
staff_user.set_password("randpw")
staff_user.save()
staff_user.groups = [factories.get_default_permission_group()]
shop.staff_members.add(staff_user)
assert staff_user in [staff for staff in shop.staff_members.all()]
assert shop.status == ShopStatus.ENABLED
client = SmartClient()
with override_settings(
SHUUP_ENABLE_MULTIPLE_SHOPS=True,
SHUUP_ENABLE_MULTIPLE_SUPPLIERS=False,
SHUUP_ADMIN_SUPPLIER_PROVIDER_SPEC="shuup.testing.supplier_provider.FirstSupplierProvider"
):
url = reverse("shuup_admin:dashboard")
client.login(username=staff_user.username, password="randpw")
response, soup = client.response_and_soup(url)
assert response.status_code == 200
assert shop.name in soup.find("div", {"class": "active-shop-and-supplier-info"}).text
assert supplier.name not in soup.find("div", {"class": "active-shop-and-supplier-info"}).text
with override_settings(
SHUUP_ENABLE_MULTIPLE_SHOPS=True,
SHUUP_ENABLE_MULTIPLE_SUPPLIERS=True,
SHUUP_ADMIN_SUPPLIER_PROVIDER_SPEC="shuup.testing.supplier_provider.FirstSupplierProvider"
):
url = reverse("shuup_admin:dashboard")
client.login(username=staff_user.username, password="randpw")
response, soup = client.response_and_soup(url)
assert response.status_code == 200
assert shop.name in soup.find("div", {"class": "active-shop-and-supplier-info"}).text
assert supplier.name in soup.find("div", {"class": "active-shop-and-supplier-info"}).text
示例7: test_user_change_password
# 需要导入模块: from shuup_tests.utils import SmartClient [as 别名]
# 或者: from shuup_tests.utils.SmartClient import response_and_soup [as 别名]
def test_user_change_password(regular_user, password_value, new_password_2, expected):
get_default_shop()
assert check_password(REGULAR_USER_PASSWORD, regular_user.password)
client = SmartClient()
client.login(username=REGULAR_USER_USERNAME, password=REGULAR_USER_PASSWORD)
change_password_url = reverse("shuup:change_password")
new_password = "12345"
data = {"old_password": password_value, "new_password1": new_password, "new_password2": new_password_2}
response, soup = client.response_and_soup(change_password_url, data, "post")
user = get_user_model().objects.get(pk=regular_user.pk)
assert regular_user == user
assert check_password(REGULAR_USER_PASSWORD, user.password) != expected
assert check_password(new_password, user.password) == expected
示例8: test_company_edit_form_links_company
# 需要导入模块: from shuup_tests.utils import SmartClient [as 别名]
# 或者: from shuup_tests.utils.SmartClient import response_and_soup [as 别名]
def test_company_edit_form_links_company(regular_user, rf):
get_default_shop()
person = get_person_contact(regular_user)
assert not get_company_contact(regular_user)
client = SmartClient()
client.login(username=REGULAR_USER_USERNAME, password=REGULAR_USER_PASSWORD)
company_edit_url = reverse("shuup:company_edit")
soup = client.soup(company_edit_url)
data = default_company_data()
data.update(default_address_data("billing"))
data.update(default_address_data("shipping"))
response, soup = client.response_and_soup(company_edit_url, data, "post")
assert response.status_code == 302
assert get_company_contact(regular_user)
示例9: test_new_user_information_edit
# 需要导入模块: from shuup_tests.utils import SmartClient [as 别名]
# 或者: from shuup_tests.utils.SmartClient import response_and_soup [as 别名]
def test_new_user_information_edit():
client = SmartClient()
get_default_shop()
# create new user
user_password = "niilo"
user = get_user_model().objects.create_user(
username="Niilo_Nyyppa",
email="[email protected]",
password=user_password,
first_name="Niilo",
last_name="Nyyppä",
)
client.login(username=user.username, password=user_password)
# make sure all information matches in form
customer_edit_url = reverse("shuup:customer_edit")
soup = client.soup(customer_edit_url)
assert soup.find(attrs={"name": "contact-email"})["value"] == user.email
assert soup.find(attrs={"name": "contact-first_name"})["value"] == user.first_name
assert soup.find(attrs={"name": "contact-last_name"})["value"] == user.last_name
# Test POSTing
form = extract_form_fields(soup)
new_email = "[email protected]"
form["contact-email"] = new_email
form["contact-country"] = "FI"
for prefix in ("billing", "shipping"):
form["%s-city" % prefix] = "test-city"
form["%s-email" % prefix] = new_email
form["%s-street" % prefix] = "test-street"
form["%s-country" % prefix] = "FI"
response, soup = client.response_and_soup(customer_edit_url, form, "post")
assert response.status_code == 302
assert get_user_model().objects.get(pk=user.pk).email == new_email
示例10: test_invalid_files
# 需要导入模块: from shuup_tests.utils import SmartClient [as 别名]
# 或者: from shuup_tests.utils.SmartClient import response_and_soup [as 别名]
def test_invalid_files(rf, admin_user):
lang = "en"
import_mode = ImportMode.CREATE_UPDATE
sku = "123"
name = "test"
import_path = reverse("shuup_admin:importer.import")
process_path = reverse("shuup_admin:importer.import_process")
tax_class = get_default_tax_class()
product_type = get_default_product_type()
get_default_sales_unit()
activate("en")
shop = get_default_shop()
shop.staff_members.add(admin_user)
client = SmartClient()
client.login(username="admin", password="password")
csv_content = str.encode("sku;name\n%s;%s" % (sku, name))
# show import view
data = {
"importer": "product_importer",
"shop": shop.pk,
"language": lang,
"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 = { # data with missing `n`
"importer": "product_importer",
"shop": shop.pk,
"language": lang,
}
response, soup = client.response_and_soup(process_path, data=data)
assert response.status_code == 400
assert "File missing." in str(soup)
示例11: test_company_still_linked_if_customer_contact_edited
# 需要导入模块: from shuup_tests.utils import SmartClient [as 别名]
# 或者: from shuup_tests.utils.SmartClient import response_and_soup [as 别名]
def test_company_still_linked_if_customer_contact_edited(regular_user):
get_default_shop()
person = get_person_contact(regular_user)
assert not get_company_contact(regular_user)
company = CompanyContact()
company.save()
company.members.add(person)
assert get_company_contact(regular_user)
client = SmartClient()
client.login(username=REGULAR_USER_USERNAME, password=REGULAR_USER_PASSWORD)
customer_edit_url = reverse("shuup:customer_edit")
soup = client.soup(customer_edit_url)
data = default_customer_data()
data.update(default_address_data("billing"))
data.update(default_address_data("shipping"))
response, soup = client.response_and_soup(customer_edit_url, data, "post")
assert response.status_code == 302
assert get_company_contact(regular_user)
示例12: test_company_edit_form_links_company
# 需要导入模块: from shuup_tests.utils import SmartClient [as 别名]
# 或者: from shuup_tests.utils.SmartClient import response_and_soup [as 别名]
def test_company_edit_form_links_company(regular_user, allow_company_registration):
get_default_shop()
configuration.set(None, "allow_company_registration", allow_company_registration)
person = get_person_contact(regular_user)
assert not get_company_contact(regular_user)
client = SmartClient()
client.login(username=REGULAR_USER_USERNAME, password=REGULAR_USER_PASSWORD)
data = default_company_data()
data.update(default_address_data("billing"))
data.update(default_address_data("shipping"))
company_edit_url = reverse("shuup:company_edit")
if allow_company_registration:
soup = client.soup(company_edit_url)
response, soup = client.response_and_soup(company_edit_url, data, "post")
assert response.status_code == 302
assert get_company_contact(regular_user)
else:
response = client.get(company_edit_url)
assert response.status_code == 404
response = client.post(company_edit_url, data)
assert response.status_code == 404
示例13: test_invalid_file_type
# 需要导入模块: from shuup_tests.utils import SmartClient [as 别名]
# 或者: from shuup_tests.utils.SmartClient import response_and_soup [as 别名]
def test_invalid_file_type(rf, admin_user):
lang = "en"
import_mode = ImportMode.CREATE_UPDATE
sku = "123"
name = "test"
import_path = reverse("shuup_admin:importer.import")
process_path = reverse("shuup_admin:importer.import_process")
get_default_tax_class()
get_default_product_type()
get_default_sales_unit()
activate("en")
shop = get_default_shop()
shop.staff_members.add(admin_user)
client = SmartClient()
client.login(username="admin", password="password")
csv_content = str.encode("sku;name\n%s;%s" % (sku, name))
# show import view
data = {
"importer": "product_importer",
"shop": shop.pk,
"language": lang,
"file": SimpleUploadedFile("file.derp", 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 = { # data with missing `n`
"importer": "product_importer",
"shop": shop.pk,
"language": lang,
}
response, soup = client.response_and_soup(process_path, data=data)
assert response.status_code == 400
for row in soup.findAll("tr"):
first_td = row.find("td")
if not first_td:
continue
tds = row.findAll("td")
if len(tds) < 2:
continue
second_td = tds[1]
if first_td.text.startswith("Connection"):
# check that sku was connected
badges = second_td.findAll("span", {"class": "badge"})
assert len(badges) == 1
assert badges[0].text == "sku"
elif first_td.text.startswith("The following fields"):
badges = second_td.findAll("span", {"class": "badge"})
assert len(badges) == 2
badge_texts = []
for b in badges:
badge_texts.append(b.text)
badge_texts.sort()
assert badge_texts[0] == "name"
assert badge_texts[1] == "sku"
data = {}
data["import_mode"] = import_mode.value
process_submit_path = "%s?%s" % (process_path, query_string)
response = client.post(process_submit_path, data=data)
assert response.status_code == 302