本文整理汇总了Python中shuup.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_context_contact_condition
def test_context_contact_condition():
rf = RequestFactory()
original_price_value, discount_value = 2, 1
request = get_request_for_contact_tests(rf)
random_person = create_random_person()
condition = ContactCondition.objects.create()
condition.contacts.add(random_person)
product = create_random_product_and_campaign(request.shop, [condition], original_price_value, discount_value)
# random_person should get this campaign
discounted_value = original_price_value - discount_value
assert_product_price_value_with_customer(request, random_person, product, discounted_value)
another_random_person = create_random_person()
# another random person shouldn't
assert_product_price_value_with_customer(request, another_random_person, product, original_price_value)
# Add another random person for the rule and see if he get's the discount
condition.contacts.add(another_random_person)
assert_product_price_value_with_customer(request, another_random_person, product, discounted_value)
# Remove random person from rule and see the discount disappear
condition.contacts.remove(random_person)
condition.save()
assert_product_price_value_with_customer(request, random_person, product, original_price_value)
示例3: test_order_creator_account_manager
def test_order_creator_account_manager():
company = create_random_company()
shop = get_shop(identifier="random-shop", enabled=True)
source = seed_source(create_random_user(), shop)
source.customer = company
source.add_line(
type=OrderLineType.PRODUCT,
product=get_default_product(),
supplier=get_default_supplier(),
quantity=1,
base_unit_price=source.create_price(10),
)
creator = OrderCreator()
order = creator.create_order(source)
assert order.account_manager is None # Company contact doesn't have account manager field
person = create_random_person()
person.account_manager = create_random_person()
person.save()
source = seed_source(create_random_user(), shop)
source.customer = person
source.add_line(
type=OrderLineType.PRODUCT,
product=get_default_product(),
supplier=get_default_supplier(),
quantity=1,
base_unit_price=source.create_price(10),
)
creator = OrderCreator()
order = creator.create_order(source)
assert order.account_manager is not None
assert order.account_manager == person.account_manager
with pytest.raises(ProtectedError):
person.account_manager.delete()
示例4: 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
示例5: test_customer_usage_limit
def test_customer_usage_limit(rf):
default_price = 10
request, product = _init_test_for_product_without_basket(rf, default_price)
shop = request.shop
customers = []
for x in range(3):
customers.append(factories.create_random_company(shop=shop))
discount_percentage = 0.20
coupon = CouponCode.objects.create(code="sUpErAle", active=True, usage_limit_customer=2)
coupon.shops = [request.shop]
discount = Discount.objects.create(
active=True, product=product, coupon_code=coupon, discount_percentage=discount_percentage)
discount.shops.add(request.shop)
# Order product twice for each customer
for customer in customers:
for y in range(2):
_create_order(request, customer, coupon, product, request.shop.create_price(8))
assert coupon.usages.count() == 6 # Each customer 2 orders
# Any of the customers created shouldn't be allowed to
# order more with this coupon code.
for customer in customers:
assert not CouponCode.is_usable(shop, coupon, customer)
# New customer should still be able to order some
new_customer = factories.create_random_person()
assert CouponCode.is_usable(shop, coupon, new_customer)
_create_order(request, new_customer, coupon, product, request.shop.create_price(8))
assert coupon.usages.count() == 7
# Set usage limit and the new customer shouldn't be able to use the code
coupon.usage_limit = 7
coupon.save()
assert not CouponCode.is_usable(request.shop, coupon, new_customer)
_create_order(request, new_customer, coupon, product, request.shop.create_price(default_price))
assert coupon.usages.count() == 7
# One of the customer got refund
refunded_customer = customers[0]
order = refunded_customer.customer_orders.first()
coupon_code_modifier = CouponCodeModule()
coupon_code_modifier.clear_codes(order)
assert coupon.usages.count() == 6
# New customer still doesn't able to create coupon
new_customer = factories.create_random_person()
assert CouponCode.is_usable(shop, coupon, new_customer)
_create_order(request, new_customer, coupon, product, request.shop.create_price(8))
assert coupon.usages.count() == 7
示例6: test_get_by_pk
def test_get_by_pk(admin_user):
get_default_shop()
for i in range(0,10):
create_random_person()
contact = create_random_person()
client = _get_client(admin_user)
response = client.get("/api/shuup/contact/%s/" % contact.id)
assert response.status_code == status.HTTP_200_OK
contact_data = json.loads(response.content.decode("utf-8"))
assert contact_data.get("id") == contact.id
assert contact_data.get("name") == contact.name
示例7: test_get_shipments
def test_get_shipments(admin_user):
client = _get_client(admin_user)
shop1 = get_shop(True)
shop2 = get_shop(True)
customer1 = create_random_person()
customer2 = create_random_person()
order1 = create_random_order(customer1, shop=shop1, completion_probability=1)
order2 = create_random_order(customer2, shop=shop1, completion_probability=1)
order3 = create_random_order(customer1, shop=shop2, completion_probability=1)
order4 = create_random_order(customer2, shop=shop1, completion_probability=1)
# list shipments
response = client.get("/api/shuup/shipment/")
assert response.status_code == status.HTTP_200_OK
shipment_data = json.loads(response.content.decode("utf-8"))
assert len(shipment_data) == 4
assert shipment_data[0]["id"] == order1.shipments.first().pk
assert shipment_data[1]["id"] == order2.shipments.first().pk
assert shipment_data[2]["id"] == order3.shipments.first().pk
assert shipment_data[3]["id"] == order4.shipments.first().pk
# get shipment by id
response = client.get("/api/shuup/shipment/%s/" % order1.shipments.first().pk)
assert response.status_code == status.HTTP_200_OK
shipment_data = json.loads(response.content.decode("utf-8"))
assert shipment_data["id"] == order1.shipments.first().pk
assert shipment_data["order"] == order1.pk
# get shipment by product
product = order2.shipments.first().products.first()
response = client.get("/api/shuup/shipment/?product=%s" % product.pk)
assert response.status_code == status.HTTP_200_OK
shipment_data = json.loads(response.content.decode("utf-8"))
for ship in shipment_data:
for ship_product in shipment_data["product"]:
assert ship_product["id"] == product.pk
assert ship_product["order"] == order2.pk
# get shipment by order
response = client.get("/api/shuup/shipment/?order=%s" % order3.pk)
assert response.status_code == status.HTTP_200_OK
shipment_data = json.loads(response.content.decode("utf-8"))
for ship in shipment_data:
assert ship["order"] == order3.pk
# get shipment by shop
response = client.get("/api/shuup/shipment/?shop=%s" % shop1.pk)
assert response.status_code == status.HTTP_200_OK
shipment_data = json.loads(response.content.decode("utf-8"))
for ship in shipment_data:
assert Shipment.objects.filter(pk=ship["id"], order__shop=shop1).exists()
示例8: test_create_new_basket
def test_create_new_basket(admin_user):
with override_settings(**REQUIRED_SETTINGS):
shop = factories.get_default_shop()
shop2 = create_shop("foobar")
client = _get_client(admin_user)
response = client.post("/api/shuup/basket/new/", {
"shop": shop2.pk
})
assert response.status_code == status.HTTP_201_CREATED
basket_data = json.loads(response.content.decode("utf-8"))
basket = Basket.objects.first()
assert basket.key == basket_data['uuid'].split("-")[1]
assert basket.shop == shop2
admin_contact = get_person_contact(admin_user)
assert basket.customer == admin_contact
assert basket.orderer == admin_contact
assert basket.creator == admin_user
# invalid shop
response = client.post("/api/shuup/basket/new/", data={"shop": 1000})
assert response.status_code == status.HTTP_400_BAD_REQUEST
# no shop in multishop mode
response = client.post("/api/shuup/basket/new/")
assert response.status_code == status.HTTP_400_BAD_REQUEST
# no shop in single shop mode
with override_settings(SHUUP_ENABLE_MULTIPLE_SHOPS=False):
response = client.post("/api/shuup/basket/new/")
assert response.status_code == status.HTTP_201_CREATED
basket_data = json.loads(response.content.decode("utf-8"))
basket = Basket.objects.all()[1]
assert basket.key == basket_data['uuid'].split("-")[1]
assert basket.shop == shop
assert basket.customer == admin_contact
assert basket.orderer == admin_contact
assert basket.creator == admin_user
person = factories.create_random_person()
response = client.post("/api/shuup/basket/new/", data={"customer": person.pk})
assert response.status_code == status.HTTP_201_CREATED
basket_data = json.loads(response.content.decode("utf-8"))
basket = Basket.objects.all()[2]
assert basket.key == basket_data['uuid'].split("-")[1]
assert basket.shop == shop
assert basket.creator == admin_user
assert basket.customer.pk == person.pk
assert basket.orderer.pk == person.pk
assert basket.creator.pk == admin_user.pk
# Try to fetch the basket as the customer
user = factories.UserFactory()
person.user = user
person.save()
response = client.get("/api/shuup/basket/{}/".format(basket_data['uuid']))
assert response.status_code == 200
customer_basket_data = json.loads(response.content.decode("utf-8"))
assert basket.key == customer_basket_data['key'] # Still same basket as before
assert customer_basket_data['customer']['id'] == person.pk # Still same customer as before
示例9: 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"
)
get_currency("EUR")
get_currency("USD")
assert shop.name == "testshop"
assert shop.currency == "EUR"
assert not ConfigurationItem.objects.filter(shop=shop, key="languages").exists()
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"] = "USD"
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 . . .
示例10: 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"]])
示例11: 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"
示例12: test_filter_parameter_contact_groups
def test_filter_parameter_contact_groups():
customer_price = 10.3
anonymous_price = 14.6
def get_price_info_mock(context, product, quantity=1):
if context.customer.get_default_group() == AnonymousContact().get_default_group():
price = context.shop.create_price(anonymous_price)
else:
price = context.shop.create_price(customer_price)
return PriceInfo(quantity * price, quantity * price, quantity)
with patch.object(DummyPricingModule, 'get_price_info', side_effect=get_price_info_mock):
(engine, context) = _get_template_engine_and_context(product_sku="123")
# test with anonymous
context['request'].customer = AnonymousContact()
context['request'].person = context['request'].customer
result = engine.from_string("{{ prod|price(quantity=2) }}")
assert result.render(context) == "$%0.2f" % (anonymous_price * 2)
# Get fresh content. I guess the prices shouldn't change between request.
(engine, context) = _get_template_engine_and_context(product_sku="1234")
# test with customer
context['request'].customer = create_random_person()
context['request'].person = context['request'].customer
result = engine.from_string("{{ prod|price(quantity=2) }}")
assert result.render(context) == "$%0.2f" % (customer_price * 2)
示例13: test_order_creator_customer_details
def test_order_creator_customer_details(rf, admin_user):
shop = get_default_shop()
contact = create_random_person(locale="en_US", minimum_name_comp_len=5)
company = create_random_company()
group = get_default_customer_group()
contact.groups.add(group)
contact.company_memberships.add(company)
contact.save()
product = create_product(sku=printable_gibberish(), supplier=get_default_supplier(), shop=shop)
order = create_random_order(contact, products=[product])
request = apply_request_middleware(rf.get("/", {"command": "customer_details", "id": contact.id}), user=admin_user)
response = OrderEditView.as_view()(request)
data = json.loads(response.content.decode("utf8"))
assert "customer_info" in data
assert "order_summary" in data
assert "recent_orders" in data
assert data["customer_info"]["name"] == contact.full_name
assert data["customer_info"]["phone_no"] == contact.phone
assert data["customer_info"]["email"] == contact.email
assert company.full_name in data["customer_info"]["companies"]
assert group.name in data["customer_info"]["groups"]
assert data["customer_info"]["merchant_notes"] == contact.merchant_notes
assert len(data["order_summary"]) == 1
assert data["order_summary"][0]["year"] == order.order_date.year
assert data["order_summary"][0]["total"] == format_money(order.taxful_total_price)
assert len(data["recent_orders"]) == 1
assert data["recent_orders"][0]["status"] == order.get_status_display()
assert data["recent_orders"][0]["total"] == format_money(order.taxful_total_price)
assert data["recent_orders"][0]["payment_status"] == force_text(order.payment_status.label)
assert data["recent_orders"][0]["shipment_status"] == force_text(order.shipping_status.label)
示例14: test_order_creator_customer_data
def test_order_creator_customer_data(rf, admin_user):
get_default_shop()
contact = create_random_person(locale="en_US", minimum_name_comp_len=5)
request = apply_request_middleware(rf.get("/", {"command": "customer_data", "id": contact.id}), user=admin_user)
response = OrderEditView.as_view()(request)
assert_contains(response, "name")
assert_contains(response, contact.name)
示例15: test_mass_edit_contacts
def test_mass_edit_contacts(rf, admin_user):
shop = get_default_shop()
contact1 = create_random_person()
contact2 = create_random_person()
contact1.gender = Gender.FEMALE
contact1.save()
contact2.gender = Gender.FEMALE
contact2.save()
request = apply_request_middleware(rf.post("/", data={"gender": Gender.MALE.value}), user=admin_user)
request.session["mass_action_ids"] = [contact1.pk, contact2.pk]
view = ContactMassEditView.as_view()
response = view(request=request)
assert response.status_code == 302
for contact in Contact.objects.all():
assert contact.gender == Gender.MALE