shuup.testing package

Subpackages

Submodules

shuup.testing.admin_main_menu_updater module

class shuup.testing.admin_main_menu_updater.TestAdminMainMenuUpdater(menu)[source]

Bases: MainMenuUpdater

updates = {2: [{'identifier': 'test_0', 'title': 'Test 0'}, {'identifier': 'test_1', 'title': 'Test 1'}]}

shuup.testing.basket_middleware module

class shuup.testing.basket_middleware.TestBasketCommandMiddleware[source]

Bases: BaseBasketCommandMiddleware

preprocess_kwargs(basket, request, command: str, kwargs: dict) dict[source]

Mutate the kwargs that will be passed to the handler. It is possible to raise a ValidationError exception if required.

postprocess_response(basket, request, command: str, kwargs: dict, response: dict) dict[source]

Mutate the response before it is returned by the command dispatcher.

shuup.testing.browser_utils module

shuup.testing.browser_utils.wait_until_disappeared(browser, css_selector, timeout=10, frequency=1.0)[source]

Wait until the element has disappeared

Parameters:
  • browser (splinter.browser.Browser)

  • css_selector (str) – String representation of the css selector

  • timeout (int) – Time to wait for element to disappear

  • frequency (float) – Polling frequency

shuup.testing.browser_utils.wait_until_appeared(browser, css_selector, timeout=10, frequency=1.0)[source]

Wait until the element has appeared

Parameters:
  • browser (splinter.browser.Browser)

  • css_selector (str) – String representation of the css selector

  • timeout (int) – Time to wait for element to appear

  • frequency (float) – Polling frequency

shuup.testing.browser_utils.wait_until_appeared_xpath(browser, xpath, timeout=10, frequency=1.0)[source]
shuup.testing.browser_utils.wait_until_condition(browser, condition, timeout=10, frequency=1.0)[source]

Wait until the condition has been met

Parameters:
  • browser (splinter.browser.Browser)

  • condition – callable that takes a splinter.browser.Browser and returns a boolean indicating whether the condition has been met

  • timeout (int) – Time to wait for element to appear

  • frequency (float) – Polling frequency

shuup.testing.browser_utils.move_to_element(browser, css_selector, header_height=155)[source]

Scroll the browser window to the element

Parameters:
  • browser (splinter.browser.Browser)

  • css_selector (str) – String representation of the css selector

shuup.testing.browser_utils.click_element(browser, css_selector, timeout=10, frequency=1.0, header_height=155)[source]

Click a browser DOM element

Parameters:
  • browser (splinter.browser.Browser)

  • css_selector (str) – String representation of the css selector

  • timeout (int) – Time to wait for element to appear

  • frequency (float) – Polling frequency

shuup.testing.browser_utils.page_has_loaded(browser)[source]

Returns whether the page has loaded

Parameters:

browser (splinter.browser.Browser)

:rtype bool

shuup.testing.browser_utils.initialize_front_browser_test(browser, live_server)[source]
shuup.testing.browser_utils.initialize_admin_browser_test(browser, live_server, settings, username='admin', password='AdminTest123!', onboarding=False, language='en', shop=None, tour_complete=True)[source]

shuup.testing.checkout_with_login_and_register_urls module

shuup.testing.extend_classes module

class shuup.testing.extend_classes.DifferentProductOrderForm(request, context, product, language, **kwargs)[source]

Bases: ProductOrderForm

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

template_name = 'shuup_testing/different_order_form.jinja'
is_compatible()[source]

shuup.testing.factories module

class shuup.testing.factories.UserFactory(**kwargs)[source]

Bases: DjangoModelFactory

Would be called if trying to instantiate the class.

email = <factory.declarations.Sequence object>
first_name = <factory.fuzzy.FuzzyText object>
last_name = <factory.fuzzy.FuzzyText object>
password = <factory.declarations.PostGenerationMethodCall object>
username = <factory.declarations.Sequence object>
class shuup.testing.factories.ShopFactory(**kwargs)[source]

Bases: DjangoModelFactory

Would be called if trying to instantiate the class.

name = <factory.fuzzy.FuzzyText object>
owner = <factory.declarations.SubFactory object>
class shuup.testing.factories.ProductTypeFactory(**kwargs)[source]

Bases: DjangoModelFactory

Would be called if trying to instantiate the class.

identifier = <factory.declarations.Sequence object>
name = <factory.fuzzy.FuzzyText object>
class shuup.testing.factories.SalesUnitFactory(**kwargs)[source]

