本文整理汇总了Python中shoop.testing.factories.create_random_person函数的典型用法代码示例。如果您正苦于以下问题:Python create_random_person函数的具体用法?Python create_random_person怎么用?Python create_random_person使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_random_person函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_category_links_plugin_with_customer
def test_category_links_plugin_with_customer(rf, show_all_categories):
"""
Test plugin for categories that is visible for certain group
"""
shop = get_default_shop()
group = get_default_customer_group()
customer = create_random_person()
customer.groups.add(group)
customer.save()
request = rf.get("/")
request.shop = get_default_shop()
apply_request_middleware(request)
request.customer = customer
category = get_default_category()
category.status = CategoryStatus.VISIBLE
category.visibility = CategoryVisibility.VISIBLE_TO_GROUPS
category.visibility_groups.add(group)
category.shops.add(shop)
category.save()
vars = {"request": request}
context = get_jinja_context(**vars)
plugin = CategoryLinksPlugin({"categories": [category.pk], "show_all_categories": show_all_categories})
assert category.is_visible(customer)
assert category in plugin.get_context_data(context)["categories"]
customer_without_groups = create_random_person()
customer_without_groups.groups.clear()
assert not category.is_visible(customer_without_groups)
request.customer = customer_without_groups
context = get_jinja_context(**vars)
assert category not in plugin.get_context_data(context)["categories"]
示例2: test_basket_contact_condition
def test_basket_contact_condition(rf):
product_price_value, campaign_discount_value = 2, 1
request = get_request_for_contact_tests(rf)
random_person = create_random_person()
request.customer = random_person
condition = ContactBasketCondition.objects.create()
condition.contacts.add(random_person)
basket, original_line_count, original_price = create_basket_and_campaign(
request, [condition], product_price_value, campaign_discount_value)
# random_person should get this campaign
assert basket.customer == random_person
assert_discounted_basket(basket, original_line_count, original_price, campaign_discount_value)
another_random_person = create_random_person()
basket.customer = another_random_person
# another random person shouldn't
assert_non_discounted_basket(basket, original_line_count, original_price)
# Add another random person for the rule and see if he get's the discount
condition.contacts.add(another_random_person)
condition.save()
assert_discounted_basket(basket, original_line_count, original_price, campaign_discount_value)
assert basket.customer == another_random_person
# Remove random person from rule and see the discount disappear
condition.contacts.remove(random_person)
condition.save()
basket.customer = random_person
assert_non_discounted_basket(basket, original_line_count, original_price)
assert basket.customer == random_person
示例3: test_coupon_amount_limit
def test_coupon_amount_limit():
coupon = Coupon.objects.create(code="TEST", active=True)
get_default_campaign(coupon)
contact = create_random_person()
shop = get_default_shop()
product = create_product("test", shop=shop, supplier=get_default_supplier(), default_price="12")
order = create_random_order(customer=contact)
for x in range(50):
coupon.use(order)
assert coupon.usages.count() == 50
coupon.increase_usage_limit_by(5)
coupon.save()
assert coupon.usage_limit == 55
assert coupon.can_use_code(contact)
for x in range(5):
coupon.use(order)
assert coupon.usages.count() == 55
assert not Coupon.is_usable(coupon.code, order.customer)
assert coupon.usages.count() == 55 # no change, limit met
示例4: test_contact_details_view_with_many_groups
def test_contact_details_view_with_many_groups(rf, admin_user):
get_default_shop()
person = create_random_person()
person.groups.add(
ContactGroup.objects.create(name="Czz Group"),
ContactGroup.objects.create(name="Azz Group"),
ContactGroup.objects.create(name="Bzz Group"),
ContactGroup.objects.language('fi').create(name="Dzz ryhmä"),
)
# Group with name in two languages
grp_e = ContactGroup.objects.language('en').create(name="Ezz Group")
grp_e.set_current_language('fi')
grp_e.name = "Ezz ryhmä"
grp_e.save()
person.groups.add(grp_e)
request = apply_request_middleware(rf.get("/"), user=admin_user)
with translation.override('en'):
view_func = ContactDetailView.as_view()
response = view_func(request, pk=person.pk)
content = response.render().content.decode('utf-8')
assert "Azz Group" in content
assert "Bzz Group" in content
assert "Czz Group" in content
assert "Dzz ryhmä" in content, "no name in active language, still present"
assert "Ezz Group" in content, "rendered with active language"
positions = [content.index(x + "zz ") for x in 'ABCDE']
assert positions == sorted(positions), "Groups are sorted"
assert response.status_code == 200
示例5: test_min_amount_is_not_included
def test_min_amount_is_not_included():
shop = get_default_shop()
supplier = get_default_supplier()
person = create_random_person()
initial_group_count = person.groups.count()
sales_ranges = [
("silver", 0, 50),
("gold", 50, 100),
("diamond", 100, 1000),
("reverse_diamond", 1000, 100)
]
for identifier, min, max in sales_ranges:
create_sales_range(identifier, shop, min, max)
payment = create_fully_paid_order(shop, person, supplier, "sku1", 50)
assert get_total_sales(shop, person) == 50
update_customers_groups(Payment, payment)
assert person.groups.count() == (initial_group_count + 1)
assert bool([group for group in person.groups.all() if group.identifier == "gold"])
assert not bool([group for group in person.groups.all() if group.identifier in ["silver", "diamond"]])
payment = create_fully_paid_order(shop, person, supplier, "sku2", 50)
assert get_total_sales(shop, person) == 100
update_customers_groups(Payment, payment)
assert person.groups.count() == (initial_group_count + 1)
assert bool([group for group in person.groups.all() if group.identifier == "diamond"])
assert not bool([group for group in person.groups.all() if group.identifier == "reverse_diamond"])
assert not bool([group for group in person.groups.all() if group.identifier in ["silver", "gold"]])
示例6: test_user_detail_contact_seed
def test_user_detail_contact_seed(rf):
get_default_shop()
contact = create_random_person()
view_func = UserDetailView.as_view()
# Check that fields populate . . .
request = apply_request_middleware(rf.get("/", {"contact_id": contact.pk}))
response = view_func(request)
response.render()
content = force_text(response.content)
assert force_text(contact.first_name) in content
assert force_text(contact.last_name) in content
assert force_text(contact.email) in content
# POST the password too to create the user . . .
post = extract_form_fields(BeautifulSoup(content))
post["password"] = "HELLO WORLD"
request.method = "POST"
request.POST = post
response = view_func(request)
assert response.status_code < 500
# Check this new user is visible in the details now
user = Contact.objects.get(pk=contact.pk).user
request = apply_request_middleware(rf.get("/", {"contact_id": contact.pk}))
response = view_func(request, pk=user.pk)
response.render()
content = force_text(response.content)
assert force_text(contact.first_name) in content
assert force_text(contact.last_name) in content
assert force_text(contact.email) in content
示例7: test_protected_fields
def test_protected_fields():
activate("en")
shop = Shop.objects.create(
name="testshop",
identifier="testshop",
status=ShopStatus.ENABLED,
public_name="test shop",
domain="derp",
currency="EUR"
)
assert shop.name == "testshop"
assert shop.currency == "EUR"
shop_form = ShopBaseForm(instance=shop, languages=settings.LANGUAGES)
assert not shop_form._get_protected_fields() # No protected fields just yet, right?
data = get_form_data(shop_form, prepared=True)
shop_form = ShopBaseForm(data=data, instance=shop, languages=settings.LANGUAGES)
_test_cleanliness(shop_form)
shop_form.save()
# Now let's make it protected!
create_product(printable_gibberish(), shop=shop, supplier=get_default_supplier())
order = create_random_order(customer=create_random_person(), shop=shop)
assert order.shop == shop
# And try again...
data["currency"] = "XBT" # Bitcoins!
shop_form = ShopBaseForm(data=data, instance=shop, languages=settings.LANGUAGES)
assert shop_form._get_protected_fields() # So protected!
_test_cleanliness(shop_form)
shop = shop_form.save()
assert shop.currency == "EUR" # But the shop form ignored the change . . .
示例8: test_order_creator_view_for_customer
def test_order_creator_view_for_customer(rf, admin_user):
get_default_shop()
contact = create_random_person(locale="en_US", minimum_name_comp_len=5)
request = apply_request_middleware(rf.get("/", {"contact_id": contact.id}), user=admin_user)
response = OrderEditView.as_view()(request)
assert_contains(response, "customerData") # in the config
assert_contains(response, "isCompany") # in the config
示例9: test_sales_ranges_update_after_range_update
def test_sales_ranges_update_after_range_update():
shop = get_default_shop()
supplier = get_default_supplier()
person = create_random_person()
company = create_random_company()
create_fully_paid_order(shop, person, supplier, "sku1", 50)
create_fully_paid_order(shop, company, supplier, "sku2", 100)
assert get_total_sales(shop, person) == 50
assert get_total_sales(shop, company) == 100
sales_range = create_sales_range("gold", shop, 10, 90)
assert sales_range.group in person.groups.all()
assert sales_range.group not in company.groups.all()
sales_range.max_value = None
sales_range.save()
assert sales_range.group in person.groups.all()
assert sales_range.group in company.groups.all()
# Make sure customers is actually removed when range changes
sales_range.max_value = 60
sales_range.save()
assert sales_range.group in person.groups.all()
assert sales_range.group not in company.groups.all()
# Inactive ranges shouldn't update group members
sales_range.min_value = None
sales_range.save()
assert sales_range.group in person.groups.all()
assert sales_range.group not in company.groups.all()
示例10: test_campaign_with_non_active_coupon
def test_campaign_with_non_active_coupon(rf):
initial_status = get_initial_order_status()
request, shop, group = initialize_test(rf, include_tax=False)
order = _get_order_with_coupon(request, initial_status)
coupon = order.coupon_usages.first().coupon
coupon.active = False
coupon.save()
modifier = UserFactory()
contact = create_random_person(locale="en_US", minimum_name_comp_len=5)
assert order.customer != contact
state = _get_frontend_order_state(shop, contact)
assert order.shop.id == state["shop"]["selected"]["id"]
request = get_frontend_request_for_command(state, "finalize", modifier)
response = OrderEditView.as_view()(request, pk=order.pk)
assert_contains(response, "orderIdentifier")
data = json.loads(response.content.decode("utf8"))
edited_order = Order.objects.get(pk=order.pk)
assert edited_order.identifier == data["orderIdentifier"] == order.identifier
assert edited_order.pk == order.pk
assert edited_order.lines.count() == 3
assert OrderLineType.DISCOUNT not in [l.type for l in edited_order.lines.all()]
assert edited_order.coupon_usages.count() == 0
示例11: test_order_creator_source_data
def test_order_creator_source_data(rf, admin_user):
get_initial_order_status() # Needed for the API
contact = create_random_person(locale="en_US", minimum_name_comp_len=5)
request = get_frontend_request_for_command(get_frontend_order_state(contact), "source_data", admin_user)
response = OrderCreateView.as_view()(request)
data = json.loads(response.content.decode("utf8"))
assert len(data.get("orderLines")) == 5
示例12: test_sales_between_ranges
def test_sales_between_ranges():
shop = get_default_shop()
supplier = get_default_supplier()
person = create_random_person()
initial_group_count = person.groups.count()
sales_ranges = [
("wood", 15, 0),
("silver", 0, 50),
("diamond", 100, None)
]
for identifier, min, max in sales_ranges:
create_sales_range(identifier, shop, min, max)
payment = create_fully_paid_order(shop, person, supplier, "sku1", 10)
assert get_total_sales(shop, person) == 10
update_customers_groups(Payment, payment)
assert person.groups.count() == (initial_group_count + 1)
assert bool([group for group in person.groups.all() if group.identifier == "silver"])
assert not bool([group for group in person.groups.all() if group.identifier == "wood"])
payment = create_fully_paid_order(shop, person, supplier, "sku2", 50)
assert get_total_sales(shop, person) == 60
update_customers_groups(Payment, payment)
assert person.groups.count() == initial_group_count
assert not bool([group for group in person.groups.all() if group.identifier in ["silver", "gold", "diamond"]])
payment = create_fully_paid_order(shop, person, supplier, "sku3", 200)
assert get_total_sales(shop, person) == 260
update_customers_groups(Payment, payment)
assert person.groups.count() == (initial_group_count + 1)
assert bool([group for group in person.groups.all() if group.identifier == "diamond"])
示例13: test_user_detail_contact_seed
def test_user_detail_contact_seed(rf):
get_default_shop()
contact = create_random_person()
# Using random data for name and email would need escaping when
# checking if it is rendered, therefore use something very basic instead
contact.name = "Matti Perustyyppi"
contact.email = "[email protected]"
contact.save()
view_func = UserDetailView.as_view()
# Check that fields populate . . .
request = apply_request_middleware(rf.get("/", {"contact_id": contact.pk}))
response = view_func(request)
response.render()
content = force_text(response.content)
assert force_text(contact.first_name) in content
assert force_text(contact.last_name) in content
assert force_text(contact.email) in content
# POST the password too to create the user . . .
post = extract_form_fields(BeautifulSoup(content))
post["password"] = "HELLO WORLD"
request.method = "POST"
request.POST = post
response = view_func(request)
assert response.status_code < 500
# Check this new user is visible in the details now
user = Contact.objects.get(pk=contact.pk).user
request = apply_request_middleware(rf.get("/", {"contact_id": contact.pk}))
response = view_func(request, pk=user.pk)
response.render()
content = force_text(response.content)
assert force_text(contact.first_name) in content
assert force_text(contact.last_name) in content
assert force_text(contact.email) in content
示例14: get_initialized_test_event
def get_initialized_test_event():
get_default_product()
customer = create_random_person()
order = create_random_order(customer)
return ATestEvent(
order_language=order.language,
order=order,
just_some_text=random_title()
)
示例15: test_contact_module_search
def test_contact_module_search(rf):
cm = ContactModule()
# This test has a chance to fail if the random person is from a strange locale
# and the database does not like it. Therefore, use `en_US` here...
contact = create_random_person(locale="en_US", minimum_name_comp_len=5)
request = rf.get("/")
assert not empty_iterable(cm.get_search_results(request, query=contact.email))
assert not empty_iterable(cm.get_search_results(request, query=contact.first_name))
assert empty_iterable(cm.get_search_results(request, query=contact.email[0]))