﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
3051	django.test.client.Client() does not set HttpResponse context and template properly	anonymous	Adrian Holovaty	"Using a view function that relies upon render_to_response(template, context), I run a doctest over the view function utilizing the django.test.client.Client class, however when I get my response object back, the context and template attributes are None.

I thought it might be specific to the doctest, however running the test by hand in a python shell yields the same result.

My view:
{{{
# URL re is (r'^(?P<mp_slug>\w+)/(?P<product_class_slug_string>[^_][a-zA-Z0-9_/]+)/_(?P<product_slug>\w+)/$', 'product_detail'),
def product_detail(request, mp_slug, product_class_slug_string, product_slug):
  manipulator = marketplace.ShoppingCartItem.AddManipulator()
  mp = get_object_or_404(marketplace.Marketplace, slug__exact=mp_slug)
  product = get_object_or_404(marketplace.Product, slug__exact=product_slug, 
                              product_class__marketplace__id__exact=mp.id)
  product_class_slug_list = product_class_slug_string.split('/')
  assert product.product_class.marketplace == mp
  assert product_class_slug_list == map(lambda pc: pc.slug, product.product_class.get_ancestry())
  product_class = product.product_class
  data_copy = {}
  
  if request.method == 'POST':
    data_copy = request.POST.copy()
    shopping_cart = marketplace.ShoppingCart.objects.get_cart(mp, request.session)
    
    errors = manipulator.get_validation_errors(data_copy)
    if not errors:
      manipulator.do_html2python(data_copy)
      shopping_cart.add_item_to_cart(product, data_copy['quantity'], data_copy['size_option'])
      return HttpResponseRedirect(shopping_cart.get_absolute_url())
  else:
    errors = {}
  form = forms.FormWrapper(manipulator, data_copy, errors)
  return render_to_response('product_detail.djt', {'form': form,
                                                   'marketplace': mp,
                                                   'product': product,
                                                   'product_class': product_class,
                                                   })


>>> from fsforg.marketplace import models as marketplace

>>> from django.test.client import Client
 

>>> mp = marketplace.Marketplace(name='Test MP', slug='test_mp')

>>> mp.save()

>>> stuff = marketplace.ProductClass(name='Stuff', slug='stuff', parent=None, marketplace=mp)

>>> stuff.save()

>>> thing = marketplace.Product(name='Thing', slug='thing', short_desc='Thing', long_desc='Thing',

...                 unit_price=123.45, photo_url='http://www.gnu.org/graphics/gnu-head-banner.png',

...                 product_class=stuff, weight=0.0)

>>> 

>>> thing.save()
>>> thing.get_absolute_url()

'/marketplaces/test_mp/stuff/_thing/'

>>> c = Client()

>>> response = c.get(thing.get_absolute_url())

>>> response.status_code

200

>>> response.context

>>> response.template

}}}"	defect	closed	Documentation	dev	normal	fixed		django@…	Ready for checkin	1	0	0	0	0	0