Bases: DjangoModelFactory

Would be called if trying to instantiate the class.

name = <factory.fuzzy.FuzzyText object>
symbol = <factory.fuzzy.FuzzyText object>
class shuup.testing.factories.CategoryFactory(**kwargs)[source]

Bases: DjangoModelFactory

Would be called if trying to instantiate the class.

identifier = <factory.declarations.Sequence object>
name = <factory.fuzzy.FuzzyText object>
status = <factory.fuzzy.FuzzyChoice object>
class shuup.testing.factories.ShopProductFactory(**kwargs)[source]

Bases: DjangoModelFactory

Would be called if trying to instantiate the class.

default_price_value = <factory.fuzzy.FuzzyDecimal object>
post = <factory.declarations.PostGeneration object>
product = <factory.declarations.SubFactory object>
purchasable = <factory.fuzzy.FuzzyAttribute object>
shop = <factory.declarations.SubFactory object>
visibility = <factory.fuzzy.FuzzyChoice object>
class shuup.testing.factories.ProductFactory(**kwargs)[source]

Bases: DjangoModelFactory

Would be called if trying to instantiate the class.

cost_center = <factory.fuzzy.FuzzyInteger object>
name = <shuup.testing.factories.product_factory.FuzzyName object>
post = <factory.declarations.PostGeneration object>
profit_center = <factory.fuzzy.FuzzyInteger object>
sales_unit = <factory.declarations.LazyAttribute object>
sku = <factory.fuzzy.FuzzyText object>
tax_class = <factory.declarations.LazyAttribute object>
type = <factory.declarations.LazyAttribute object>
class shuup.testing.factories.CompanyFactory(**kwargs)[source]

Bases: DjangoModelFactory

Would be called if trying to instantiate the class.

email = <factory.declarations.Sequence object>
name = <factory.fuzzy.FuzzyText object>
tax_number = <factory.fuzzy.FuzzyText object>
class shuup.testing.factories.PersonContactFactory(**kwargs)[source]

Bases: DjangoModelFactory

Would be called if trying to instantiate the class.

email = <factory.declarations.Sequence object>
first_name = <factory.faker.Faker object>
gender = <factory.declarations.Iterator object>
language = 'en'
last_name = <factory.faker.Faker object>
name = <factory.faker.Faker object>
phone = <factory.faker.Faker object>
shuup.testing.factories.create_random_company(shop=None) CompanyContact[source]
shuup.testing.factories.create_random_contact_group(shop=None)[source]
shuup.testing.factories.create_random_order(customer=None, products=(), completion_probability=0, shop=None, random_products=True, create_payment_for_order_total=False, order_date=None) Order[source]
shuup.testing.factories.create_random_person(locale='en', minimum_name_comp_len=0, shop=None)[source]
shuup.testing.factories.create_random_product_attribute()[source]
shuup.testing.factories.get_default_product_type()[source]
shuup.testing.factories.get_default_supplier(shop=None)[source]
shuup.testing.factories.get_initial_order_status()[source]
shuup.testing.factories.get_completed_order_status()[source]
shuup.testing.factories.default_by_identifier(model)[source]
shuup.testing.factories.get_default_attribute_set()[source]
shuup.testing.factories.get_default_manufacturer()[source]
shuup.testing.factories.get_tax(code, name, rate=None, amount=None)[source]
shuup.testing.factories.create_default_tax_rule(tax)[source]
shuup.testing.factories.get_default_tax()[source]
shuup.testing.factories.get_test_tax(rate)[source]
shuup.testing.factories.get_default_tax_class()[source]
shuup.testing.factories.get_currency(code, digits=2)[source]
shuup.testing.factories.get_default_currency()[source]
shuup.testing.factories.get_custom_payment_processor()[source]
shuup.testing.factories.get_payment_processor_with_checkout_phase()[source]
shuup.testing.factories.get_custom_carrier()[source]
shuup.testing.factories.get_default_payment_method()[source]
shuup.testing.factories.get_payment_method(shop=None, price=None, waive_at=None, name=None)[source]
shuup.testing.factories.get_default_shipping_method()[source]
shuup.testing.factories.get_shipping_method(shop=None, price=None, waive_at=None, name=None)[source]
shuup.testing.factories.get_default_customer_group(shop=None)[source]
shuup.testing.factories.get_supplier(module_identifier, shop=None, **kwargs)[source]
shuup.testing.factories.get_default_shop()[source]
shuup.testing.factories.get_shop(prices_include_tax=True, currency='EUR', identifier=None, enabled=False, **kwargs)[source]
shuup.testing.factories.get_random_filer_image()[source]
shuup.testing.factories.complete_product(product)[source]
shuup.testing.factories.create_product(sku, shop=None, supplier=None, default_price=None, **attrs)[source]
shuup.testing.factories.get_default_product()[source]
shuup.testing.factories.get_default_shop_product()[source]
shuup.testing.factories.get_default_sales_unit()[source]
shuup.testing.factories.get_fractional_sales_unit()[source]
shuup.testing.factories.get_default_category()[source]
shuup.testing.factories.get_default_permission_group(permissions=('dashboard',))[source]
shuup.testing.factories.get_faker(providers, locale='en')[source]
shuup.testing.factories.create_random_user(locale='en', **kwargs)[source]
shuup.testing.factories.get_default_staff_user(shop=None)[source]
shuup.testing.factories.get_random_email(fake)[source]
shuup.testing.factories.create_random_address(fake=None, save=True, **values) MutableAddress[source]
shuup.testing.factories.get_address(**overrides)[source]
shuup.testing.factories.create_attribute_with_options(name, options, min_options=0, max_options=0)[source]
shuup.testing.factories.create_empty_order(prices_include_tax=False, shop=None)[source]
shuup.testing.factories.add_product_to_order(order, supplier, product, quantity, taxless_base_unit_price, tax_rate=0, pricing_context=None)[source]
shuup.testing.factories.create_order_with_product(product, supplier, quantity, taxless_base_unit_price, tax_rate=0, n_lines=1, shop=None)[source]
shuup.testing.factories.get_all_seeing_key(user_or_contact)[source]
shuup.testing.factories.get_basket(shop=None)[source]
shuup.testing.factories.create_package_product(sku, shop=None, supplier=None, default_price=None, children=4, **attrs)[source]
shuup.testing.factories.create_default_order_statuses()[source]

