def setUp(self): super(FormsTestCase, self).setUp() from django_shop_payer_backend.forms import PayerRedirectForm from django_shop_payer_backend.helper import ( payer_order_item_from_order_item, payer_order_item_from_extra_order_price) payer_order = PayerOrder( order_id=self.shop.get_order_unique_id(self.order), description="Test order", ) payer_order.set_buyer_details( buyer_details_from_user(user=self.user, order=self.order)) for order_item in self.order.items.all(): payer_order.add_order_item( payer_order_item_from_order_item(order_item)) for extra_order_price in self.order.extraorderpricefield_set.all(): payer_order.add_order_item( payer_order_item_from_extra_order_price(extra_order_price)) pc = PayerProcessingControl( success_redirect_url="http://host.com/shop/success/", authorize_notification_url="http://host.com/shop/authorize/", settle_notification_url="http://host.com/shop/settle/", redirect_back_to_shop_url="http://host.com/shop/redirect/", ) self.backend.api.set_processing_control(pc) self.backend.api.set_order(payer_order) self.redirect_data = self.backend.api.get_post_data() self.form = PayerRedirectForm(redirect_data=self.redirect_data)
def setUp(self): super(FormsTestCase, self).setUp() from django_shop_payer_backend.forms import PayerRedirectForm from django_shop_payer_backend.helper import ( payer_order_item_from_order_item, payer_order_item_from_extra_order_price) payer_order = PayerOrder( order_id=self.shop.get_order_unique_id(self.order), description="Test order", ) payer_order.set_buyer_details(buyer_details_from_user(user=self.user, order=self.order)) for order_item in self.order.items.all(): payer_order.add_order_item(payer_order_item_from_order_item(order_item)) for extra_order_price in self.order.extraorderpricefield_set.all(): payer_order.add_order_item(payer_order_item_from_extra_order_price(extra_order_price)) pc = PayerProcessingControl( success_redirect_url="http://host.com/shop/success/", authorize_notification_url="http://host.com/shop/authorize/", settle_notification_url="http://host.com/shop/settle/", redirect_back_to_shop_url="http://host.com/shop/redirect/", ) self.backend.api.set_processing_control(pc) self.backend.api.set_order(payer_order) self.redirect_data = self.backend.api.get_post_data() self.form = PayerRedirectForm(redirect_data=self.redirect_data)
def test_anonymous_user_with_address_signal(self): # Existing callable at path with self.settings(SHOP_PAYER_BACKEND_ADDRESS_HANDLER= 'django_shop_payer_backend.tests.override_address'): buyer = buyer_details_from_user(AnonymousUser(), self.order) self.assertEquals(buyer.first_name, "Peter") self.assertEquals(buyer.last_name, "Parker") self.assertEquals(buyer.address_line_1, "Back Street 987") self.assertEquals(buyer.postal_code, "98765") self.assertEquals(buyer.city, "Somewhere") self.assertEquals(buyer.email, None) # Inexistent callable at path for invalid_path in ['invalid.path']: with self.settings( SHOP_PAYER_BACKEND_ADDRESS_HANDLER=invalid_path): self.assertRaises(ImportError, buyer_details_from_user, ( AnonymousUser(), self.order, )) from django_shop_payer_backend.helper import _import_path self.assertRaises(ValueError, _import_path, None) self.assertRaises(ValueError, _import_path, "")
def test_anonymous_user_with_signal(self): populate_buyer_details_dict.connect(self.add_additional_buyer_details) buyer = buyer_details_from_user(AnonymousUser(), self.order) self.assertAddressData(buyer) self.assertEquals(buyer.email, None) self.assertEquals(buyer.organisation, "The Company Inc.") populate_buyer_details_dict.disconnect(self.add_additional_buyer_details)
def test_auth_user_without_address_with_signal(self): populate_buyer_details_dict.connect(self.add_additional_buyer_details) buyer = buyer_details_from_user(self.user, self.order) self.assertAddressData(buyer) self.assertEquals(buyer.email, "*****@*****.**") self.assertEquals(buyer.organisation, "The Company Inc.") populate_buyer_details_dict.disconnect(self.add_additional_buyer_details)
def test_anonymous_user_with_signal(self): populate_buyer_details_dict.connect(self.add_additional_buyer_details) buyer = buyer_details_from_user(AnonymousUser(), self.order) self.assertAddressData(buyer) self.assertEquals(buyer.email, None) self.assertEquals(buyer.organisation, "The Company Inc.") populate_buyer_details_dict.disconnect( self.add_additional_buyer_details)
def test_auth_user_without_address_with_signal(self): populate_buyer_details_dict.connect(self.add_additional_buyer_details) buyer = buyer_details_from_user(self.user, self.order) self.assertAddressData(buyer) self.assertEquals(buyer.email, "*****@*****.**") self.assertEquals(buyer.organisation, "The Company Inc.") populate_buyer_details_dict.disconnect( self.add_additional_buyer_details)
def test_auth_user_without_address_no_signal(self): user = User.objects.create(username="******", email="*****@*****.**", first_name="Mary-Jane", last_name="Watson") user.save() buyer = buyer_details_from_user(user, self.order) self.assertAddressData(buyer) self.assertEquals(buyer.email, "*****@*****.**")
def test_auth_user_without_address_no_signal(self): user = User.objects.create( username="******", email="*****@*****.**", first_name="Mary-Jane", last_name="Watson") user.save() buyer = buyer_details_from_user(user, self.order) self.assertAddressData(buyer) self.assertEquals(buyer.email, "*****@*****.**")
def payer_redirect_view(self, request): """ This view generates the order XML data and other key-value pairs needed, outputs the as hidden input elemens in a form and redirects to Payer. """ order = self.shop.get_order(request) description = self.shop.get_order_short_name(order) order_id = self.shop.get_order_unique_id(order) user = None if request.user.is_authenticated(): user = request.user payer_order = PayerOrder( order_id=order_id, description=description, ) payer_order.set_buyer_details(buyer_details_from_user(user=user, order=order)) for order_item in order.items.all(): payer_order.add_order_item(payer_order_item_from_order_item(order_item)) for extra_order_price in order.extraorderpricefield_set.all(): payer_order.add_order_item(payer_order_item_from_extra_order_price(extra_order_price)) for info in order.extra_info.all(): for t in list(string_chunks(info.text, 255)): payer_order.add_info_line(t) self.api.set_processing_control(self.get_processing_control(request)) self.api.set_order(payer_order) redirect_data = self.api.get_post_data() form = PayerRedirectForm(redirect_data=redirect_data) ctx_data = { 'order': order, 'redirect_data': redirect_data, 'form_action': self.api.get_post_url(), 'form': form, } if settings.DEBUG: ctx_data['xml_data'] = self.api.get_xml_data(pretty_print=True) context = RequestContext(request, ctx_data) return render_to_response(self.template, context)
def test_anonymous_user_with_address_signal(self): # Existing callable at path with self.settings(SHOP_PAYER_BACKEND_ADDRESS_HANDLER='django_shop_payer_backend.tests.override_address'): buyer = buyer_details_from_user(AnonymousUser(), self.order) self.assertEquals(buyer.first_name, "Peter") self.assertEquals(buyer.last_name, "Parker") self.assertEquals(buyer.address_line_1, "Back Street 987") self.assertEquals(buyer.postal_code, "98765") self.assertEquals(buyer.city, "Somewhere") self.assertEquals(buyer.email, None) # Inexistent callable at path for invalid_path in ['invalid.path']: with self.settings(SHOP_PAYER_BACKEND_ADDRESS_HANDLER=invalid_path): self.assertRaises( ImportError, buyer_details_from_user, (AnonymousUser(), self.order,)) from django_shop_payer_backend.helper import _import_path self.assertRaises(ValueError, _import_path, None) self.assertRaises(ValueError, _import_path, "")
def test_anonymous_user_no_signal(self): buyer = buyer_details_from_user(AnonymousUser(), self.order) self.assertAddressData(buyer) self.assertEquals(buyer.email, None)
def test_auth_user_no_signal(self): buyer = buyer_details_from_user(self.user, self.order) self.assertAddressData(buyer) self.assertEquals(buyer.email, "*****@*****.**")
def test_anonymous_user_no_signal(self): buyer = buyer_details_from_user(AnonymousUser(), self.order) self.assertAddressData(buyer) self.assertEquals(buyer.email, None)
def test_auth_user_no_signal(self): buyer = buyer_details_from_user(self.user, self.order) self.assertAddressData(buyer) self.assertEquals(buyer.email, "*****@*****.**")