本文整理汇总了Python中shuup.testing.factories.get_shop函数的典型用法代码示例。如果您正苦于以下问题:Python get_shop函数的具体用法?Python get_shop怎么用?Python get_shop使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_shop函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_same_codes
def test_same_codes():
shop1 = factories.get_shop(True, "EUR")
shop2 = factories.get_shop(True, "USD")
dc1 = Coupon.objects.create(code="TEST")
dc2 = Coupon.objects.create(code="TEST")
BasketCampaign.objects.create(name="test1", active=True, shop_id=shop1.id, coupon_id=dc1.id)
with pytest.raises(ValidationError):
BasketCampaign.objects.create(name="test1", active=True, shop_id=shop1.id, coupon_id=dc2.id)
BasketCampaign.objects.create(name="test2", active=True, shop_id=shop2.id, coupon_id=dc2.id)
with pytest.raises(ValidationError):
BasketCampaign.objects.create(name="test2", active=True, shop_id=shop2.id, coupon_id=dc1.id)
# Disable one campaigns for dc1 and you should be able to set the code to different campaign again
dc3 = Coupon.objects.create(code="TEST")
BasketCampaign.objects.filter(coupon=dc1).update(active=False)
BasketCampaign.objects.create(name="test1", active=True, shop_id=shop1.id, coupon_id=dc3.id)
# Try to reactivate the campaign for shop1
c = BasketCampaign.objects.filter(coupon=dc1).first()
assert c.active == False
with pytest.raises(ValidationError):
c.active = True
c.save()
# Try to sneak one duplicate code by saving the coupon
dc4 = Coupon.objects.create(code="TEST1")
BasketCampaign.objects.create(name="test4", active=True, shop_id=shop2.id, coupon_id=dc4.id)
with pytest.raises(ValidationError):
dc4.code = "TEST"
dc4.save()
示例2: test_happy_hours_admin_edit_view_over_midnight
def test_happy_hours_admin_edit_view_over_midnight(rf, staff_user, admin_user):
shop = factories.get_default_shop()
shop.staff_members.add(staff_user)
factories.get_shop(identifier="shop2", enabled=True)
assert Shop.objects.count() == 2
# Staff user gets shop automatically
from_hour = datetime.time(hour=21, minute=0)
to_hour = datetime.time(hour=3, minute=0)
data = {
"name": "Happiest Hour 2pm",
"weekdays": [1], # Tue
"from_hour": from_hour,
"to_hour": to_hour
}
request = apply_request_middleware(rf.post("/", data=data), user=staff_user, shop=shop)
set_shop(request, shop)
assert request.shop == shop
view_func = HappyHourEditView.as_view()
response = view_func(request)
if hasattr(response, "render"):
response.render()
assert response.status_code == 302
happy_hour = HappyHour.objects.first()
assert happy_hour is not None
assert happy_hour.shops.first() == shop
assert happy_hour.time_ranges.count() == 2 # Since happy hour starts and ends on different day
assert happy_hour.time_ranges.filter(weekday=1).exists()
assert happy_hour.time_ranges.filter(weekday=1, from_hour=from_hour, to_hour=datetime.time(23, 59)).exists()
assert happy_hour.time_ranges.filter(weekday=2, from_hour=datetime.time(0), to_hour=to_hour).exists()
_assert_view_get(rf, happy_hour, shop, staff_user) # Viewing the edit should also still work
示例3: test_manufacturer_admin_multishop_shop
def test_manufacturer_admin_multishop_shop(rf, staff_user, admin_user, superuser):
with override_settings(SHUUP_ENABLE_MULTIPLE_SHOPS=True):
shop1 = factories.get_shop(identifier="shop1", enabled=True)
shop2 = factories.get_shop(identifier="shop2", enabled=True)
shop1.staff_members.add(staff_user)
shop2.staff_members.add(staff_user)
assert Manufacturer.objects.count() == 0
user = admin_user if superuser else staff_user
request = apply_request_middleware(rf.post("/", data=dict(name="Manuf shop2")), user=user, shop=shop2)
set_shop(request, shop2)
view_func = ManufacturerEditView.as_view()
response = view_func(request)
assert response.status_code == 302
if superuser:
assert Manufacturer.objects.first().shops.count() == 0
else:
assert Manufacturer.objects.first().shops.first() == shop2
for view_class in (ManufacturerEditView, ManufacturerListView):
view_instance = view_class()
view_instance.request= request
assert view_instance.get_queryset().count() == 1
if superuser:
assert view_instance.get_queryset().first().shops.count() == 0
else:
assert view_instance.get_queryset().first().shops.count() == 1
assert view_instance.get_queryset().first().shops.first() == shop2
request = apply_request_middleware(rf.post("/", data=dict(name="Manuf shop1")), user=user, shop=shop1)
set_shop(request, shop1)
view_func = ManufacturerEditView.as_view()
response = view_func(request)
assert response.status_code == 302
if superuser:
assert Manufacturer.objects.last().shops.count() == 0
else:
assert Manufacturer.objects.last().shops.first() == shop1
for view_class in (ManufacturerEditView, ManufacturerListView):
view_instance = view_class()
view_instance.request= request
assert view_instance.get_queryset().count() == (2 if superuser else 1)
if superuser:
assert view_instance.get_queryset().first().shops.count() == 0
assert view_instance.get_queryset().last().shops.count() == 0
else:
assert view_instance.get_queryset().first().shops.count() == 1
assert view_instance.get_queryset().first().shops.first() == shop1
示例4: 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()
示例5: test_edit_shared_file
def test_edit_shared_file(admin_user):
with override_settings(SHUUP_ENABLE_MULTIPLE_SHOPS=True):
shop1 = factories.get_shop(identifier="shop1", enabled=True)
shop2 = factories.get_shop(identifier="shop2", enabled=True)
folder1 = Folder.objects.create(name="folder1")
folder2 = Folder.objects.create(name="folder2")
file = File.objects.create(original_filename="test.jpg", folder=folder1) # Shared file
file_count = File.objects.count()
assert force_text(file) == "test.jpg"
response = _mbv_command(shop1, admin_user, {"action": "rename_file", "id": file.pk, "name": "test.tiff"})
assert not response["success"]
response = _mbv_command(shop1, admin_user, {"action": "move_file", "file_id": file.pk, "folder_id": folder2.pk})
assert not response["success"]
assert File.objects.get(pk=file.pk).folder == folder1
response = _mbv_command(shop1, admin_user, {"action": "delete_file", "id": file.pk})
assert not response["success"]
# Let's make sure rename works when only one shop owns the file
media_file = MediaFile.objects.create(file=file)
media_file.shops.add(shop1)
response = _mbv_command(shop1, admin_user, {"action": "rename_file", "id": file.pk, "name": "test.tiff"})
assert response["success"]
file = File.objects.get(pk=file.pk)
assert force_text(file) == "test.tiff"
# Let's move the file to different folder
response = _mbv_command(shop1, admin_user, {"action": "move_file", "file_id": file.pk, "folder_id": folder2.pk})
assert response["success"]
assert File.objects.get(pk=file.pk).folder == folder2
# Then add second shop for the file and let's check and
# renaming should be disabled again.
media_file.shops.add(shop2)
response = _mbv_command(shop1, admin_user, {"action": "rename_file", "id": file.pk, "name": "test.tiff"})
assert not response["success"]
response = _mbv_command(shop1, admin_user, {"action": "delete_file", "id": file.pk})
assert not response["success"]
response = _mbv_command(shop2, admin_user, {"action": "rename_file", "id": file.pk, "name": "test.tiff"})
assert not response["success"]
response = _mbv_command(shop2, admin_user, {"action": "delete_file", "id": file.pk})
assert not response["success"]
# Finally remove the file as shop2
media_file.shops.remove(shop1)
response = _mbv_command(shop1, admin_user, {"action": "delete_file", "id": file.pk})
assert response["error"] == "File matching query does not exist."
response = _mbv_command(shop2, admin_user, {"action": "delete_file", "id": file.pk})
assert response["success"]
assert File.objects.count() == file_count - 1
示例6: test_happy_hours_admin_edit_view
def test_happy_hours_admin_edit_view(rf, staff_user, admin_user):
with override_settings(SHUUP_ENABLE_MULTIPLE_SHOPS=True):
shop = factories.get_default_shop()
shop.staff_members.add(staff_user)
factories.get_shop(identifier="shop2", enabled=True)
assert Shop.objects.count() == 2
# Staff user gets shop automatically
data = {
"name": "Happiest Hour 2pm",
"weekdays": [6], # Sun
"from_hour": datetime.time(hour=14, minute=0),
"to_hour": datetime.time(hour=14, minute=0)
}
request = apply_request_middleware(rf.post("/", data=data), user=staff_user, shop=shop)
set_shop(request, shop)
assert request.shop == shop
view_func = HappyHourEditView.as_view()
response = view_func(request)
if hasattr(response, "render"):
response.render()
assert response.status_code == 302
happy_hour1 = HappyHour.objects.first()
assert happy_hour1 is not None
assert happy_hour1.shops.first() == shop
assert happy_hour1.time_ranges.count() == 1 # Since happy hour starts and ends on same day
# Test with superuser and with different shop
shop2 = factories.get_shop(enabled=True)
request = apply_request_middleware(rf.post("/", data=data), user=admin_user, shop=shop2)
set_shop(request, shop2)
view_func = HappyHourEditView.as_view()
response = view_func(request)
assert response.status_code == 302
assert HappyHour.objects.count() == 2
happy_hour2 = HappyHour.objects.exclude(id=happy_hour1.pk).first()
assert happy_hour1 != happy_hour2
assert happy_hour2.shops.count() == 1
assert happy_hour2.shops.filter(id=shop2.pk).first()
# Staff user can only view coupon codes since that has the right shop
_assert_view_get(rf, happy_hour1, shop, staff_user)
_assert_view_get(rf, happy_hour2, shop, staff_user, True)
# Superuser can see both if needed, but only when right shop is active
_assert_view_get(rf, happy_hour1, shop, admin_user)
_assert_view_get(rf, happy_hour2, shop, admin_user, True)
_assert_view_get(rf, happy_hour2, shop2, admin_user)
示例7: test_exceptions_admin_edit_view
def test_exceptions_admin_edit_view(rf, staff_user, admin_user):
with override_settings(SHUUP_ENABLE_MULTIPLE_SHOPS=True):
shop = factories.get_default_shop()
shop.staff_members.add(staff_user)
factories.get_shop(identifier="shop2", enabled=True)
assert Shop.objects.count() == 2
# Staff user gets shop automatically
data = {
"name": "No deals in next 2 days!",
"start_datetime": datetime.datetime(year=2018, month=11, day=9),
"end_datetime": datetime.datetime(year=2018, month=11, day=11),
}
request = apply_request_middleware(rf.post("/", data=data), user=staff_user, shop=shop)
set_shop(request, shop)
assert request.shop == shop
view_func = AvailabilityExceptionEditView.as_view()
response = view_func(request)
if hasattr(response, "render"):
response.render()
assert response.status_code == 302
exception1 = AvailabilityException.objects.first()
assert exception1 is not None
assert exception1.shops.first() == shop
# Test with superuser and with different shop
shop2 = factories.get_shop(enabled=True)
request = apply_request_middleware(rf.post("/", data=data), user=admin_user, shop=shop2)
set_shop(request, shop2)
view_func = AvailabilityExceptionEditView.as_view()
response = view_func(request)
assert response.status_code == 302
assert AvailabilityException.objects.count() == 2
exception2 = AvailabilityException.objects.exclude(id=exception1.pk).first()
assert exception1 != exception2
assert exception2.shops.count() == 1
assert exception2.shops.filter(id=shop2.pk).exists()
# Staff user can only view coupon codes since that has the right shop
_assert_view_get(rf, exception1, shop, staff_user)
_assert_view_get(rf, exception2, shop, staff_user, True)
# Superuser can see both if needed, but only when right shop is active
_assert_view_get(rf, exception1, shop, admin_user)
_assert_view_get(rf, exception2, shop, admin_user, True)
_assert_view_get(rf, exception2, shop2, admin_user)
示例8: _test_happy_hours_list_view
def _test_happy_hours_list_view(rf, index):
shop = factories.get_shop(identifier="shop%s" % index, enabled=True)
staff_user = factories.create_random_user(is_staff=True)
shop.staff_members.add(staff_user)
happy_hour = HappyHour.objects.create(name="After Work %s" % index)
happy_hour.shops = [shop]
view_func = HappyHourListView.as_view()
request = apply_request_middleware(
rf.get("/", {
"jq": json.dumps({"perPage": 100, "page": 1})
}),
user=staff_user,
shop=shop)
set_shop(request, shop)
response = view_func(request)
if hasattr(response, "render"):
response.render()
assert response.status_code == 200
view_instance = HappyHourListView()
view_instance.request = request
assert request.shop == shop
assert view_instance.get_queryset().count() == 1
data = json.loads(view_instance.get(request).content.decode("UTF-8"))
assert len(data["items"]) == 1
示例9: _get_source
def _get_source(user, shipping_country, billing_country):
prices_include_taxes = True
shop = get_shop(prices_include_taxes)
payment_method = get_payment_method(shop)
shipping_method = get_shipping_method(shop)
source = _seed_source(shop, user, shipping_country, billing_country)
source.payment_method = payment_method
source.shipping_method = shipping_method
assert source.payment_method_id == payment_method.id
assert source.shipping_method_id == shipping_method.id
supplier = get_default_supplier()
product = create_product(
sku="test-%s--%s" % (prices_include_taxes, 10),
shop=source.shop,
supplier=supplier,
default_price=10
)
source.add_line(
type=OrderLineType.PRODUCT,
product=product,
supplier=supplier,
quantity=1,
base_unit_price=source.create_price(10),
)
assert payment_method == source.payment_method
assert shipping_method == source.shipping_method
return source
示例10: get_request_for_contact_tests
def get_request_for_contact_tests(rf):
activate("en")
request = rf.get("/")
request.shop = get_shop(prices_include_tax=True)
get_payment_method(request.shop)
apply_request_middleware(request)
return request
示例11: test_stacked_tax_taxful_price
def test_stacked_tax_taxful_price():
shop = get_shop(prices_include_tax=True, currency='EUR')
source = OrderSource(shop)
assert source.prices_include_tax
source.add_line(
type=OrderLineType.OTHER, quantity=1, base_unit_price=source.create_price(20)
)
with override_provides("tax_module", TAX_MODULE_SPEC):
with override_settings(SHUUP_TAX_MODULE="irvine"):
source.shipping_address = MutableAddress(
street="16215 Alton Pkwy",
postal_code="92602",
)
line = source.get_final_lines(with_taxes=True)[0]
assert isinstance(line, SourceLine)
assert line.taxes
assert line.taxful_price == TaxfulPrice(20, 'EUR')
assert_almost_equal(line.taxless_price, TaxlessPrice("18.52", 'EUR'))
source.uncache()
# Let's move out to a taxless location.
source.shipping_address.postal_code = "11111"
line = source.get_final_lines(with_taxes=True)[0]
assert isinstance(line, SourceLine)
assert not line.taxes
assert line.taxful_price == TaxfulPrice(20, source.currency)
assert line.taxless_price.value == Decimal("20")
示例12: _test_exception_delete_view
def _test_exception_delete_view(rf, index):
shop = factories.get_shop(identifier="shop%s" % index, enabled=True)
staff_user = factories.create_random_user(is_staff=True)
shop.staff_members.add(staff_user)
exception_name = "Exception %s" % index
exception = AvailabilityException.objects.create(
name=exception_name, start_datetime=now(), end_datetime=now())
exception.shops = [shop]
extra_exception = AvailabilityException.objects.create(
name="Extra Exception %s" % index, start_datetime=now(), end_datetime=now())
extra_exception.shops = [shop]
assert AvailabilityException.objects.filter(name=exception_name).exists()
view_func = AvailabilityExceptionDeleteView.as_view()
request = apply_request_middleware(rf.post("/"), user=staff_user, shop=shop)
set_shop(request, shop)
response = view_func(request, pk=exception.pk)
if hasattr(response, "render"):
response.render()
assert response.status_code == 302
assert not AvailabilityException.objects.filter(name=exception_name).exists()
# Make sure that this staff can't remove other people discounts
other_exceptions = AvailabilityException.objects.exclude(shops=shop)
exception_count = other_exceptions.count()
for coupon in other_exceptions:
view_func = AvailabilityExceptionDeleteView.as_view()
request = apply_request_middleware(rf.post("/"), user=staff_user, shop=shop)
set_shop(request, shop)
with pytest.raises(Http404):
response = view_func(request, pk=coupon.pk)
if hasattr(response, "render"):
response.render()
assert exception_count == AvailabilityException.objects.exclude(shops=shop).count()
示例13: test_editing_sales_ranges_multi_shop
def test_editing_sales_ranges_multi_shop(rf, admin_user):
get_default_shop()
another_shop = get_shop(prices_include_tax=True)
another_shop.status = ShopStatus.ENABLED
another_shop.save()
group = get_default_customer_group()
data = {}
for shop in Shop.objects.all():
data.update(get_edit_view_data(shop, group, 0, 50))
assert ContactGroupSalesRange.objects.count() == 0
# To make this test work we need to mock members form_part since the extra
# forms does not render correctly
with patch.object(ContactGroupEditView, "base_form_part_classes", [ContactGroupBaseFormPart]):
request = apply_request_middleware(rf.post("/", data=data), user=admin_user)
view = ContactGroupEditView.as_view()
response = view(request=request, pk=group.pk)
if hasattr(response, "render"):
response.render()
assert response.status_code in [200, 302]
assert ContactGroupSalesRange.objects.count() == 2
for shop in Shop.objects.all():
sales_range = ContactGroupSalesRange.objects.filter(group=group, shop=shop).first()
assert sales_range.min_value == 0
assert sales_range.max_value == 50
示例14: 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()
示例15: _test_happy_hours_delete_view
def _test_happy_hours_delete_view(rf, index):
shop = factories.get_shop(identifier="shop%s" % index, enabled=True)
staff_user = factories.create_random_user(is_staff=True)
shop.staff_members.add(staff_user)
happy_hour_name = "The Hour %s" % index
happy_hour = HappyHour.objects.create(name=happy_hour_name)
happy_hour.shops = [shop]
extra_happy_hour= HappyHour.objects.create(name="Extra Hour %s" % index)
extra_happy_hour.shops = [shop]
assert HappyHour.objects.filter(name=happy_hour_name).exists()
view_func = HappyHourDeleteView.as_view()
request = apply_request_middleware(rf.post("/"), user=staff_user, shop=shop)
set_shop(request, shop)
response = view_func(request, pk=happy_hour.pk)
if hasattr(response, "render"):
response.render()
assert response.status_code == 302
assert not HappyHour.objects.filter(name=happy_hour_name).exists()
# Make sure that this staff can't remove other people discounts
other_exceptions = HappyHour.objects.exclude(shops=shop)
exception_count = other_exceptions.count()
for coupon in other_exceptions:
view_func = HappyHourDeleteView.as_view()
request = apply_request_middleware(rf.post("/"), user=staff_user, shop=shop)
set_shop(request, shop)
with pytest.raises(Http404):
response = view_func(request, pk=coupon.pk)
if hasattr(response, "render"):
response.render()
assert exception_count == HappyHour.objects.exclude(shops=shop).count()