def eligible_products(self, order, items, products=None): """ Return a list of products which are eligible for discounting using the discount configuration. """ if not products: shop = plata.shop_instance() products = shop.product_model._default_manager.all() variations = ProductVariation.objects.filter( id__in=[item.variation_id for item in items]) orderitems = shop.orderitem_model.objects.filter( id__in=[item.id for item in items]) for key, parameters in self.config.items(): parameters = dict((str(k), v) for k, v in parameters.items()) cfg = dict(self.CONFIG_OPTIONS)[key] if 'variation_query' in cfg: variations = variations.filter(cfg['variation_query'](**parameters)) if 'orderitem_query' in cfg: orderitems = orderitems.filter(cfg['orderitem_query'](**parameters)) return products.filter(id__in=variations.values('product_id')).filter(id__in=orderitems.values('variation__product__id'))
def home(request): if request.fb_session.signed_request: # request is from facebook just_installed = request.session.get("just_installed",None) if just_installed: del request.session["just_installed"] page_info=request.fb_session.signed_request['page'] store = Store.objects.get(page=page_info["id"]) products = store.product_set.filter(is_flag=False, is_deleted = False) facebook_url = "http://facebook.com/pages/imly/"+page_info["id"]+'?id='+page_info["id"]+'&sk=app_'+str(settings.FACEBOOK_APPS['facestore']['ID']) try: special_event = Special.objects.filter(active=True, live=True).order_by("priority")[0] special_products = special_event.products.filter(store=store) products = products.exclude(special=special_event) except IndexError: pass try: shop = plata.shop_instance() order = shop.order_from_request(request) store_order = order.storeorder_set.get(store=store).store_items except: store_order = 0 return render(request, "facebook_store/fb_product_list.html", locals()) else: return HttpResponse('oye, some wanderer on net, get lost you troll')
def plata_context(request): """ Adds a few variables from Plata to the context if they are available: * ``plata.shop``: The current :class:`plata.shop.views.Shop` instance * ``plata.order``: The current order * ``plata.contact``: The current contact instance * ``plata.price_includes_tax``: Whether prices include tax or not """ shop = plata.shop_instance() return ( { "plata": { "shop": shop, "order": shop.order_from_request(request), "contact": ( shop.contact_from_user(request.user) if hasattr(request, "user") else None ), "price_includes_tax": shop.price_includes_tax(request), } } if shop else {} )
def render(self, request, context, **kwargs): products = self.queryset._clone() if self.only_featured: products = products.filter(is_featured=True) categories = [c.pk for c in self.categories.all()] if categories: products = products.filter(categories__in=categories) if self.only_sale: shop = plata.shop_instance() currency = shop.default_currency(request=request) products = [p for p in products if p.in_sale(currency)] my_ctx = {'content': self, 'object_list': products} if self.paginate_by: paginator = Paginator(products, self.paginate_by) try: page = int(request.GET.get('page')) except (TypeError, ValueError): page = 1 try: products = paginator.page(page) except (EmptyPage, InvalidPage): products = paginator.page(paginator.num_pages) my_ctx['page'] = products my_ctx['object_list'] = products.object_list return render_to_string('product/product_list.html', my_ctx, context_instance=context)
def product_detail(request, pk): product = get_object_or_404(Product, pk=pk) if request.method == "POST": form = OrderItemForm(request.POST) if form.is_valid(): shop = plata.shop_instance() order = shop.order_from_request(request, create=True) try: order.modify_item(product, form.cleaned_data.get("quantity")) messages.success(request, _("The cart has been updated.")) except forms.ValidationError as e: if e.code == "order_sealed": [messages.error(request, msg) for msg in e.messages] else: raise return redirect("plata_shop_cart") else: form = OrderItemForm() return render(request, "product/product_detail.html", { "object": product, "form": form })
def product_detail(request, pk): product = get_object_or_404(Product, pk=pk) if request.method == 'POST': form = OrderItemForm(request.POST) if form.is_valid(): shop = plata.shop_instance() order = shop.order_from_request(request, create=True) try: order.modify_item(product, form.cleaned_data.get('quantity')) messages.success(request, _('The cart has been updated.')) except forms.ValidationError as e: if e.code == 'order_sealed': [messages.error(request, msg) for msg in e.messages] else: raise return redirect('plata_shop_cart') else: form = OrderItemForm() return render(request, 'product/product_detail.html', { 'object': product, 'form': form, })
def plata_cart(context): shop = plata.shop_instance() order = shop.order_from_request(context['request'], create=False) return { 'order': order }
def fb_add_order(request, store_slug, product_slug): shop = plata.shop_instance() product = get_object_or_404(Product, slug=product_slug, store__slug=store_slug) if request.method == "POST": form = OrderItemForm(data=request.POST) if form.is_valid(): order = shop.order_from_request(request,create=True) stock_change = product.stock_change(order) quantity = form.cleaned_data["quantity"] if quantity > stock_change: data = {"success":False,"product_slug":product.slug} '''messages.error(request, "I can only make %d more %ss today" %(product.items_in_stock, product.name)) return render(request, "imly_product_detail.html", {"object":product, "form":form})''' return HttpResponse(simplejson.dumps(data),mimetype="application/json") order.modify_item(product, relative=form.cleaned_data["quantity"]) try: messages.success(request,"The cart has been updated") except ValidationError, e: if e.code == "order_sealed": pass else: raise #return redirect("plata_shop_cart") data = {"success":True,"count":order.items.count(),"product":product.name.lower(),"product_slug":product.slug, "items_in_stock":product.items_in_stock - quantity,"store":product.store.name.lower(),"quantity":quantity,"image":product.image_thumbnail_mini.url} return HttpResponse(simplejson.dumps(data),mimetype="application/json")
def clean(self): data = self.cleaned_data if not data.get('shipping_same_as_billing'): for f in REQUIRED_ADDRESS_FIELDS: field = 'shipping_%s' % f if not data.get(field): self._errors[field] = self.error_class([ _('This field is required.')]) email = data.get('email') create_account = data.get('create_account') if email: try: user = User.objects.get(email=email) if user != self.request.user: if self.request.user.is_authenticated(): self._errors['email'] = self.error_class([ _('This e-mail address belongs to a different account.')]) else: self._errors['email'] = self.error_class([ _('This e-mail address might belong to you, but we cannot know for sure because you are not authenticated yet.')]) # Clear e-mail address so that further processing is aborted email = None except User.DoesNotExist: # Everything is well, the e-mail address isn't occupied yet pass if email and create_account and not self.contact and not self._errors: password = None if not self.request.user.is_authenticated(): # TODO send registration mail / create registration profile password = User.objects.make_random_password() user = User.objects.create_user(email, email, password) user = auth.authenticate(username=email, password=password) auth.login(self.request, user) else: user = self.request.user shop = plata.shop_instance() contact = shop.contact_model( user=user, currency=self.instance.currency) for k, v in data.items(): if k.startswith('shipping_') or k.startswith('billing_'): setattr(contact, k, v) contact.save() self.instance.contact = contact signals.contact_created.send(sender=self, user=user, contact=contact, password=password) elif self.contact: self.instance.contact = self.contact return data
def plata_context(request): shop = plata.shop_instance() return {'plata': { 'shop': shop, 'order': shop.order_from_request(request, create=False), 'contact': shop.contact_from_user(request.user), }}
def product_list(request): shop = plata.shop_instance() return list_detail.object_list(request, queryset=shop.product_model.objects.active(), paginate_by=9, template_name='product/product_list.html', )
def test_07_paypal_ipn(self): """Test PayPal Instant Payment Notification handler""" paypal_ipn_data = { 'txn_id': '123456789', 'invoice': 'Order-1-1', 'mc_currency': 'CHF', 'mc_gross': '1234', 'payment_status': 'Completed', } from plata.payment.modules import paypal import cgi def mock_urlopen(*args, **kwargs): qs = cgi.parse_qs(args[1]) assert qs['cmd'][0] == '_notify-validate' for k, v in paypal_ipn_data.iteritems(): assert qs[k][0] == v import StringIO s = StringIO.StringIO('VERIFIED') return s paypal.urllib.urlopen = mock_urlopen shop = plata.shop_instance() request = get_request() product = self.create_product() product.stock_transactions.create(type=StockTransaction.PURCHASE, change=10) self.client.post(product.get_absolute_url(), { 'quantity': 5, }) response = self.client.post( '/confirmation/', { 'terms_and_conditions': True, 'payment_method': 'plata.payment.modules.paypal', }) self.assertContains(response, 'sandbox') self.assertEqual(StockTransaction.objects.count(), 2) self.assertEqual(Order.objects.count(), 1) self.assertEqual(OrderPayment.objects.count(), 1) self.assertContains( self.client.post('/payment/paypal/ipn/', paypal_ipn_data), 'Ok') order = Order.objects.get(pk=1) assert order.is_paid() self.assertEqual( set(( StockTransaction.PURCHASE, StockTransaction.SALE, StockTransaction.PAYMENT_PROCESS_RESERVATION, )), set(StockTransaction.objects.values_list('type', flat=True)))
def test_07_paypal_ipn(self): """Test PayPal Instant Payment Notification handler""" paypal_ipn_data = { 'txn_id': '123456789', 'invoice': 'Order-1-1', 'mc_currency': 'CHF', 'mc_gross': '1234', 'payment_status': 'Completed', } from plata.payment.modules import paypal import cgi def mock_urlopen(*args, **kwargs): qs = cgi.parse_qs(args[1]) assert qs['cmd'][0] == '_notify-validate' for k, v in paypal_ipn_data.iteritems(): assert qs[k][0] == v import StringIO s = StringIO.StringIO('VERIFIED') return s paypal.urllib.urlopen = mock_urlopen shop = plata.shop_instance() request = get_request() product = self.create_product() product.stock_transactions.create(type=StockTransaction.PURCHASE, change=10) self.client.post(product.get_absolute_url(), { 'quantity': 5, }) response = self.client.post('/confirmation/', { 'terms_and_conditions': True, 'payment_method': 'plata.payment.modules.paypal', }) self.assertContains(response, 'sandbox') self.assertEqual(StockTransaction.objects.count(), 2) self.assertEqual(Order.objects.count(), 1) self.assertEqual(OrderPayment.objects.count(), 1) self.assertContains(self.client.post('/payment/paypal/ipn/', paypal_ipn_data), 'Ok') order = Order.objects.get(pk=1) with warnings.catch_warnings(record=True) as w: self.assertTrue(order.is_paid()) self.assertEqual(len(w), 1) self.assertTrue( 'Order.is_paid() has been deprecated' in str(w[-1])) self.assertEqual( set(( StockTransaction.PURCHASE, StockTransaction.SALE, StockTransaction.PAYMENT_PROCESS_RESERVATION, )), set(StockTransaction.objects.values_list('type', flat=True)))
def shop(self): """ use this to get a shop instance without interfering with the Django startup. If you include shop_instance in the top level you may end up importing too much for Django to chew on during module loading. """ from plata import shop_instance return shop_instance()
def _fn(request, *args, **kwargs): shop = plata.shop_instance() order = shop.order_from_request(request) for check in checks: r = check(order=order, shop=shop, request=request) if r: return r return fn(request, order=order, *args, **kwargs)
def invoice_pdf(request, order_id): """ Returns the invoice PDF """ order = get_object_or_404(plata.shop_instance().order_model, pk=order_id) pdf, response = pdf_response('invoice-%09d' % order.id) plata.reporting.order.invoice_pdf(pdf, order) return response
def setUp(self): super(OrderPaymentPaypalTests, self).setUp() from plata import shop_instance self.shop = shop_instance() self.password = '******' self.username = '******' self.user = User.objects.create_user(self.username, password=self.password) self.setup_shopdata()
def packing_slip_pdf(request, order_id): """ Returns the packing slip PDF """ order = get_object_or_404(plata.shop_instance().order_model, pk=order_id) pdf, response = pdf_response('packing-slip-%09d' % order.id) plata.reporting.order.packing_slip_pdf(pdf, order) return response
def _fn(request, *args, **kwargs): shop = plata.shop_instance() order = shop.order_from_request(request, create=False) for check in checks: r = check(order=order, shop=shop, request=request) if r: return r return fn(request, order=order, *args, **kwargs)
def __init__(self, *args, **kwargs): self.order = kwargs.pop('order') super(ConfirmationForm, self).__init__(*args, **kwargs) payment_module_choices = [(m.__module__, m.name) for m in \ plata.shop_instance().get_payment_modules()] self.fields['payment_method'] = forms.ChoiceField( label=_('Payment method'), choices=[('', '----------')]+payment_module_choices, )
def one_step_checkout(request): shop = plata.shop_instance() order = shop.order_from_request(request) if not order or not order.items.count():# or order.created.date() < date.today(): #added last part to check for stale orders in cart return redirect(reverse('plata_shop_cart')) try: order.validate(order.VALIDATE_CART) except ValidationError, e: for message in e.messages: messages.error(request, message) return HttpResponseRedirect(reverse('plata_shop_cart'))
def test_02_authenticated_user_has_contact(self): """Test shop.contact_from_user works correctly""" user = User.objects.create_user("test", "*****@*****.**", "testing") self.client.login(username="******", password="******") contact = Contact.objects.create(user=user) shop = plata.shop_instance() request = get_request(user=user) self.assertEqual(shop.contact_from_user(request.user), contact)
def setUp(self): u = User.objects.create_user('admin', '*****@*****.**', 'password') u.is_staff = True u.is_superuser = True u.save() shop = plata.shop_instance() self.product_admin_url = '/admin/%s/%s/' % ( shop.product_model._meta.app_label, shop.product_model._meta.module_name, )
def test_02_authenticated_user_has_contact(self): """Test shop.contact_from_user works correctly""" user = User.objects.create_user('test', '*****@*****.**', 'testing') self.client.login(username='******', password='******') contact = Contact.objects.create(user=user) shop = plata.shop_instance() request = get_request(user=user) self.assertEqual(shop.contact_from_user(request.user), contact)
def test_05_creation(self): """Test creation of orders through the shop object""" shop = plata.shop_instance() request = get_request() order = shop.order_from_request(request) self.assertEqual(order, None) order = shop.order_from_request(request, create=True) self.assertEqual(Order.objects.count(), 1) self.assertEqual(order.user, None)
def receipt_pdf(request, order_id): """ Returns the invoice PDF """ order = get_object_or_404(plata.shop_instance().order_model, pk=order_id) if order in request.user.orders.all(): pdf, response = pdf_response('invoice-%09d' % order.id) plata.reporting.order.invoice_pdf(pdf, order) return response else: raise Http404
def get_price(self, currency=None, orderitem=None): if currency is None: currency = (orderitem.currency if orderitem else plata.shop_instance().default_currency()) possible = self.prices.filter( currency=currency, from_quantity__lte=(orderitem.quantity if orderitem else 1)) try: return possible.order_by('-from_quantity')[0] except IndexError: raise possible.model.DoesNotExist
def determine_price(self, product, currency=None): currency = currency or plata.shop_instance().default_currency() prices = dict(self.determine_prices(product)).get(currency, {}) if prices.get('sale'): return prices['sale'] if prices.get('normal'): return prices['normal'] elif prices.get('sale'): return prices['sale'] raise self.model.DoesNotExist
def plata_context(request): """ Adds the current :class:`plata.shop.views.Shop` and (if available) the current order and contact instances to the context. """ shop = plata.shop_instance() if not shop: return {} return {'plata': { 'shop': shop, 'order': shop.order_from_request(request, create=False), 'contact': shop.contact_from_user(request.user), }}
def clean_code(self): code = self.cleaned_data.get('code') if not code: return self.cleaned_data shop = plata.shop_instance() try: discount = shop.discount_model.objects.get(code=code) except shop.discount_model.DoesNotExist: raise forms.ValidationError(_('This code does not validate')) discount.validate(self.order) self.cleaned_data['discount'] = discount return code
def test_07_paypal_ipn(self): """Test PayPal Instant Payment Notification handler""" paypal_ipn_data = { "txn_id": "123456789", "invoice": "Order-1-1", "mc_currency": "CHF", "mc_gross": "1234", "payment_status": "Completed", } from plata.payment.modules import paypal import cgi def mock_urlopen(*args, **kwargs): qs = cgi.parse_qs(args[1]) assert qs["cmd"][0] == "_notify-validate" for k, v in paypal_ipn_data.iteritems(): assert qs[k][0] == v import StringIO s = StringIO.StringIO("VERIFIED") return s paypal.urllib.urlopen = mock_urlopen shop = plata.shop_instance() request = get_request() product = self.create_product() product.variations.get().stock_transactions.create(type=StockTransaction.PURCHASE, change=10) self.client.post(product.get_absolute_url(), {"quantity": 5}) response = self.client.post( "/confirmation/", {"terms_and_conditions": True, "payment_method": "plata.payment.modules.paypal"} ) self.assertContains(response, "sandbox") self.assertEqual(StockTransaction.objects.count(), 2) self.assertEqual(Order.objects.count(), 1) self.assertEqual(OrderPayment.objects.count(), 1) self.assertContains(self.client.post("/payment/paypal/ipn/", paypal_ipn_data), "Ok") order = Order.objects.get(pk=1) assert order.is_paid() self.assertEqual(StockTransaction.objects.count(), 2)
def featured_products_for_categories(category_list, variable_name='featured_product'): """ {% featured_products_for_categories category_list "variable_name" %} """ product_qset = plata.shop_instance().product_model.objects.active() category_list = list(category_list) for category in category_list: try: setattr(category, variable_name, product_qset.filter( categories=category).order_by('-is_featured', 'ordering', 'name')[0]) except IndexError: pass return u''
def get_price(self, currency=None, orderitem=None): if currency is None: currency = (orderitem.currency if orderitem else plata.shop_instance().default_currency()) prices = dict(self.get_prices()).get(currency, {}) if prices.get('sale'): return prices['sale'] if prices.get('normal'): return prices['normal'] elif prices.get('sale'): return prices['sale'] raise self.prices.model.DoesNotExist
def get_price(self, currency=None, orderitem=None): """ This method is part of the public, required API of products. It returns either a price instance or raises a ``DoesNotExist`` exception. If you need more complex pricing schemes, override this method with your own implementation. """ if currency is None: currency = (orderitem.currency if orderitem else plata.shop_instance().default_currency()) try: # Let's hope that ordering=[-id] from the base price definition # makes any sense here :-) return self.prices.filter(currency=currency)[0] except IndexError: raise self.prices.model.DoesNotExist
def plata_context(request): """ Adds a few variables from Plata to the context if they are available: * ``plata.shop``: The current :class:`plata.shop.views.Shop` instance * ``plata.order``: The current order * ``plata.contact``: The current contact instance * ``plata.price_includes_tax``: Whether prices include tax or not """ shop = plata.shop_instance() return {'plata': { 'shop': shop, 'order': shop.order_from_request(request), 'contact': (shop.contact_from_user(request.user) if hasattr(request, 'user') else None), 'price_includes_tax': plata.settings.PLATA_PRICE_INCLUDES_TAX, }} if shop else {}
def plata_context(request): """ Adds a few variables from Plata to the context if they are available: * ``plata.shop``: The current :class:`plata.shop.views.Shop` instance * ``plata.order``: The current order * ``plata.contact``: The current contact instance """ shop = plata.shop_instance() if not shop: return {} return {'plata': { 'shop': shop, 'order': shop.order_from_request(request, create=False), 'contact': shop.contact_from_user(request.user), }}
def plata_context(request): """ Adds a few variables from Plata to the context if they are available: * ``plata.shop``: The current :class:`plata.shop.views.Shop` instance * ``plata.order``: The current order * ``plata.contact``: The current contact instance * ``plata.price_includes_tax``: Whether prices include tax or not """ shop = plata.shop_instance() return {'plata': { 'shop': shop, 'order': shop.order_from_request(request), 'contact': (shop.contact_from_user(request.user) if hasattr(request, 'user') else None), 'price_includes_tax': shop.price_includes_tax(request), }} if shop else {}
def get_context_data(self, **kwargs): context = super(FBProductDetail,self).get_context_data(**kwargs) context["form"] = OrderItemForm() try: special_event = Special.objects.filter(active=True, live=True).order_by("priority")[0] if special_event: context["special_event"] = special_event context["special_product"] = self.get_object().special_set.filter(slug=special_event.slug) except IndexError: pass try: shop = plata.shop_instance() order = shop.order_from_request(self.request) store_order = order.storeorder_set.get(store=self.get_object().store).store_items except: store_order = 0 context["store_order"] = store_order context["store"] = self.get_object().store return context
def plata_context(request): """ Adds a few variables from Plata to the context if they are available: * ``plata.shop``: The current :class:`plata.shop.views.Shop` instance * ``plata.order``: The current order * ``plata.contact``: The current contact instance * ``plata.price_includes_tax``: Whether prices include tax or not """ shop = plata.shop_instance() if not shop: return {} return { 'plata': { 'shop': shop, 'order': shop.order_from_request(request), 'contact': shop.contact_from_user(request.user), 'price_includes_tax': plata.settings.PLATA_PRICE_INCLUDES_TAX, } }
def test_06_postfinance_ipn(self): """Test Postfinance server-to-server request handling""" shop = plata.shop_instance() request = get_request() product = self.create_product() Period.objects.create(name='Test period') product.stock_transactions.create(type=StockTransaction.PURCHASE, change=10) self.client.post(product.get_absolute_url(), { 'quantity': 5, }) response = self.client.post('/confirmation/', { 'terms_and_conditions': True, 'payment_method': 'postfinance', }) self.assertContains(response, 'SHASign') self.assertContains(response, '721735bc3876094bb7e5ff075de8411d85494a66') self.assertEqual(StockTransaction.objects.count(), 2) self.assertEqual(Order.objects.get().status, Order.CONFIRMED) self.assertEqual(OrderPayment.objects.count(), 1) self.client.get('/order/payment_failure/') # payment process reservation should have been removed now, # this does not change anything else though self.assertEqual(StockTransaction.objects.count(), 1) self.assertEqual(Order.objects.get().status, Order.CHECKOUT) self.assertContains(self.client.post('/payment/postfinance/ipn/', { }), 'Missing data', status_code=403) order = Order.objects.get(pk=1) ipn_data = { 'orderID': 'Order-1-1', 'currency': order.currency, 'amount': order.balance_remaining, 'PM': 'Postfinance', 'ACCEPTANCE': 'xxx', 'STATUS': '5', # Authorized 'CARDNO': 'xxxxxxxxxxxx1111', 'PAYID': '123456789', 'NCERROR': '', 'BRAND': 'VISA', 'SHASIGN': 'this-value-is-invalid', } self.assertContains(self.client.post('/payment/postfinance/ipn/', ipn_data), 'Hash did not validate', status_code=403) ipn_data['SHASIGN'] = '4b4cf5f9a5f0b54cc119be3696f43f81139232ae' self.assertContains(self.client.post('/payment/postfinance/ipn/', ipn_data), 'OK', status_code=200) order = Order.objects.get(pk=1) with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') self.assertTrue(order.is_paid()) self.assertEqual(len(w), 1) self.assertTrue( 'Order.is_paid() has been deprecated' in str(w[-1])) self.assertTrue(order.status >= Order.PAID) self.assertEqual(StockTransaction.objects.count(), 2) # Manipulate paid amount order.paid -= 10 order.save() self.assertRedirects(self.client.get('/cart/'), '/confirmation/?confirmed=1') self.assertContains(self.client.get('/order/success/'), '<h1>Order has been partially paid.</h1>') # Revert manipulation order.paid += 10 order.save() self.assertRedirects(self.client.get('/checkout/'), '/order/success/')
def test_07_paypal_ipn(self): """Test PayPal Instant Payment Notification handler""" paypal_ipn_data = { 'txn_id': '123456789', 'invoice': 'Order-1-1', 'mc_currency': 'CHF', 'mc_gross': '1234', 'payment_status': 'Completed', 'last_name': u'H\xe5konsen', } from plata.payment.modules import paypal import cgi def mock_urlopen(*args, **kwargs): qs = cgi.parse_qs(args[1].encode('ascii')) self.assertEqual(qs['cmd'][0], '_notify-validate') for k, v in paypal_ipn_data.iteritems(): self.assertEqual(unicode(qs[k][0], 'utf-8'), v) s = BytesIO('VERIFIED') return s paypal.urllib2.urlopen = mock_urlopen shop = plata.shop_instance() request = get_request() product = self.create_product() product.stock_transactions.create(type=StockTransaction.PURCHASE, change=10) self.client.post(product.get_absolute_url(), { 'quantity': 5, }) response = self.client.post('/confirmation/', { 'terms_and_conditions': True, 'payment_method': 'paypal', }) self.assertContains(response, 'sandbox') self.assertEqual(StockTransaction.objects.count(), 2) self.assertEqual(Order.objects.count(), 1) self.assertEqual(OrderPayment.objects.count(), 1) self.assertContains( self.client.post('/payment/paypal/ipn/', paypal_ipn_data), 'Ok' ) # test windows-1252 encoded IPN also: self.assertContains( self.client.post( '/payment/paypal/ipn/', dict( map( lambda (k,v): (k, v.encode('windows-1252')), dict(paypal_ipn_data, charset='windows-1252').items() ) ), ), 'Ok' ) order = Order.objects.get(pk=1) with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') self.assertTrue(order.is_paid()) self.assertEqual(len(w), 1) self.assertTrue( 'Order.is_paid() has been deprecated' in str(w[-1])) self.assertEqual( set(( StockTransaction.PURCHASE, StockTransaction.SALE, StockTransaction.PAYMENT_PROCESS_RESERVATION, )), set(StockTransaction.objects.values_list('type', flat=True)))