本文整理汇总了Python中shuup_tests.utils.printable_gibberish函数的典型用法代码示例。如果您正苦于以下问题:Python printable_gibberish函数的具体用法?Python printable_gibberish怎么用?Python printable_gibberish使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了printable_gibberish函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_draft_reversion
def test_draft_reversion():
view_name = printable_gibberish()
theme = ATestTheme()
placeholder_name = "test_ph"
vc = ViewConfig(theme=theme, view_name=view_name, draft=True)
def get_layout_data(draft):
# shorthand -- we're going to be doing this a lot in this test case
return ViewConfig(theme=theme, view_name=view_name, draft=draft).saved_view_config.get_layout_data(placeholder_name)
data1 = {printable_gibberish(): True}
data2 = {printable_gibberish(): True}
vc.save_placeholder_layout(placeholder_name, data1)
vc.publish()
assert get_layout_data(draft=False) == data1
assert get_layout_data(draft=True) == data1
vc = ViewConfig(theme=theme, view_name=view_name, draft=True)
svc = vc.saved_view_config
assert svc.draft
assert svc.get_layout_data(placeholder_name) == data1
# Make changes over the last published version
svc.set_layout_data(placeholder_name, data2)
svc.save()
# Still all good in public?
assert get_layout_data(draft=False) == data1
# Still got it in draft?
assert get_layout_data(draft=True) == data2
# Actually revert those draft changes now!
vc.revert()
# So in draft we're back to the published version, right?
assert get_layout_data(draft=True) == data1
示例2: test_mass_edit_products2
def test_mass_edit_products2(rf, admin_user):
shop = get_default_shop()
supplier = get_default_supplier()
product1 = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price="50")
product2 = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price="501")
shop_product1 = product1.get_shop_instance(shop)
shop_product2 = product2.get_shop_instance(shop)
# ensure no categories set
assert shop_product1.primary_category is None
assert shop_product2.primary_category is None
payload = {
"action": InvisibleMassAction().identifier,
"values": [product1.pk, product2.pk]
}
request = apply_request_middleware(rf.post(
"/",
user=admin_user,
))
request._body = json.dumps(payload).encode("UTF-8")
view = ProductListView.as_view()
response = view(request=request)
assert response.status_code == 200
for product in Product.objects.all():
assert product.get_shop_instance(shop).visibility == ShopProductVisibility.NOT_VISIBLE
示例3: test_mass_edit_orders
def test_mass_edit_orders(rf, admin_user):
shop = get_default_shop()
supplier = get_default_supplier()
contact1 = create_random_person()
product1 = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price="50")
product2 = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price="501")
order = create_random_order(customer=contact1,
products=[product1, product2],
completion_probability=0)
assert order.status.role != OrderStatusRole.CANCELED
payload = {
"action": CancelOrderAction().identifier,
"values": [order.pk]
}
request = apply_request_middleware(rf.post(
"/",
user=admin_user,
))
request._body = json.dumps(payload).encode("UTF-8")
view = OrderListView.as_view()
response = view(request=request)
assert response.status_code == 200
for order in Order.objects.all():
assert order.status.role == OrderStatusRole.CANCELED
示例4: 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
示例5: test_mass_edit_orders3
def test_mass_edit_orders3(rf, admin_user):
shop = get_default_shop()
supplier = get_default_supplier()
contact1 = create_random_person()
product1 = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price="50")
product2 = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price="501")
order1 = create_random_order(customer=contact1,
products=[product1, product2],
completion_probability=0)
order2 = create_random_order(customer=contact1,
products=[product1, product2],
completion_probability=0)
assert order1.status.role != OrderStatusRole.CANCELED
assert order2.status.role != OrderStatusRole.CANCELED
payload = {
"action": OrderConfirmationPdfAction().identifier,
"values": [order1.pk, order2.pk]
}
request = apply_request_middleware(rf.post(
"/",
user=admin_user,
))
request._body = json.dumps(payload).encode("UTF-8")
view = OrderListView.as_view()
response = view(request=request)
assert response.status_code == 200
if weasyprint:
assert response['Content-Disposition'] == 'attachment; filename=order_confirmation_pdf.zip'
else:
assert response["content-type"] == "application/json"
示例6: test_user_list
def test_user_list(rf, admin_user):
shop = get_default_shop()
user = get_user_model().objects.create(
username=printable_gibberish(20),
first_name=printable_gibberish(10),
last_name=printable_gibberish(10),
password="suihku",
is_staff=True,
is_superuser=False
)
shop.staff_members.add(user)
view_func = UserListView.as_view()
request = rf.get("/", {"jq": json.dumps({"perPage": 100, "page": 1})})
# check with superuser
response = view_func(apply_request_middleware(request, user=admin_user))
assert response.status_code == 200
data = json.loads(response.content.decode("utf-8"))
assert len(data["items"]) == 2
# check with staff user
response = view_func(apply_request_middleware(request, user=user))
assert response.status_code == 200
data = json.loads(response.content.decode("utf-8"))
assert len(data["items"]) == 1
示例7: test_basket_shipping_error
def test_basket_shipping_error(rf):
StoredBasket.objects.all().delete()
shop = get_default_shop()
supplier = get_default_supplier()
shipped_product = create_product(
printable_gibberish(), shop=shop, supplier=supplier, default_price=50,
shipping_mode=ShippingMode.SHIPPED
)
unshipped_product = create_product(
printable_gibberish(), shop=shop, supplier=supplier, default_price=50,
shipping_mode=ShippingMode.NOT_SHIPPED
)
request = rf.get("/")
request.session = {}
request.shop = shop
apply_request_middleware(request)
basket = get_basket(request)
# With a shipped product but no shipping methods, we oughta get an error
basket.add_product(supplier=supplier, shop=shop, product=shipped_product, quantity=1)
assert any(ve.code == "no_common_shipping" for ve in basket.get_validation_errors())
basket.clear_all()
# But with an unshipped product, we should not
basket.add_product(supplier=supplier, shop=shop, product=unshipped_product, quantity=1)
assert not any(ve.code == "no_common_shipping" for ve in basket.get_validation_errors())
示例8: test_move_file
def test_move_file():
folder1 = Folder.objects.create(name=printable_gibberish())
folder2 = Folder.objects.create(name=printable_gibberish())
file = File.objects.create(folder=folder1)
mbv_command({"action": "move_file", "file_id": file.pk, "folder_id": folder2.pk})
assert File.objects.get(pk=file.pk).folder == folder2
mbv_command({"action": "move_file", "file_id": file.pk, "folder_id": 0})
assert File.objects.get(pk=file.pk).folder is None
示例9: test_editor_view_commands
def test_editor_view_commands():
with initialize_editor_view(printable_gibberish(), printable_gibberish()) as view_obj:
view_obj.request.method = "POST"
view_obj.request.POST = {"command": "add_row"}
view_obj._populate_vars() # don't tell anyone we're calling a private method here
assert len(view_obj.layout) == 0
view_obj.dispatch(view_obj.request)
assert len(view_obj.layout) == 1
示例10: test_get_folder
def test_get_folder():
folder1 = Folder.objects.create(name=printable_gibberish())
folder2 = Folder.objects.create(name=printable_gibberish(), parent=folder1)
root_resp = mbv_command({"action": "folder"}, "GET")
assert any(f["id"] == folder1.pk for f in root_resp["folder"]["folders"])
f1_resp = mbv_command({"action": "folder", "id": folder1.pk}, "GET")
assert f1_resp["folder"]["folders"][0]["id"] == folder2.pk
assert not f1_resp["folder"]["files"]
assert f1_resp["folder"]["name"] == folder1.name
assert mbv_command({"action": "folder", "id": -1}, "GET")["error"]
示例11: test_basket_free_product
def test_basket_free_product(rf):
request, shop, _ = initialize_test(rf, False)
basket = get_basket(request)
supplier = get_default_supplier()
single_product_price = "50"
original_quantity = 2
# create basket rule that requires 2 products in basket
product = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price=single_product_price)
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=2)
basket.shipping_method = get_shipping_method(shop=shop)
basket.save()
second_product = create_product(printable_gibberish(),
shop=shop,
supplier=supplier,
default_price=single_product_price)
# no shop
third_product = create_product(printable_gibberish(), supplier=supplier)
rule = BasketTotalProductAmountCondition.objects.create(value="2")
campaign = BasketCampaign.objects.create(active=True, shop=shop, name="test", public_name="test")
campaign.conditions.add(rule)
effect = FreeProductLine.objects.create(campaign=campaign, quantity=2)
effect.products.add(second_product)
discount_lines_count = len(effect.get_discount_lines(basket, [], supplier))
assert discount_lines_count == 1
# do not affect as there is no shop product for the product
effect.products.add(third_product)
assert len(effect.get_discount_lines(basket, [], supplier)) == discount_lines_count
basket.uncache()
final_lines = basket.get_final_lines()
assert len(final_lines) == 3
line_types = [l.type for l in final_lines]
assert OrderLineType.DISCOUNT not in line_types
for line in basket.get_final_lines():
assert line.type in [OrderLineType.PRODUCT, OrderLineType.SHIPPING]
if line.type == OrderLineType.SHIPPING:
continue
if line.product != product:
assert line.product == second_product
assert line.line_source == LineSource.DISCOUNT_MODULE
assert line.quantity == original_quantity
else:
assert line.line_source == LineSource.CUSTOMER
示例12: test_deleting_mid_folder
def test_deleting_mid_folder(rf):
folder1 = Folder.objects.create(name=printable_gibberish())
folder2 = Folder.objects.create(name=printable_gibberish(), parent=folder1)
folder3 = Folder.objects.create(name=printable_gibberish(), parent=folder2)
tree = get_id_tree(mbv_command({"action": "folders"}, "GET"))
assert tree[folder1.pk] == {folder2.pk: {folder3.pk: {}}}
mbv_command({"action": "delete_folder", "id": folder2.pk})
tree = get_id_tree(mbv_command({"action": "folders"}, "GET"))
assert tree[folder1.pk] == {folder3.pk: {}}
folder1 = Folder.objects.get(pk=folder1.pk)
assert list(folder1.get_children()) == [folder3]
示例13: test_get_folders
def test_get_folders(rf):
# Create a structure and retrieve it
folder1 = Folder.objects.create(name=printable_gibberish())
folder2 = Folder.objects.create(name=printable_gibberish())
folder3 = Folder.objects.create(name=printable_gibberish())
folder4 = Folder.objects.create(name=printable_gibberish(), parent=folder2)
folder5 = Folder.objects.create(name=printable_gibberish(), parent=folder3)
tree = get_id_tree(mbv_command({"action": "folders"}, "GET"))
assert set((folder1.id, folder2.id, folder3.id)) <= set(tree.keys())
assert folder4.pk in tree[folder2.pk]
assert folder5.pk in tree[folder3.pk]
示例14: test_variable_variation_form
def test_variable_variation_form():
var1 = printable_gibberish()
var2 = printable_gibberish()
parent = create_product(printable_gibberish())
for a in range(4):
for b in range(3):
child = create_product(printable_gibberish())
child.link_to_parent(parent, variables={var1: a, var2: b})
assert parent.variation_children.count() == 4 * 3
form = VariableVariationChildrenForm(parent_product=parent)
assert len(form.fields) == 12
示例15: test_undiscounted_effects
def test_undiscounted_effects(rf, include_tax):
request, shop, _ = initialize_test(rf, include_tax)
basket = get_basket(request)
supplier = get_default_supplier()
single_product_price = Decimal(50)
discounted_product_quantity = 4
normal_priced_product_quantity = 2
discount_percentage = Decimal(0.2) # 20%
discount_amount = basket.create_price(single_product_price * normal_priced_product_quantity * discount_percentage)
category = CategoryFactory()
discounted_product = create_product(
printable_gibberish(), shop=shop, supplier=supplier, default_price=single_product_price)
second_product = create_product(
printable_gibberish(), shop=shop, supplier=supplier, default_price=single_product_price)
ShopProduct.objects.get(shop=shop, product=discounted_product).categories.add(category)
ShopProduct.objects.get(shop=shop, product=second_product).categories.add(category)
basket.add_product(supplier=supplier, shop=shop, product=discounted_product, quantity=discounted_product_quantity)
basket.add_product(supplier=supplier, shop=shop, product=second_product, quantity=normal_priced_product_quantity)
basket.shipping_method = get_shipping_method(shop=shop)
basket.save()
# Store basket price before any campaigns exists
original_price = basket.total_price
# CatalogCampaign
catalog_campaign = CatalogCampaign.objects.create(active=True, shop=shop, name="test", public_name="test")
# Limit catalog campaign to "discounted_product"
product_filter = ProductFilter.objects.create()
product_filter.products.add(discounted_product)
catalog_campaign.filters.add(product_filter)
# BasketCampaign
campaign = BasketCampaign.objects.create(
active=True, shop=shop, name="test2", public_name="test2")
final_lines = basket.get_final_lines()
assert len(final_lines) == 3
# Discount based on undiscounted product values
DiscountPercentageFromUndiscounted.objects.create(campaign=campaign, discount_percentage=discount_percentage)
basket.uncache()
final_lines = basket.get_final_lines()
assert len(final_lines) == 4
discounted_basket_price = original_price - discount_amount
assert basket.total_price.as_rounded() == discounted_basket_price.as_rounded()