I'm interested in learning how to Doctests and Unit tests in a more Agile / BDD way. I've found a few tutorials that seem reasonable, but they are just thumbnails. What I would really like to see is the source code of some Django projects that were developed BDD style.
The things I'm unclear about are how do you handle request objects etc. I have a situation where I have deployed my app and I'm getting completely different behavior in production that I did in development or even from the Python shell on the production server. I'm hoping some Doctests will help me diagnose this and well as open the door for a more Agile process of writing the tests first.
Specifically, here is the code I'm trying to test:
def match_pictures_with_products( queryset, number_of_images = 3):
products = []
i = 0
for product in queryset:
if i < ( number_of_images ):
image = product.imagemain_set.all()[:1]
product.photo_url = image[0].photo.url
products.append(product)
i += 1
return products
def index(request):
"""returns the top 10 most clicked products"""
products = Product.objects.all()[:10]
products = match_pictures_with_products( products, 10) .
return render_to_response('products/product_list.html', {'products': products})
How do I create a Doctest that ensures that index returns 10 objects?
The Product queries seem to work fine from the shell on the production server. The actual server is not returning any products at all.