shuup.testing.image_generator module

class shuup.testing.image_generator.BaseImageGenerator(image, palette, seed)[source]

Bases: object

Parameters:
  • image (PIL.Image.Image) – The image to draw on

  • palette – A list of RGB tuples

  • seed (int) – Random generator seed

__init__(image, palette, seed)[source]
Parameters:
  • image (PIL.Image.Image) – The image to draw on

  • palette – A list of RGB tuples

  • seed (int) – Random generator seed

generate()[source]
draw_circle(x, y, w, h, color)[source]
draw_rectangle(x, y, w, h, color)[source]
class shuup.testing.image_generator.RandomImageGenerator(image, palette, seed)[source]

Bases: BaseImageGenerator

Parameters:
  • image (PIL.Image.Image) – The image to draw on

  • palette – A list of RGB tuples

  • seed (int) – Random generator seed

generate()[source]
step()[source]
class shuup.testing.image_generator.ModernArtImageGenerator(image, palette, seed)[source]

Bases: BaseImageGenerator

Parameters:
  • image (PIL.Image.Image) – The image to draw on

  • palette – A list of RGB tuples

  • seed (int) – Random generator seed

generate()[source]
class shuup.testing.image_generator.RingImageGenerator(image, palette, seed)[source]

Bases: BaseImageGenerator

Parameters:
  • image (PIL.Image.Image) – The image to draw on

  • palette – A list of RGB tuples

  • seed (int) – Random generator seed

generate()[source]
shuup.testing.image_generator.generate_image(width, height, palette=None, seed=None, supersample=2)[source]

shuup.testing.importers module

class shuup.testing.importers.DummyImporter(data, context)[source]

Bases: DataImporter

identifier = 'dummy_importer'
name = 'Dummy Importer'
model

alias of Contact

example_files = [<shuup.importer.importing.importing.ImporterExampleFile object>]
get_row_model(row)[source]

Get model that matches the row.

Can be used in cases where you have multiple types of data in same import.

Parameters:

row – A row dict.

class shuup.testing.importers.DummyFileImporter(data, context)[source]

Bases: DataImporter

identifier = 'dummy_file_importer'
name = 'Dummy File Importer'
model

alias of Contact

example_files = [<shuup.importer.importing.importing.ImporterExampleFile object>]
get_row_model(row)[source]

