class TestCheckoutSession(TestCase): """ oscar.apps.checkout.utils.CheckoutSessionData """ def setUp(self): request = RequestFactory().get('/') SessionMiddleware().process_request(request) self.session_data = CheckoutSessionData(request) def test_allows_data_to_be_written_and_read_out(self): self.session_data._set('namespace', 'key', 'value') self.assertEqual('value', self.session_data._get('namespace', 'key')) def test_allows_set_data_can_be_unset(self): self.session_data._set('namespace', 'key', 'value') self.session_data._unset('namespace', 'key') self.assertIsNone(self.session_data._get('namespace', 'key')) def test_stores_guest_email(self): self.session_data.set_guest_email('*****@*****.**') self.assertEqual('*****@*****.**', self.session_data.get_guest_email()) def test_allows_a_namespace_to_be_flushed(self): self.session_data._set('ns', 'a', 1) self.session_data._set('ns', 'b', 2) self.session_data._flush_namespace('ns') self.assertIsNone(self.session_data._get('ns', 'a')) self.assertIsNone(self.session_data._get('ns', 'b')) def test_allows_bill_to_user_address(self): address = mock.Mock() address.id = 1 self.session_data.bill_to_user_address(address) self.assertEqual(1, self.session_data.billing_user_address_id())
class TestCheckoutSession(TestCase): """ oscar.apps.checkout.utils.CheckoutSessionData """ def setUp(self): request = RequestFactory().get('/') SessionMiddleware().process_request(request) self.session_data = CheckoutSessionData(request) def test_allows_data_to_be_written_and_read_out(self): self.session_data._set('namespace', 'key', 'value') self.assertEqual('value', self.session_data._get('namespace', 'key')) def test_allows_set_data_can_be_unset(self): self.session_data._set('namespace', 'key', 'value') self.session_data._unset('namespace', 'key') self.assertIsNone(self.session_data._get('namespace', 'key')) def test_stores_guest_email(self): self.session_data.set_guest_email('*****@*****.**') self.assertEquals('*****@*****.**', self.session_data.get_guest_email()) def test_allows_a_namespace_to_be_flushed(self): self.session_data._set('ns', 'a', 1) self.session_data._set('ns', 'b', 2) self.session_data._flush_namespace('ns') self.assertIsNone(self.session_data._get('ns', 'a')) self.assertIsNone(self.session_data._get('ns', 'b')) def test_allows_bill_to_user_address(self): address = mock.Mock() address.id = 1 self.session_data.bill_to_user_address(address) self.assertEqual(1, self.session_data.billing_user_address_id())
def place_order(sender, **kwargs): """ collect basket, user, shipping_method and address, order_number, total and pass them to handle_order_placement, but first add payment events and sources """ request = kwargs.get('request', None) or HttpRequest() basket = sender user = basket.owner if basket.owner else AnonymousUser() guest_email = None strategy = selector.strategy(user=user) session_data = shipping_address = shipping_method = None log.debug("initialising: \n basket = %s \n usr = %s \n strategy = %s", basket, user, strategy) basket.strategy = strategy amount_allocated = kwargs['OutSum'] session_key = kwargs['session_key'] order_num = kwargs['order_num'] if session_key is not None: session = SessionStore(session_key = session_key) if len(session.items()): log.debug("Session %s successfully restored", session) request.session = session request.user = user session_data = CheckoutSessionData(request) if isinstance(user, AnonymousUser): guest_email = session_data.get_guest_email() order_placement = RobokassaOrderPlacement() order_placement.request = request if session_data is not None: order_placement.checkout_session = session_data shipping_address = order_placement.get_shipping_address(basket) shipping_method = order_placement.get_shipping_method( basket, shipping_address) total = order_placement.get_order_totals(basket, shipping_method) else: # session not found, lets try to place order anyway log.error(("Session was not restored, trying default order for " "basket #%s"), basket.id) basket.is_shipping_required = False total = prices.Price( currency=basket.currency, excl_tax=basket.total_excl_tax, incl_tax=basket.total_incl_tax) # now create payment source and events source_type, is_created = SourceType.objects.get_or_create( name=u'Робокасса', code='robokassa') source = Source(source_type=source_type, amount_allocated=amount_allocated, amount_debited=amount_allocated) order_placement.add_payment_source(source) order_placement.add_payment_event('allocated', amount_allocated) order_placement.add_payment_event('debited', amount_allocated) post_payment.send(sender=order_placement, user=user, source=source) # all done lets place an order order_placement.handle_order_placement( order_num, user, basket, shipping_address, shipping_method, total, guest_email=guest_email)
def place_order(sender, **kwargs): """ collect basket, user, shipping_method and address, order_number, total and pass them to handle_order_placement, but first add payment events and sources """ request = kwargs.get('request', None) or HttpRequest() basket = sender user = basket.owner if basket.owner else AnonymousUser() guest_email = None strategy = selector.strategy(user=user) session_data = shipping_address = shipping_method = None log.debug("initialising: \n basket = %s \n usr = %s \n strategy = %s", basket, user, strategy) basket.strategy = strategy amount_allocated = kwargs['OutSum'] session_key = kwargs['session_key'] order_num = kwargs['order_num'] if session_key is not None: session = SessionStore(session_key=session_key) if len(session.items()): log.debug("Session %s successfully restored", session) request.session = session request.user = user session_data = CheckoutSessionData(request) if isinstance(user, AnonymousUser): guest_email = session_data.get_guest_email() order_placement = RobokassaOrderPlacement() order_placement.request = request if session_data is not None: order_placement.checkout_session = session_data shipping_address = order_placement.get_shipping_address(basket) shipping_method = order_placement.get_shipping_method( basket, shipping_address) total = order_placement.get_order_totals(basket, shipping_method) else: # session not found, lets try to place order anyway log.error(("Session was not restored, trying default order for " "basket #%s"), basket.id) basket.is_shipping_required = False total = prices.Price(currency=basket.currency, excl_tax=basket.total_excl_tax, incl_tax=basket.total_incl_tax) # now create payment source and events source_type, is_created = SourceType.objects.get_or_create( name=u'Робокасса', code='robokassa') source = Source(source_type=source_type, amount_allocated=amount_allocated, amount_debited=amount_allocated) order_placement.add_payment_source(source) order_placement.add_payment_event('allocated', amount_allocated) order_placement.add_payment_event('debited', amount_allocated) post_payment.send(sender=order_placement, user=user, source=source) # all done lets place an order order_placement.handle_order_placement(order_num, user, basket, shipping_address, shipping_method, total, guest_email=guest_email)