def test_processor_orderability(admin_user): source = OrderSource(Shop()) processor = OrderProcessor() line = source.add_line( type=OrderLineType.PRODUCT, product=get_default_product(), supplier=get_default_supplier(), quantity=1, shop=get_default_shop(), base_unit_price=source.create_price(10), ) line.order = Order(shop=get_default_shop()) assert processor._check_orderability(line) is None unorderable_line = source.add_line( type=OrderLineType.PRODUCT, product=create_product("no-shop"), supplier=get_default_supplier(), quantity=1, shop=get_default_shop(), base_unit_price=source.create_price(20), ) unorderable_line.order = Order(shop=get_default_shop()) with pytest.raises(ValidationError) as exc: processor._check_orderability(unorderable_line) assert "Not available in" in exc.value.message
def test_contact_group_basket_condition_with_none(rf): request = apply_request_middleware(rf.get("/")) request.shop = Shop() basket = get_basket(request) condition = ContactGroupBasketCondition.objects.create() result = condition.matches(basket) # Should not raise any errors assert result is False
def test_get_shop_configuration(conf_get_mock, rf): shop = Shop(identifier='da-shop', name='The Shop') request = rf.get('/') request.shop = shop ctx = Template('').new_context({'request': request}) get_shop_configuration(ctx, 'some_variable') conf_get_mock.assert_called_once_with(shop, 'some_variable', None) conf_get_mock.reset_mock() get_shop_configuration(ctx, 'some_variable', 'default') conf_get_mock.assert_called_once_with(shop, 'some_variable', 'default')
def test_pricing_module_is_active(): """ Make sure that our custom pricing module is active. """ shop = Shop(currency='USD', prices_include_tax=False) customer = AnonymousContact() product = Product(sku='6.0745') pricing_mod = get_pricing_module() pricing_ctx = pricing_mod.get_context_from_data(shop, customer) pi = product.get_price_info(pricing_ctx, quantity=2) price = shop.create_price assert pi.price == price('12.149') assert pi.base_price == price('48.596') assert pi.quantity == 2 assert pi.discounted_unit_price == price('6.0745') assert pi.base_unit_price == price('24.298') assert pi.discount_rate == Decimal('0.75')
def test_codes_type_conversion(): source = OrderSource(Shop()) assert source.codes == [] source.add_code("t") source.add_code("e") source.add_code("s") assert source.codes == ["t", "e", "s"] was_added = source.add_code("t") assert was_added is False assert source.codes == ["t", "e", "s"] was_cleared = source.clear_codes() assert was_cleared assert source.codes == [] was_cleared = source.clear_codes() assert not was_cleared source.add_code("test") source.add_code(1) source.add_code("1") assert source.codes == ["test", "1"]
def test_invalid_source_line_updating(): source = OrderSource(Shop()) with pytest.raises(TypeError): # Test forbidden keys SourceLine(source).update({"update": True})
def test_invalid_order_source_updating(): with pytest.raises(ValueError): # Test nonexisting key updating OrderSource(Shop()).update(__totes_not_here__=True)
def get_request(): request = RequestFactory().get('/') request.shop = Shop(currency='USD', prices_include_tax=False) request.customer = AnonymousContact() request.person = request.customer