Get model that matches the row.

Can be used in cases where you have multiple types of data in same import.

Parameters:

row – A row dict.

classmethod get_example_file_content(example_file, request)[source]

Returns a binary file that will be served through the request. This base implementation just renders a template and returns the result as BytesIO or StringIO. Override this method to return a custom file content.

:param request HttpRequest :rtype StringIO|BytesIO

shuup.testing.line_properties_descriptor module

class shuup.testing.line_properties_descriptor.TestLinePropertiesDescriptor[source]

Bases: BaseLinePropertiesDescriptor

classmethod get_line_properties(line, **kwargs)[source]

shuup.testing.mock_population module

class shuup.testing.mock_population.Populator[source]

Bases: object

__init__()[source]
populate()[source]
generate_pricing(product)[source]
ensure_shop_products()[source]

Ensure all products are associated with the default shop.

populate_if_required()[source]
ensure_product_stock()[source]

Ensure all shop products have sufficient stock for testing.

shuup.testing.mock_population.populate_if_required()[source]

shuup.testing.notify_script_templates module

class shuup.testing.notify_script_templates.DummyScriptTemplate(script_instance=None)[source]

Bases: ScriptTemplate

Parameters:

script_instance (shuup.notify.models.script.Script|None) – script instance to change or None

identifier = 'dummy_script_template'
name = 'A Dummy Script Template'
description = 'More Texts'
help_text = 'A good help here'
create_script(shop, form=None)[source]

Create and returns the Script.

If form_class is set, the will be validated and you can use it to do extra configuration on the Script.

Returns:

the created script

Return type:

shuup.notify.models.script.Script

can_edit_script()[source]

Check whether the bound script_instance attribute can be edited by this TemplateScript.

This means if you can still understand the current script state and structure and parse it, so you can edit the script through the form_class.

This is a necessary check since the user can change the script through the Editor and those changes can disfigure the expected script structure.

Return type:

bool

Returns:

whether the bound script_instance can be edited by this script template

update_script(form)[source]

Updates the current bound script_instance with the validated form data.

This method is invoked when editing a Script created through this ScriptTemplate.

Note that only script templates which provides a form will have this method invoked.

Returns:

the updated script

Return type:

shuup.notify.models.script.Script

shuup.testing.receivers module

shuup.testing.receivers.shop_product_orderability_check(sender, **kwargs)[source]

Signal handler for detecting shop product orderability changes

For projects which purchasable doesn’t change based on contact or contact group can hide unorderable products from frontend by changing the product visibility. By default Shuup shows all visible products at front which might not be desired for all projects.

Orderability can depend on contact or contact group only when some custom supplier modules are included. In these cases the project orderability signal handler has to adapt accordingly.

shuup.testing.receivers.ensure_shop_product_visibility(shop_product)[source]

shuup.testing.service_forms module

shuup.testing.shop_provider module

class shuup.testing.shop_provider.TestingAdminShopProvider[source]

Bases: object

get_shop(request)[source]
set_shop(request, shop=None)[source]
unset_shop(request)[source]

shuup.testing.simple_checkout_phase module

shuup.testing.single_page_checkout_test_urls module

shuup.testing.single_page_checkout_with_login_and_register_conf module

class shuup.testing.single_page_checkout_with_login_and_register_conf.SinglePageCheckoutViewWithLoginAndRegister(**kwargs)[source]

Bases: SinglePageCheckoutView

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

initial_phase = 'checkout_method'
phase_specs = ['shuup.front.checkout.checkout_method:CheckoutMethodPhase', 'shuup.front.checkout.checkout_method:RegisterPhase', 'shuup.front.checkout.addresses:AddressesPhase', 'shuup.front.checkout.methods:MethodsPhase', 'shuup.front.checkout.methods:ShippingMethodPhase', 'shuup.front.checkout.methods:PaymentMethodPhase', 'shuup.front.checkout.confirm:ConfirmPhase']
empty_phase_spec = 'shuup.front.checkout.empty:EmptyPhase'

shuup.testing.soup_utils module

shuup.testing.soup_utils.extract_form_fields(soup)[source]

Turn a BeautifulSoup form in to a dict of fields and default values

shuup.testing.subscription_option_provider module

class shuup.testing.subscription_option_provider.TestSubscriptionOptionProvider[source]

Bases: BaseProductSubscriptionOptionProvider

classmethod get_subscription_options(context: ProductSubscriptionContext) Iterable[ProductSubscriptionOption][source]

