本文整理汇总了Python中shuup.apps.provides.override_provides函数的典型用法代码示例。如果您正苦于以下问题:Python override_provides函数的具体用法?Python override_provides怎么用?Python override_provides使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了override_provides函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_custom_view_toolbar_buttons
def test_custom_view_toolbar_buttons(rf, admin_user):
factories.get_default_shop()
request = apply_request_middleware(rf.get("/"), user=admin_user)
list_view_func = ContactGroupPriceDisplayListView.as_view()
edit_view_func = ContactGroupPriceDisplayEditView.as_view()
with override_provides("contact_group_price_list_toolbar_provider", [
"shuup.testing.modules.mocker.toolbar:ContactGroupPriceDisplayButtonProvider"
]):
list_response = list_view_func(request)
list_response.render()
list_content = list_response.content.decode("utf-8")
assert "btn-contact-group-hello" in list_content
edit_response = edit_view_func(request)
edit_response.render()
edit_response = edit_response.content.decode("utf-8")
assert "btn-contact-group-hello" not in edit_response
# use global provider - all views should have that button
with override_provides("admin_toolbar_button_provider", [
"shuup.testing.modules.mocker.toolbar:ContactGroupPriceDisplayButtonProvider"
]):
list_response = list_view_func(request)
list_response.render()
list_content = list_response.content.decode("utf-8")
assert "btn-contact-group-hello" in list_content
edit_response = edit_view_func(request)
edit_response.render()
edit_response = edit_response.content.decode("utf-8")
assert "btn-contact-group-hello" in edit_response
示例2: test_rules_and_effects
def test_rules_and_effects(rf, admin_user):
"""
To make things little bit more simple let's use only english as
a language.
"""
get_default_shop()
with override_settings(LANGUAGES=[("en", "en")]):
shop = get_default_shop()
object = BasketCampaign.objects.create(name="test campaign", active=True, shop=shop)
assert object.conditions.count() == 0
assert object.discount_effects.count() == 0
view = BasketCampaignEditView.as_view()
data = {
"base-name": "test campaign",
"base-public_name__en": "Test Campaign",
"base-shop": get_default_shop().id,
"base-active": True,
"base-basket_line_text": "Test campaign activated!"
}
with override_provides(
"campaign_basket_condition", ["shuup.campaigns.admin_module.forms:BasketTotalProductAmountConditionForm"]):
with override_provides(
"campaign_basket_discount_effect_form", ["shuup.campaigns.admin_module.forms:BasketDiscountAmountForm"]):
with override_provides("campaign_basket_line_effect_form", []):
data.update(get_products_in_basket_data())
data.update(get_free_product_data(object))
request = apply_request_middleware(rf.post("/", data=data), user=admin_user)
view(request, pk=object.pk)
object.refresh_from_db()
assert object.conditions.count() == 1
assert object.discount_effects.count() == 1
示例3: test_campaign_end_date
def test_campaign_end_date(rf, admin_user):
"""
To make things little bit more simple let's use only english as
a language.
"""
with override_settings(LANGUAGES=[("en", "en")]):
shop = get_default_shop()
old_name = "test_campaign"
object = CatalogCampaign.objects.create(name=old_name, active=True, shop=shop)
object.save()
view = CatalogCampaignEditView.as_view()
new_name = "Test Campaign"
assert object.name != new_name
data = {
"base-name": new_name,
"base-public_name__en": "Test Campaign",
"base-shop": get_default_shop().id,
"base-active": True,
"base-basket_line_text": "Test campaign activated!",
"base-start_datetime": datetime.datetime(year=2016, month=6, day=19),
"base-end_datetime": datetime.datetime(year=2016, month=6, day=10)
}
methods_before = CatalogCampaign.objects.count()
# Conditions, effects and effects is tested separately
with override_provides("campaign_context_condition", []):
with override_provides("campaign_catalog_filter", []):
with override_provides("campaign_product_discount_effect_form", []):
request = apply_request_middleware(rf.post("/", data=data), user=admin_user)
response = view(request, pk=object.pk)
assert response.status_code in [200, 302]
content = response.render().content.decode("utf-8")
assert "Campaign end date can't be before start date." in content
assert CatalogCampaign.objects.count() == methods_before
assert CatalogCampaign.objects.get(pk=object.pk).name == old_name
示例4: test_view_custom_mass_actions
def test_view_custom_mass_actions(rf, admin_user):
factories.get_default_shop()
request = apply_request_middleware(rf.get("/", {"jq": json.dumps({"perPage": 100, "page": 1})}), user=admin_user)
list_view_func = ManufacturerListView.as_view()
# no mass actions
response = list_view_func(request)
data = json.loads(response.content.decode("utf-8"))
assert not data["massActions"]
# test with specific key
with override_provides("manufacturer_list_mass_actions_provider", [
"shuup.testing.modules.mocker.mass_actions:DummyMassActionProvider"
]):
response = list_view_func(request)
data = json.loads(response.content.decode("utf-8"))
identifiers = [action["key"] for action in data["massActions"]]
assert "dummy_mass_action_1" in identifiers
assert "dummy_mass_action_2" in identifiers
list_view_func = SalesUnitListView.as_view()
# test with global
with override_provides("admin_mass_actions_provider", [
"shuup.testing.modules.mocker.mass_actions:DummyMassActionProvider"
]):
response = list_view_func(request)
data = json.loads(response.content.decode("utf-8"))
identifiers = [action["key"] for action in data["massActions"]]
assert "dummy_mass_action_1" in identifiers
assert "dummy_mass_action_2" in identifiers
示例5: test_method_edit_save
def test_method_edit_save(rf, admin_user, view, model, get_object, service_provider_attr):
"""
To make things little bit more simple let's use only english as
an language.
"""
with override_settings(LANGUAGES=[("en", "en")]):
object = get_object()
object.choice_identifier = ""
object.save()
assert object.choice_identifier == ""
view = view.as_view()
service_provider_attr_field = "base-%s" % service_provider_attr
data = {
"base-name__en": object.name,
"base-shop": object.shop.id,
"base-tax_class": object.tax_class.id,
"base-enabled": True,
service_provider_attr_field: getattr(object, service_provider_attr).pk,
"base-choice_identifier": "manual"
}
methods_before = model.objects.count()
# Behavior components is tested at shuup.tests.admin.test_service_behavior_components
with override_provides("service_behavior_component_form", []):
with override_provides("service_behavior_component_form_part", []):
request = apply_request_middleware(rf.post("/", data=data), user=admin_user)
response = view(request, pk=object.pk)
if hasattr(response, "render"):
response.render()
assert response.status_code in [200, 302]
assert model.objects.count() == methods_before
assert model.objects.get(pk=object.pk).choice_identifier == "manual"
示例6: test_campaign_edit_save
def test_campaign_edit_save(rf, admin_user):
"""
To make things little bit more simple let's use only english as
a language.
"""
with override_settings(LANGUAGES=[("en", "en")]):
shop = get_default_shop()
object = BasketCampaign.objects.create(name="test campaign", active=True, shop=shop)
object.save()
view = BasketCampaignEditView.as_view()
new_name = "Test Campaign"
assert object.name != new_name
data = {
"base-name": new_name,
"base-public_name__en": "Test Campaign",
"base-shop": get_default_shop().id,
"base-active": True,
"base-basket_line_text": "Test campaign activated!"
}
methods_before = BasketCampaign.objects.count()
# Conditions and effects is tested separately
with override_provides("campaign_basket_condition", []):
with override_provides("campaign_basket_discount_effect_form", []):
with override_provides("campaign_basket_line_effect_form", []):
request = apply_request_middleware(rf.post("/", data=data), user=admin_user)
response = view(request, pk=object.pk)
assert response.status_code in [200, 302]
assert BasketCampaign.objects.count() == methods_before
assert BasketCampaign.objects.get(pk=object.pk).name == new_name
示例7: test_contact_detail_has_mocked_toolbar_action_items
def test_contact_detail_has_mocked_toolbar_action_items(rf, admin_user):
get_default_shop()
contact = create_random_person(locale="en_US", minimum_name_comp_len=5)
request = apply_request_middleware(rf.get("/"), user=admin_user)
view_func = ContactDetailView.as_view()
with override_provides("admin_contact_toolbar_action_item", [
"shuup.testing.admin_module.toolbar:MockContactToolbarActionItem"
]):
assert _check_if_mock_action_item_exists(view_func, request, contact)
with override_provides("admin_contact_toolbar_action_item", []):
assert not _check_if_mock_action_item_exists(view_func, request, contact)
示例8: test_sorts_and_filter_in_category_edit
def test_sorts_and_filter_in_category_edit(rf, admin_user):
get_default_shop()
cache.clear()
activate("en")
with override_provides("front_extend_product_list_form", DEFAULT_FORM_MODIFIERS):
category = get_default_category()
view = CategoryEditView.as_view()
assert get_configuration(category=category) == settings.SHUUP_FRONT_DEFAULT_SORT_CONFIGURATION
data = {
"base-name__en": category.name,
"base-status": category.status.value,
"base-visibility": category.visibility.value,
"base-ordering": category.ordering,
"product_list_facets-sort_products_by_name": True,
"product_list_facets-sort_products_by_name_ordering": 6,
"product_list_facets-sort_products_by_price": False,
"product_list_facets-sort_products_by_price_ordering": 32,
"product_list_facets-filter_products_by_manufacturer": True,
"product_list_facets-filter_products_by_manufacturer_ordering": 1
}
request = apply_request_middleware(rf.post("/", data=data), user=admin_user)
response = view(request, pk=category.pk)
if hasattr(response, "render"):
response.render()
assert response.status_code in [200, 302]
expected_configurations = {
"sort_products_by_name": True,
"sort_products_by_name_ordering": 6,
"sort_products_by_price": False,
"sort_products_by_price_ordering": 32,
"filter_products_by_manufacturer": True,
"filter_products_by_manufacturer_ordering": 1
}
assert get_configuration(category=category) == expected_configurations
示例9: test_sorts_and_filter_in_shop_edit
def test_sorts_and_filter_in_shop_edit(rf, admin_user):
cache.clear()
activate("en")
with override_provides("front_extend_product_list_form", DEFAULT_FORM_MODIFIERS):
shop = get_default_shop()
view = ShopEditView.as_view()
assert get_configuration(shop=shop) == settings.SHUUP_FRONT_DEFAULT_SORT_CONFIGURATION
data = {
"base-name__en": shop.name,
"base-public_name__en": shop.public_name,
"base-status": shop.status.value,
"base-currency": shop.currency,
"base-prices_include_tax": shop.prices_include_tax,
"base-languages": "en",
"product_list_facets-sort_products_by_name": True,
"product_list_facets-sort_products_by_name_ordering": 11,
"product_list_facets-sort_products_by_price": False,
"product_list_facets-sort_products_by_price_ordering": 32,
"product_list_facets-filter_products_by_manufacturer": False,
"product_list_facets-filter_products_by_manufacturer_ordering": 1
}
request = apply_request_middleware(rf.post("/", data=data), user=admin_user)
response = view(request, pk=shop.pk)
if hasattr(response, "render"):
response.render()
assert response.status_code in [200, 302]
expected_configurations = {
"sort_products_by_name": True,
"sort_products_by_name_ordering": 11,
"sort_products_by_price": False,
"sort_products_by_price_ordering": 32,
"filter_products_by_manufacturer": False,
"filter_products_by_manufacturer_ordering": 1
}
assert get_configuration(shop=shop) == expected_configurations
示例10: 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")
示例11: test_reports_admin_permissions
def test_reports_admin_permissions(rf):
shop = get_default_shop() # We need a shop to exists
staff_user = get_default_staff_user(shop)
permission_group = get_default_permission_group()
staff_user.groups = [permission_group]
request = apply_request_middleware(rf.get("/"), user=staff_user)
request.user = staff_user
with replace_modules([ReportsAdminModule]):
with override_provides("reports", REPORTS):
extra_permissions = ReportsAdminModule().get_extra_permissions()
assert len(extra_permissions) == 3
assert SalesReport.identifier in extra_permissions
assert TotalSales.identifier in extra_permissions
assert SalesPerHour.identifier in extra_permissions
with admin_only_urls():
view_func = ReportView.as_view()
response = view_func(request)
response.render()
response = view_func(request, pk=None) # "new mode"
response.render()
assert response.content
soup = BeautifulSoup(response.content)
assert soup.find("div", {"class": "content-block"}).text == "No reports available"
expected_report_identifiers = []
for report_cls in [SalesReport, TotalSales, SalesPerHour]:
expected_report_identifiers.append(report_cls.identifier)
set_permissions_for_group(permission_group, [report_cls.identifier])
response = view_func(request, pk=None) # "new mode"
response.render()
assert response.content
soup = BeautifulSoup(response.content)
for option in soup.find("select", {"id": "id_report"}).findAll("option"):
assert option["value"] in expected_report_identifiers
示例12: test_dummy_script_template_manual
def test_dummy_script_template_manual(rf):
with override_provides("notify_script_template", [
"shuup.testing.notify_script_templates:DummyScriptTemplate"
]):
get_default_shop()
Script.objects.all().delete()
script_template = DummyScriptTemplate()
form = script_template.get_form()
assert form is None
script = script_template.create_script()
assert script is not None
db_script = Script.objects.first()
assert script.pk == db_script.pk
serialized_steps = db_script.get_serialized_steps()
assert len(serialized_steps) == 1
assert len(serialized_steps[0]["actions"]) == 0
assert len(serialized_steps[0]["conditions"]) == 1
assert serialized_steps[0]["conditions"][0]["v1"]["constant"]
assert not serialized_steps[0]["conditions"][0]["v2"]["constant"]
示例13: test_multishops_middleware
def test_multishops_middleware(rf, host):
with override_provides("xtheme", [
"shuup_tests.xtheme.utils:FauxTheme",
"shuup_tests.xtheme.utils:FauxTheme2"
]):
shop1 = Shop.objects.create(identifier="shop1", domain="shop-1")
shop2 = Shop.objects.create(identifier="shop2", domain="shop-test-2")
theme_settings_shop1 = ThemeSettings.objects.create(theme_identifier=FauxTheme.identifier, shop=shop1)
theme_settings_shop2 = ThemeSettings.objects.create(theme_identifier=FauxTheme2.identifier, shop=shop2)
request = rf.get("/")
request.META["HTTP_HOST"] = host
# should apply the correct shop and the template
apply_request_middleware(request)
if host == "shop-1.somedomain.com":
assert request.shop.id == shop1.id
assert get_middleware_current_theme().identifier == FauxTheme.identifier
assert get_middleware_current_theme().settings_obj.id == theme_settings_shop1.id
else:
assert request.shop.id == shop2.id
assert get_middleware_current_theme().identifier == FauxTheme2.identifier
assert get_middleware_current_theme().settings_obj.id == theme_settings_shop2.id
示例14: test_extending_shipment_form_valid_hook
def test_extending_shipment_form_valid_hook(rf, admin_user):
shop = get_default_shop()
supplier = get_default_supplier()
product = create_product(sku="test-sku", shop=shop, supplier=supplier, default_price=3.33)
quantity = 1
order = create_order_with_product(
product, supplier, quantity=quantity, taxless_base_unit_price=1, shop=shop)
extend_form_class = "shuup_tests.admin.test_shipment_creator.ShipmentFormModifierTest"
with override_provides(ShipmentForm.form_modifier_provide_key, [extend_form_class]):
phone_number = "+358911"
data = {
"q_%s" % product.pk: 1,
"supplier": supplier.pk,
"phone": phone_number
}
request = apply_request_middleware(rf.post("/", data=data), user=admin_user)
view = OrderCreateShipmentView.as_view()
response = view(request, pk=order.pk)
assert response.status_code == 302
# Order should now have shipment, but let's re fetch it first
order = Order.objects.get(pk=order.pk)
assert order.shipments.count() == 1
shipment = order.shipments.first()
assert order.shipping_data.get(shipment.identifier).get("phone") == phone_number
assert shipment.supplier_id == supplier.id
assert shipment.products.count() == 1
assert shipment.products.first().product_id == product.id
示例15: test_provider_provides_fields
def test_provider_provides_fields(rf, admin_user):
if "shuup.front.apps.registration" not in settings.INSTALLED_APPS:
pytest.skip("shuup.front.apps.registration required in installed apps")
shop = get_default_shop()
with override_provides("front_registration_field_provider", [
"shuup_tests.front.utils.FieldTestProvider",
]):
current_username = "test"
request = apply_request_middleware(rf.post("/"), shop=shop)
payload = {
"username": current_username,
"password1": "asdf",
"password2": "asdf",
"email": "[email protected]"
}
form = PersonRegistrationForm(request=request, data=payload)
assert FieldTestProvider.key in form.fields
assert not form.is_valid()
assert form.errors[FieldTestProvider.key][0] == FieldTestProvider.error_msg
# accept terms
payload.update({FieldTestProvider.key: True})
form = PersonRegistrationForm(request=request, data=payload)
assert FieldTestProvider.key in form.fields
assert form.is_valid()
# test signal fires
person_registration_save.connect(change_username_signal, dispatch_uid="test_registration_change_username")
user = form.save()
assert user.username != current_username
assert user.username == "changed_username"
person_registration_save.disconnect(dispatch_uid="test_registration_change_username")