def test_wizard_get_payment_method_from_data_method(self): """ Test that method can return module name from forms data """ form_list = [Mock(data={'payment_method': 'dummy'}), Mock(data=[])] wizard = PrePaymentWizard() expected_value = 'dummy' module_name = wizard.get_payment_method_from_data(form_list) self.assertEqual(expected_value, module_name)
def test_generate_choices(self): """ Test that method generate currect choices """ expected_list = [('flat', 'Flat Shipping ($20)')] wizard = PrePaymentWizard() choice_data = {'flat': {'price': 20, 'name': 'Flat Shipping'}} current_list = wizard.generate_choices(choice_data) self.assertEqual(expected_list, current_list)
def test_wizard_get_payment_method_name_from_request_method(self): """ Test that method can return module name from request """ request = RequestFactory().post('/', {'payment_method': 'dummy'}) wizard = PrePaymentWizard() wizard.request = request expected_value = 'dummy' module_name = wizard.get_payment_method_name_from_request() self.assertEqual(expected_value, module_name)
def test_dummy_form_save_credit_number(self): """ Test that dummy payment form save method save order """ wizard = PrePaymentWizard() cart = model_factory(Cart, save=True) wizard.order = model_factory(Order, cart=cart) form = DummyPaymentForm() form.cleaned_data = FORM_CLEANED_DATA order = form.save(wizard) self.assertEqual(order.card_number, '1111')
def test_process_step_call_shipping(self): request = RequestFactory().post('/', {'shipping_method': 'flat'}) request.session = {'choice_data': {'flat': {'price': 20, 'name': 'Flat Shipping'}} } wizard = PrePaymentWizard() wizard.request = request with patch( 'salest.payments.views.PrePaymentWizard.store_shipping_cost') \ as store_shipping_cost: wizard.process_step(Mock()) store_shipping_cost.assert_called_once_with()
def test_base_address_save(self): """ Test that form save address with shipping=True and address is saved """ wizard = PrePaymentWizard() wizard.contact = model_factory(Contact, save=True) address = model_factory(Address) form = BaseAddressForm() with patch('django.forms.ModelForm.save', Mock(return_value=address)): address = form.save(wizard=wizard) self.assertTrue(address.pk is not None) self.assertEqual(address.contact, wizard.contact)
def test_remove_payment_form_if_change(self): """ Test that method remove payment form from wizard if payment method change """ last_form = Mock() form_list = {'0': Mock(), '1': Mock(), '2': last_form} request = RequestFactory().post('/', {'payment_method': 'paypal'}) request.session = {'module_name': 'dummy'} wizard = PrePaymentWizard() wizard.form_list = form_list wizard.request = request wizard.remove_payment_form_if_change() self.assertFalse(last_form in wizard.form_list)
def test_trustcommerce_form_save_credit_number(self): """ Test that method save last four number or credit cart """ wizard = PrePaymentWizard() request = RequestFactory().get('/') request.session = {} wizard.request = request cart = model_factory(Cart, save=True) wizard.order = model_factory(Order, cart=cart) form = TrustCommercePaymentForm() form.cleaned_data = FORM_CLEANED_DATA order = form.save(wizard) self.assertEqual(order.card_number, '1111')
def test_store_shipping_cost(self): """ Test that method store shipping cost """ expected_value = 20 request = RequestFactory().post('/', {'shipping_method': 'flat'}) request.session = {'choice_data': {'flat': {'price': expected_value, 'name': 'Flat Shipping'}} } wizard = PrePaymentWizard() wizard.request = request with patch('django.conf.settings.PAYMENT_MODULES', {'dummy': 'salest.payments.modules.dummy'}): wizard.store_shipping_cost() self.assertEqual(expected_value, request.session['shipping_cost'])
def test_trustcommerce_form_save_session(self): """ Test that method set data in session """ expected_dict = PAYMENT_INFO_IN_SESSION.copy() wizard = PrePaymentWizard() request = RequestFactory().get('/') request.session = {} wizard.request = request cart = model_factory(Cart, save=True) wizard.order = model_factory(Order, cart=cart, save=True) form = TrustCommercePaymentForm() form.cleaned_data = FORM_CLEANED_DATA form.save(wizard) self.assertEqual(expected_dict, request.session)
def test_billing_address_save(self): """ Test that form save address with shipping=True""" address = model_factory(Address) form = BillingAddressForm() base_save = Mock(return_value=address) commit_save = Mock(return_value=address) wizard = PrePaymentWizard() wizard.contact = model_factory(Contact, save=True) with nested(patch( 'salest.accounts.forms.BaseAddressForm.save', base_save), patch('salest.accounts.forms.InstanceSaveCommitMixin.save', commit_save)): address = form.save(wizard=wizard) base_save.assert_called_once_with(form, commit=False, wizard=wizard) commit_save.assert_called_once_with(form, commit=True) self.assertTrue(address.is_billing)
def test_wizard_cart_checkout(self): """ Test that wizard methot done call cart checkout method """ request = RequestFactory().get('/') user = model_factory(User, save=True) cart = model_factory(Cart, contact=user.contact, is_active=True, save=True) model_factory(Order, cart=cart, save=True) request.user = user request.cart = cart wizard = PrePaymentWizard() wizard.request = request with patch('salest.cart.models.Cart.checkout') as cart_checkout: wizard.done([Mock(data={'payment_method': 'dummy'}), Mock(data=[])]) cart_checkout.assert_called_once_with()
def test_wizard_form_save(self): """ Test that wizard mwthod done save forms """ request = RequestFactory().get('/') user = model_factory(User, save=True) cart = model_factory(Cart, contact=user.contact, is_active=True, save=True) model_factory(Order, cart=cart, save=True) request.user = user request.cart = cart wizard = PrePaymentWizard() wizard.request = request form1 = Mock(data={'payment_method': 'dummy'}) form2 = Mock(data=[]) wizard.done([form1, form2]) self.assertTrue(form1.save.call_count == 1) self.assertTrue(form2.save.call_count == 1)
def test_save(self): """ Test that method set currect data to order """ expected_list = ['flat', 20.0] cart = model_factory(Cart, save=True) order = model_factory(Order, cart=cart, save=True) request = RequestFactory() request.session = {'shipping_cost': 20} wizard = PrePaymentWizard() wizard.order = order wizard.request = request form = ChoiceShippingForm() form.cleaned_data = {'shipping_method': 'flat'} form.save(wizard) self.assertEqual(expected_list, [wizard.order.shipping_method, wizard.order.shipping_price])
def test_wizard_add_paymet_form_method(self): """ Test that method add payment form to wizard from payment module """ request = RequestFactory().post('/', {'payment_method': 'dummy'}) request.session = {} form_with_method_name = Mock(data={'payment_method': 'dummy'}) form_list = {'1': Mock(data=[]), '0': form_with_method_name} wizard = PrePaymentWizard() wizard.request = request wizard.steps = Mock(count=2) wizard.form_list = form_list with patch('django.conf.settings.PAYMENT_MODULES', {'dummy': 'salest.payments.modules.dummy'}): wizard.add_paymet_form() self.assertIn(DummyPaymentForm, wizard.form_list.values())
from django.conf.urls.defaults import patterns, url, include from salest.accounts.forms import ShippingAddressForm, BillingAddressForm from salest.payments.views import PrePaymentWizard from salest.payments.forms import ChoicePaymentForm, ChoiceShippingForm,\ ConfirmForm pre_payment_wizard = PrePaymentWizard.as_view(( ('Shipping Address', ShippingAddressForm ), ('Billing Address', BillingAddressForm), ('Shipping Method', ChoiceShippingForm), ('Payment Method', ChoicePaymentForm), ('Confirm', ConfirmForm))) urlpatterns = patterns('salest.payments.views', url(r'^$', pre_payment_wizard, name='pre_payment'), # url(r'^success/$', 'success', name='success'), )