Note that there are some explanatory texts on larger screens.

plurals
  1. POExamples of using Doctests in Django in an Agile / BDD way
    text
    copied!<p>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.</p> <p>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.</p> <p>Specifically, here is the code I'm trying to test:</p> <pre><code>def match_pictures_with_products( queryset, number_of_images = 3): products = [] i = 0 for product in queryset: if i &lt; ( 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}) </code></pre> <p>How do I create a Doctest that ensures that index returns 10 objects?<br> The Product queries seem to work fine from the shell on the production server. The actual server is not returning any products at all.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload