def test_different_values(self): shipping_values = ['1.00', '5.00', '10.00', '12.00'] for value in shipping_values: basket = Basket() method = FixedPrice(D(value)) method.set_basket(basket) self.assertEquals(D(value), method.basket_charge_excl_tax())
def get_shipping_method(self, basket, shipping_address=None, **kwargs): """ Return the shipping method used """ if not basket.is_shipping_required(): return NoShippingRequired() # Instantiate a new FixedPrice shipping method instance charge_incl_tax = D(self.txn.value('PAYMENTREQUEST_0_SHIPPINGAMT')) # Assume no tax for now charge_excl_tax = charge_incl_tax name = self.txn.value('SHIPPINGOPTIONNAME') session_method = super(SuccessResponseView, self).get_shipping_method( basket, shipping_address, **kwargs) if not session_method or (name and name != session_method.name): if name: method = self._get_shipping_method_by_name(name, basket, shipping_address) else: method = None if not method: method = FixedPrice(charge_excl_tax, charge_incl_tax) if session_method: method.name = session_method.name method.code = session_method.code else: method = session_method return method
def get_shipping_method(self, basket=None): """ Return the shipping method used """ charge = D(self.txn.value('PAYMENTREQUEST_0_SHIPPINGAMT')) method = FixedPrice(charge) basket = basket if basket else self.request.basket method.set_basket(basket) method.name = self.txn.value('SHIPPINGOPTIONNAME') return method
class StubRepository(Repository): """ Stubbed shipped repository which overrides the get_shipping_methods method in order to use a non-free default shipping method. This allows the shipping discounts to be tested. """ methods = [FixedPrice(D('10.00'), D('10.00'))]
class Repository(CoreRepository): """ This class is included so that there is a choice of shipping methods. Oscar's default behaviour is to only have one which means you can't test the shipping features of PayFast. """ methods = [Free(), FixedPrice(D('10.00'), D('10.00'))]
def setUp(self): self.non_discount_methods = [ Free(), FixedPrice(D('10.00'), D('10.00')), OrderAndItemCharges(price_per_order=D('5.00'), price_per_item=D('1.00')) ]
def get_shipping_method(self, basket=None): """ Return the shipping method used """ charge = D(self.txn.value('PAYMENTREQUEST_0_SHIPPINGAMT')) method = FixedPrice(charge) basket = basket if basket else self.request.basket method.set_basket(basket) name = self.txn.value('SHIPPINGOPTIONNAME') if not name: # Look to see if there is a method in the session session_method = self.checkout_session.shipping_method(basket) if session_method: method.name = session_method.name else: method.name = name return method
def test_forbids_zero_value_basket(self): basket = create_mock_basket(D('0.00')) shipping_methods = [FixedPrice(D('2.50'))] with patch('paypal.express.gateway._fetch_response') as mock_fetch: with self.assertRaises(InvalidBasket): gateway.set_txn(basket, shipping_methods, 'GBP', 'http://example.com', 'http://example.com')
def get_available_shipping_methods(self, basket, shipping_addr=None, **kwargs): """ Return a list of all applicable shipping method instances for a given basket, address etc. """ methods = [Free(), FixedPrice(D('10.00'), D('10.00'))] return methods
def test_not_forbid_if_shipping_not_zero(self): basket = create_mock_basket(D('0.00')) shipping_methods = [FixedPrice(D('2.50'), D('2.50'))] with patch('paypal.express.gateway._fetch_response') as mock_fetch: gateway.set_txn(basket, shipping_methods, 'GBP', 'http://example.com', 'http://example.com') args, __ = mock_fetch.call_args params = args[1] self.assertEqual(params['PAYMENTREQUEST_0_AMT'], D('2.50'))
def get_shipping_method(self, basket=None, shipping_address=None, **kwargs): """ Return the shipping method used """ # Instantiate a new FixedPrice shipping method instance charge_incl_tax = D(self.txn.value('PAYMENTREQUEST_0_SHIPPINGAMT')) # Assume no tax for now charge_excl_tax = charge_incl_tax method = FixedPrice(charge_excl_tax, charge_incl_tax) method.set_basket(basket) name = self.txn.value('SHIPPINGOPTIONNAME') if not name: # Look to see if there is a method in the session session_method = super(SuccessResponseView, self).get_shipping_method(basket, shipping_address) if session_method: method.name = session_method.name else: method.name = name return method
def get_shipping_method(self, basket, shipping_address=None, **kwargs): """ Return the shipping method used """ if not basket.is_shipping_required(): return NoShippingRequired() # Instantiate a new FixedPrice shipping method instance charge_incl_tax = D(self.txn.value('PAYMENTREQUEST_0_SHIPPINGAMT')) # Assume no tax for now charge_excl_tax = charge_incl_tax method = FixedPrice(charge_excl_tax, charge_incl_tax) method.set_basket(basket) name = self.txn.value('SHIPPINGOPTIONNAME') if not name: # Look to see if there is a method in the session session_method = self.checkout_session.shipping_method_code(basket) if session_method: method.name = session_method #.name else: method.name = name return method
class Repository(CoreRepository): """ This class is included so that there is a choice of shipping methods. Oscar's default behaviour is to only have one which means you can't test the shipping features of PayPal. """ methods = [Free(), FixedPrice(D('10.00'))] def get_shipping_methods(self, user, basket, shipping_addr=None, **kwargs): return self.prime_methods(basket, self.methods) def find_by_code(self, code, basket): for method in self.methods: if code == method.code: return self.prime_method(basket, method)
def test_shipping_offer_is_applied(self): add_product(self.basket, D('12.00')) offer = self.apply_20percent_shipping_offer() shipping = FixedPrice(D('5.00'), D('5.00')) shipping = Repository().apply_shipping_offer(self.basket, shipping, offer) place_order(self.creator, basket=self.basket, order_number='1234', shipping_method=shipping) order = Order.objects.get(number='1234') self.assertEqual(1, len(order.shipping_discounts)) self.assertEqual(D('4.00'), order.shipping_incl_tax) self.assertEqual(D('16.00'), order.total_incl_tax)
from decimal import Decimal as D from oscar.apps.shipping.methods import FixedPrice from oscar.apps.shipping.repository import Repository as CoreRepository # Dummy shipping methods method1 = FixedPrice(charge_excl_tax=D("10.00"), charge_incl_tax=D("10.00")) method1.code = "method1" method1.description = "Ship by van" method2 = FixedPrice(charge_excl_tax=D("20.00"), charge_incl_tax=D("20.00")) method2.code = "method2" method2.description = "Ship by boat" class Repository(CoreRepository): methods = ( method1, method2, )
def get_methods(self): return [Free(), FixedPrice(D('10.00'), D('10.00'))]
def test_fixed_price_shipping_assumes_no_tax(self): method = FixedPrice(D('10.00')) basket = Basket() method.set_basket(basket) self.assertEquals(D('10.00'), method.basket_charge_excl_tax())
def test_update_address_book(self): basket = factories.create_basket(empty=True) user = factories.UserFactory() add_product(basket, D('12.00')) shipping_method = FixedPrice(D('5.00'), D('5.00')) billing_address = factories.BillingAddressFactory( line1='1 Boardwalk Place', line2='Trafalgar Way', line3='Tower Hamlets', line4='London') shipping_address = factories.ShippingAddressFactory( line1='Knightsbridge', line2='159', line4='London') shipping_charge = shipping_method.calculate(basket) order_total = OrderTotalCalculator().calculate(basket, shipping_charge) order_submission_data = { 'user': user, 'order_number': '12345', 'basket': basket, 'shipping_address': shipping_address, 'shipping_method': shipping_method, 'shipping_charge': shipping_charge, 'billing_address': billing_address, 'order_total': order_total } OrderPlacementMixin().place_order(**order_submission_data) self.assertEqual( user.addresses.filter( hash=billing_address.generate_hash()).count(), 1) self.assertEqual( user.addresses.filter( hash=shipping_address.generate_hash()).count(), 1) user_billing_address = user.addresses.get( hash=billing_address.generate_hash()) user_shipping_address = user.addresses.get( hash=shipping_address.generate_hash()) self.assertEqual(user_billing_address.num_orders_as_billing_address, 1) self.assertEqual(user_shipping_address.num_orders_as_shipping_address, 1) order_submission_data['order_number'] = '12346' OrderPlacementMixin().place_order(**order_submission_data) user_billing_address = user.addresses.get( hash=billing_address.generate_hash()) user_shipping_address = user.addresses.get( hash=shipping_address.generate_hash()) self.assertEqual(user_billing_address.num_orders_as_billing_address, 2) self.assertEqual(user_shipping_address.num_orders_as_shipping_address, 2) order_submission_data.pop('billing_address', None) order_submission_data['order_number'] = '123457' OrderPlacementMixin().place_order(**order_submission_data) user_billing_address = user.addresses.get( hash=billing_address.generate_hash()) user_shipping_address = user.addresses.get( hash=shipping_address.generate_hash()) self.assertEqual(user_billing_address.num_orders_as_billing_address, 2) self.assertEqual(user_shipping_address.num_orders_as_shipping_address, 3) shipping_address.line2 = '160' order_submission_data['billing_address'] = billing_address order_submission_data['order_number'] = '123458' OrderPlacementMixin().place_order(**order_submission_data) user_billing_address = user.addresses.get( hash=billing_address.generate_hash()) user_shipping_address = user.addresses.get( hash=shipping_address.generate_hash()) self.assertEqual(user_billing_address.num_orders_as_billing_address, 3) self.assertEqual(user_shipping_address.num_orders_as_shipping_address, 1)
def get_shipping_methods(self, user, basket, shipping_addr=None, **kwargs): methods = [Free(), FixedPrice(D('10.00')), FixedPrice(D('20.00'))] return self.prime_methods(basket, methods)
def test_fixed_price_shipping_charges_for_empty_basket(self): method = FixedPrice(D('10.00'), D('10.00')) basket = Basket() method.set_basket(basket) self.assertEquals(D('10.00'), method.basket_charge_incl_tax()) self.assertEquals(D('10.00'), method.basket_charge_excl_tax())
from decimal import Decimal as D from oscar.apps.shipping.methods import FixedPrice, NoShippingRequired from oscar.apps.shipping.repository import Repository as CoreRepository # Dummy shipping methods method1 = FixedPrice(D('10.00')) method1.code = 'method1' method1.description = 'Ship by van' method2 = FixedPrice(D('20.00')) method2.code = 'method2' method2.description = 'Ship by boat' class Repository(CoreRepository): methods = ( method1, method2, )
class StubRepository(Repository): """ Custom shipping methods """ methods = (FixedPrice(D('5.00'), D('5.00')), Free())
from decimal import Decimal as D from oscar.apps.shipping.methods import FixedPrice, NoShippingRequired from oscar.apps.shipping.repository import Repository as CoreRepository # Dummy shipping methods method1 = FixedPrice(D("10.00")) method1.code = "method1" method1.description = "Ship by van" method2 = FixedPrice(D("20.00")) method2.code = "method2" method2.description = "Ship by boat" METHODS = (method1, method2) class Repository(CoreRepository): def get_shipping_methods(self, user, basket, shipping_addr=None, **kwargs): return self.prime_methods(basket, METHODS) def find_by_code(self, code, basket): if code == NoShippingRequired.code: method = NoShippingRequired() else: method = None for method_ in METHODS: if method_.code == code: method = method_ if method is None: raise ValueError("No shipping method found with code '%s'" % code) return self.prime_method(basket, method)
def test_update_address_book(self): basket = factories.create_basket(empty=True) user = factories.UserFactory() add_product(basket, D('12.00')) shipping_method = FixedPrice(D('5.00'), D('5.00')) billing_address = factories.BillingAddressFactory(line1='1 Boardwalk Place', line2='Trafalgar Way', line3='Tower Hamlets', line4='London') shipping_address = factories.ShippingAddressFactory(line1='Knightsbridge', line2='159', line4='London') shipping_charge = shipping_method.calculate(basket) order_total = OrderTotalCalculator().calculate(basket, shipping_charge) order_submission_data = {'user': user, 'order_number': '12345', 'basket': basket, 'shipping_address': shipping_address, 'shipping_method': shipping_method, 'shipping_charge': shipping_charge, 'billing_address': billing_address, 'order_total': order_total} OrderPlacementMixin().place_order(**order_submission_data) self.assertEqual(user.addresses.filter(hash=billing_address.generate_hash()).count(), 1) self.assertEqual(user.addresses.filter(hash=shipping_address.generate_hash()).count(), 1) user_billing_address = user.addresses.get(hash=billing_address.generate_hash()) user_shipping_address = user.addresses.get(hash=shipping_address.generate_hash()) self.assertEqual(user_billing_address.num_orders_as_billing_address, 1) self.assertEqual(user_shipping_address.num_orders_as_shipping_address, 1) order_submission_data['order_number'] = '12346' OrderPlacementMixin().place_order(**order_submission_data) user_billing_address = user.addresses.get(hash=billing_address.generate_hash()) user_shipping_address = user.addresses.get(hash=shipping_address.generate_hash()) self.assertEqual(user_billing_address.num_orders_as_billing_address, 2) self.assertEqual(user_shipping_address.num_orders_as_shipping_address, 2) order_submission_data.pop('billing_address', None) order_submission_data['order_number'] = '123457' OrderPlacementMixin().place_order(**order_submission_data) user_billing_address = user.addresses.get(hash=billing_address.generate_hash()) user_shipping_address = user.addresses.get(hash=shipping_address.generate_hash()) self.assertEqual(user_billing_address.num_orders_as_billing_address, 2) self.assertEqual(user_shipping_address.num_orders_as_shipping_address, 3) shipping_address.line2 = '160' order_submission_data['billing_address'] = billing_address order_submission_data['order_number'] = '123458' OrderPlacementMixin().place_order(**order_submission_data) user_billing_address = user.addresses.get(hash=billing_address.generate_hash()) user_shipping_address = user.addresses.get(hash=shipping_address.generate_hash()) self.assertEqual(user_billing_address.num_orders_as_billing_address, 3) self.assertEqual(user_shipping_address.num_orders_as_shipping_address, 1)
def test_different_values(self, value): method = FixedPrice(D(value)) basket = Basket() method.set_basket(basket) self.assertEquals(D(value), method.basket_charge_excl_tax())
def get_shipping_methods(self, basket): methods = [FixedPrice(D('10.00'), D('10.00'))] return self.prime_methods(basket, methods)
class Repository(CoreRepository): methods = [Free(), FixedPrice(D('10.00'), D('10.00'))]
from decimal import Decimal as D from oscar.apps.shipping.methods import FixedPrice, NoShippingRequired from oscar.apps.shipping.repository import Repository as CoreRepository # Dummy shipping methods method1 = FixedPrice(D('12.00')) method1.code = 'method1' method1.name = 'Ship by van' method2 = FixedPrice(D('24.00')) method2.code = 'method2' method2.name = 'Ship by pigeon' method2.description = 'Here is a description of this shipping method' class Repository(CoreRepository): methods = { method1.code: method1, method2.code: method2, } def get_shipping_methods(self, user, basket, shipping_addr=None, **kwargs): methods = self.methods.values() return self.prime_methods(basket, methods) def find_by_code(self, code, basket): if code == NoShippingRequired.code: method = NoShippingRequired() else: method = self.methods.get(code, None) return self.prime_method(basket, method)
from decimal import Decimal as D from oscar.apps.shipping.methods import FixedPrice, NoShippingRequired from oscar.apps.shipping.repository import Repository as CoreRepository # Dummy shipping methods method1 = FixedPrice(charge_excl_tax=D('10.00'), charge_incl_tax=D('10.00')) method1.code = 'method1' method1.description = 'Ship by van' method2 = FixedPrice(charge_excl_tax=D('20.00'), charge_incl_tax=D('20.00')) method2.code = 'method2' method2.description = 'Ship by boat' class Repository(CoreRepository): methods = (method1, method2,)