shuup.testing.supplier_provider module

class shuup.testing.supplier_provider.UsernameSupplierProvider[source]

Bases: object

classmethod get_supplier(request, **kwargs)[source]
class shuup.testing.supplier_provider.RequestSupplierProvider[source]

Bases: object

classmethod get_supplier(request, **kwargs)[source]
class shuup.testing.supplier_provider.FirstSupplierProvider[source]

Bases: object

classmethod get_supplier(request, **kwargs)[source]

shuup.testing.text_data module

shuup.testing.text_data.random_title(second_adj_chance=0.3, prefix='', suffix='')[source]

shuup.testing.utils module

shuup.testing.utils.apply_request_middleware(request, **attrs)[source]

Apply all the process_request capable middleware configured into the given request.

Parameters:
Returns:

The same request, massaged in-place.

Return type:

django.http.HttpRequest

shuup.testing.utils.apply_view_middleware(request)[source]

Apply all the process_view capable middleware configured into the given request.

The logic is roughly copied from django.core.handlers.base.BaseHandler.get_response

Parameters:

request (django.http.HttpRequest) – The request to massage.

Returns:

The same request, massaged in-place.

Return type:

django.http.HttpRequest

shuup.testing.utils.disable_weak_password_middleware(test_func)[source]

Decorator to disable weak password middleware for tests that don’t check password complexity.

This decorator temporarily removes the weak password middleware from Django’s MIDDLEWARE setting during test execution, preventing password complexity validation from interfering with tests that focus on other functionality.

Usage:

@disable_weak_password_middleware def test_user_creation(self):

# Test user creation without password complexity validation pass

Parameters:

test_func – The test function to decorate

Returns:

Wrapped test function with middleware disabled

shuup.testing.utils.apply_all_middleware(request, **attrs)[source]

Apply all the process_request and process_view capable middleware configured into the given request.

Parameters:
  • request (django.http.HttpRequest) – The request to massage.

  • attrs (dict) – Additional attributes to set to the request after massage.

Returns:

The same request, massaged in-place.

Return type:

django.http.HttpRequest

Module contents

shuup.testing.activate_sqlite_fk_constraint(sender, connection, **kwargs)[source]

Enable integrity constraint with SQLite and not running browser tests.

class shuup.testing.ShuupTestingAppConfig(*args, **kwargs)[source]

Bases: AppConfig

name = 'shuup.testing'
verbose_name = 'Shuup Testing & Demo Utilities'
label = 'shuup_testing'
provides = {'admin_contact_edit_toolbar_button': ['shuup.testing.modules.mocker.toolbar:MockContactToolbarButton'], 'admin_contact_section': ['shuup.testing.modules.mocker.sections:MockContactSection'], 'admin_contact_toolbar_action_item': ['shuup.testing.modules.mocker.toolbar:MockContactToolbarActionItem'], 'admin_contact_toolbar_button': ['shuup.testing.modules.mocker.toolbar:MockContactToolbarButton'], 'admin_module': ['shuup.testing.modules.mocker:TestingAdminModule', 'shuup.testing.modules.sample_data:SampleDataAdminModule', 'shuup.testing.modules.demo:DemoModule'], 'admin_product_toolbar_action_item': ['shuup.testing.modules.mocker.toolbar:MockProductToolbarActionItem'], 'admin_shop_edit_toolbar_button': ['shuup.testing.modules.mocker.toolbar:MockShopToolbarButton'], 'front_service_checkout_phase_provider': ['shuup.testing.simple_checkout_phase.PaymentPhaseProvider', 'shuup.testing.simple_checkout_phase.ShipmentPhaseProvider'], 'importers': ['shuup.testing.importers.DummyImporter', 'shuup.testing.importers.DummyFileImporter'], 'pricing_module': ['shuup.testing.supplier_pricing.pricing:SupplierPricingModule'], 'service_provider_admin_form': ['shuup.testing.service_forms:PseudoPaymentProcessorForm', 'shuup.testing.service_forms:PaymentWithCheckoutPhaseForm', 'shuup.testing.service_forms:CarrierWithCheckoutPhaseForm'], 'xtheme': ['shuup.testing.themes:ShuupTestingTheme', 'shuup.testing.themes:ShuupTestingThemeWithCustomBase']}

See /provides for details about the provides variable.

ready()[source]

Override this method in subclasses to run code when Django starts.