def test_multiple_payment_events(self): basket = factories.create_basket(empty=True) user = factories.UserFactory() add_product(basket, D('100.00')) order_placement = OrderPlacementMixin() order_placement.add_payment_event('Gift Card Payment', D('10')) order_placement.add_payment_event('Credit Card Payment', D('90')) shipping_method = Free() shipping_charge = shipping_method.calculate(basket) order_total = OrderTotalCalculator().calculate(basket, shipping_charge) billing_address = factories.BillingAddressFactory() shipping_address = factories.ShippingAddressFactory() order_submission_data = { 'user': user, 'order_number': '12345', 'basket': basket, 'shipping_method': shipping_method, 'shipping_charge': shipping_charge, 'order_total': order_total, 'billing_address': billing_address, 'shipping_address': shipping_address } order_placement.place_order(**order_submission_data) order1 = Order.objects.get(number='12345') self.assertEqual(order1.payment_events.count(), 2) event1 = order1.payment_events.all()[0] event2 = order1.payment_events.all()[1] self.assertEqual(event1.event_type.name, 'Credit Card Payment') self.assertEqual(event1.amount, D('90')) self.assertEqual(event1.lines.count(), 1) self.assertEqual(event2.event_type.name, 'Gift Card Payment') self.assertEqual(event2.amount, D('10')) self.assertEqual(event2.lines.count(), 1)
def setUp(self): self.product = factories.create_product() self.stockrecord = factories.create_stockrecord(self.product, D('12.00'), num_in_stock=5) self.basket = factories.create_basket(empty=True) add_product(self.basket, product=self.product)
def setUp(self): self.order = factories.create_order() self.handler = EventHandler() basket = factories.create_basket(empty=True) add_product(basket, D('10.00'), 5) self.order = factories.create_order(basket=basket) self.settled = models.PaymentEventType.objects.create(name='Settled')
def setUp(self): self.range = models.Range.objects.create(name="All products", includes_all_products=True) self.condition = models.CountCondition.objects.create( range=self.range, type=models.Condition.COUNT, value=3) self.offer = mock.Mock() self.basket = factories.create_basket(empty=True)
def test_moving_from_saved_basket(self): self.user = User.objects.create_user(username='******', password='******', email='*****@*****.**') product = create_product(price=D('10.00'), num_in_stock=2) basket = factories.create_basket(empty=True) basket.owner = self.user basket.save() add_product(basket, product=product) saved_basket, created = Basket.saved.get_or_create(owner=self.user) saved_basket.strategy = basket.strategy add_product(saved_basket, product=product) response = self.get(reverse('basket:summary')) saved_formset = response.context['saved_formset'] saved_form = saved_formset.forms[0] data = { saved_formset.add_prefix('INITIAL_FORMS'): 1, saved_formset.add_prefix('MAX_NUM_FORMS'): 1, saved_formset.add_prefix('TOTAL_FORMS'): 1, saved_form.add_prefix('id'): saved_form.initial['id'], saved_form.add_prefix('move_to_basket'): True, } response = self.post(reverse('basket:saved'), params=data) self.assertEqual( Basket.open.get(id=basket.id).lines.get(product=product).quantity, 2) self.assertRedirects(response, reverse('basket:summary'))
def test_checks_whether_passed_product_id_matches_a_real_product(self): basket = factories.create_basket() product = basket.all_lines()[0].product # Add more of the same product data = {'quantity': -1} form = forms.AddToBasketForm(basket=basket, product=product, data=data) self.assertFalse(form.is_valid())
def test_allows_a_product_quantity_to_be_increased(self): basket = factories.create_basket() product = basket.all_lines()[0].product # Add more of the same product data = {'quantity': 1} form = forms.AddToBasketForm(basket=basket, product=product, data=data) self.assertTrue(form.is_valid())
def test_multi_item_basket(self): basket = factories.create_basket(empty=True) record = factories.create_stockrecord() basket.add_product(record.product, 7) charge = self.method.calculate(basket) self.assertEqual(D('5.00') + 7 * D('1.00'), charge.incl_tax)
def setUp(self): range = models.Range.objects.create(name="All products", includes_all_products=True) self.condition = models.CountCondition.objects.create( range=range, type=models.Condition.COUNT, value=3) self.benefit = models.FixedPriceBenefit.objects.create( range=range, type=models.Benefit.FIXED_PRICE, value=D('20.00')) self.offer = mock.Mock() self.basket = factories.create_basket(empty=True)
def setUp(self): range = models.Range.objects.create(name="All products", includes_all_products=True) self.condition = models.CountCondition.objects.create( range=range, type=models.Condition.COUNT, value=2) self.offer = mock.Mock() self.benefit = models.AbsoluteDiscountBenefit.objects.create( range=range, type=models.Benefit.FIXED, value=D('3.00')) self.basket = factories.create_basket(empty=True)
def setUp(self): range = models.Range.objects.create(name="All products", includes_all_products=True) self.condition = models.CountCondition.objects.create( range=range, type=models.Condition.COUNT, value=3) self.benefit = models.MultibuyDiscountBenefit.objects.create( range=range, type=models.Benefit.MULTIBUY) self.offer = mock.Mock() self.basket = factories.create_basket(empty=True)
def setUp(self): basket = create_basket(empty=True) add_product(basket, D('10.00'), 4) self.order = create_order(number='100002', basket=basket) self.line = self.order.lines.all()[0] self.order_placed, __ = ShippingEventType.objects.get_or_create( code='order_placed', name='Order placed') self.dispatched, __ = ShippingEventType.objects.get_or_create( code='dispatched', name='Dispatched')
def setUp(self): """ Creates two orders. order_in has self.user in it's partner users list. """ super().setUp() self.address = ShippingAddressFactory() self.basket_in = create_basket() self.basket_out = create_basket() # replace partner with one that has the user in it's users list self.partner_in = PartnerFactory(users=[self.user]) stockrecord = self.basket_in.lines.all()[0].stockrecord stockrecord.partner = self.partner_in stockrecord.save() self.order_in = create_order(basket=self.basket_in, shipping_address=self.address) self.order_out = create_order(basket=self.basket_out, shipping_address=self.address)
def setUp(self): range = models.Range.objects.create(name="All products", includes_all_products=True) self.condition = models.ValueCondition.objects.create( range=range, type=models.Condition.VALUE, value=D('10.00')) self.benefit = models.PercentageDiscountBenefit.objects.create( range=range, type=models.Benefit.PERCENTAGE, value=20) self.offer = mock.Mock() self.basket = factories.create_basket(empty=True)
def setUp(self): self.range = models.Range.objects.create(name="All products range", includes_all_products=True) self.basket = factories.create_basket(empty=True) self.condition = models.ValueCondition(range=self.range, type="Value", value=D('10.00')) self.offer = mock.Mock() self.item = factories.create_product(price=D('5.00')) self.expensive_item = factories.create_product(price=D('15.00'))
def setUp(self): range = models.Range.objects.create(name="All products", includes_all_products=True) self.condition = models.CountCondition.objects.create( range=range, type=models.Condition.COUNT, value=2) self.benefit = models.ShippingPercentageDiscountBenefit.objects.create( type=models.Benefit.SHIPPING_PERCENTAGE, value=50) self.offer = models.ConditionalOffer(condition=self.condition, benefit=self.benefit) self.basket = factories.create_basket(empty=True)
def test_consumes_correct_number_of_products_for_4_product_basket(self): basket = factories.create_basket(empty=True) add_products(basket, [(D('1'), 2), (D('1'), 2)]) self.assertTrue(self.offer.is_condition_satisfied(basket)) discount = self.offer.apply_benefit(basket) self.assertTrue(discount.discount > 0) self.assertEqual(3, basket.num_items_with_discount) self.assertEqual(1, basket.num_items_without_discount) self.assertFalse(self.offer.is_condition_satisfied(basket))
def test_partner_name_is_optional(self): for partner_name, order_number in [('', 'A'), ('p1', 'B')]: self.basket = factories.create_basket(empty=True) product = factories.create_product(partner_name=partner_name) add_product(self.basket, D('12.00'), product=product) place_order( self.creator, basket=self.basket, order_number=order_number) line = Order.objects.get(number=order_number).lines.all()[0] partner = product.stockrecords.all()[0].partner self.assertTrue(partner_name == line.partner_name == partner.name)
def setUp(self): basket = create_basket(empty=True) add_product(basket, D('10.00'), 4) self.order = create_order(number='100002', basket=basket) self.line = self.order.lines.all()[0] self.shipped, __ = ShippingEventType.objects.get_or_create( name='Shipped') self.returned, __ = ShippingEventType.objects.get_or_create( name='Returned')
def test_prevents_event_quantities_higher_than_original_line(self): basket = factories.create_basket(empty=True) add_product(basket, D('10.00'), 5) order = factories.create_order(basket=basket) # First shipping event lines = order.lines.all() self.handler.handle_shipping_event(order, self.shipped, lines, [4]) with self.assertRaises(exceptions.InvalidShippingEvent): self.handler.handle_shipping_event(order, self.shipped, lines, [4])
def test_returns_correct_weight_for_nonempty_basket_with_line_quantities( self): basket = factories.create_basket(empty=True) products = [(factories.create_product(attributes={'weight': '1'}, price=D('5.00')), 3), (factories.create_product(attributes={'weight': '2'}, price=D('5.00')), 4)] for product, quantity in products: basket.add(product, quantity=quantity) scale = Scale(attribute_code='weight') self.assertEqual(1 * 3 + 2 * 4, scale.weigh_basket(basket))
def test_single_item_basket_that_doesnt_require_shipping(self): # Create a product that doesn't require shipping record = factories.create_stockrecord() product = record.product product.product_class.requires_shipping = False product.product_class.save() basket = factories.create_basket(empty=True) basket.add_product(record.product) charge = self.method.calculate(basket) self.assertEqual(D('5.00'), charge.incl_tax)
def test_returns_correct_weight_for_nonempty_basket(self): basket = factories.create_basket(empty=True) products = [ factories.create_product(attributes={'weight': '1'}, price=D('5.00')), factories.create_product(attributes={'weight': '2'}, price=D('5.00')) ] for product in products: basket.add(product) scale = Scale(attribute_code='weight') self.assertEqual(1 + 2, scale.weigh_basket(basket))
def test_are_stock_allocations_available_track_stock_off(self): product_class = factories.ProductClassFactory(requires_shipping=False, track_stock=False) product = factories.ProductFactory(product_class=product_class) basket = factories.create_basket(empty=True) add_product(basket, D('10.00'), 5, product=product) order = factories.create_order(basket=basket) line = order.lines.get() self.assertEqual( self.handler.are_stock_allocations_available([line], [105]), True, )
def test_zero_charge_with_shipping_discount(self): offer = factories.create_offer( benefit=Benefit.objects.create( type=Benefit.SHIPPING_FIXED_PRICE, value=1), ) basket = factories.create_basket() Applicator().apply_offers(basket, [offer]) # Similar to test_zero_charge_discount(), # but now test how the repository deals with it. method = Repository().apply_shipping_offer( basket, self.standard, offer) self.assertEqual(D('0.00'), method.discount(basket))
def setUp(self): range = models.Range.objects.create(name="All products", includes_all_products=True) self.condition = models.CountCondition(range=range, type=models.Condition.COUNT, value=2) self.benefit = models.PercentageDiscountBenefit( range=range, type=models.Benefit.PERCENTAGE, value=20, max_affected_items=1) self.offer = mock.Mock() self.basket = factories.create_basket(empty=True)
def setUp(self): self.products = [ factories.create_product(), factories.create_product() ] self.range = models.Range.objects.create(name="Some products") for product in self.products: self.range.add_product(product) self.range.add_product(product) self.basket = factories.create_basket(empty=True) self.condition = models.CoverageCondition(range=self.range, type="Coverage", value=2) self.offer = mock.Mock()
def test_consumes_correct_number_of_products_for_6_product_basket(self): basket = factories.create_basket(empty=True) add_products(basket, [(D('1'), 3), (D('1'), 3)]) # First application discount = self.offer.apply_benefit(basket) self.assertTrue(discount.discount > 0) self.assertEqual(3, basket.num_items_with_discount) self.assertEqual(3, basket.num_items_without_discount) # Second application discount = self.offer.apply_benefit(basket) self.assertTrue(discount.discount > 0) self.assertEqual(6, basket.num_items_with_discount)
def setUp(self): self.applicator = Applicator() rng = RangeFactory(includes_all_products=True) self.condition = ConditionFactory( range=rng, type=ConditionFactory._meta.model.VALUE, value=D('100'), proxy_class=None) self.benefit = BenefitFactory(range=rng, type=BenefitFactory._meta.model.FIXED, value=D('10'), max_affected_items=1) self.basket = factories.create_basket() self.line = self.basket.all_lines()[0]
def test_decimals(self): basket = factories.create_basket(empty=True) product = factories.create_product(attributes={'weight': '0.3'}, price=D('5.00')) basket.add(product) scale = Scale(attribute_code='weight') self.assertEqual(D('0.3'), scale.weigh_basket(basket)) basket.add(product) self.assertEqual(D('0.6'), scale.weigh_basket(basket)) basket.add(product) self.assertEqual(D('0.9'), scale.weigh_basket(basket))