Question

I have given my view and models below and i need to write testcase for the following This is my view:

def dashboard_vendors(request, template="template/vendors.html"):
    """
        Listing all the vendors
    """
    try:
        page = request.GET['page']
    except:
        page = 1
    vendors = VendorProfile.objects.all().order_by('created')
    return render_to_response(template, {'vendors':vendors,'page':page },      context_instance=RequestContext(request),)

my models.py:

class VendorProfile(DateBaseModel):
"""  Vendors Profile  """
    user = models.OneToOneField(User, verbose_name=_('user'),
        related_name='vendor_profile')
    shop_name = models.CharField(_('Shop Name'), max_length=100)
    shop_image = models.ImageField(upload_to = "shops/")
    area = models.ForeignKey(Area,verbose_name=_('Area'))
    category = models.ManyToManyField(Category,related_name='vendor_category')
    owner_name = models.CharField(_('Owners Name'), max_length=100,)
    contact_name = models.CharField(_('Contact Name'), max_length=100,)

I need to write testcase for this function,am a new-bie to django and django
testing.Please Help

Was it helpful?

Solution

This helped me a lot at first:

http://toastdriven.com/blog/2011/apr/10/guide-to-testing-in-django/

Runs you through different approaches to testing and installing fixtures for you models.

In future you should really think about writing the tests first, it seems counter-intuitive if you haven't worked that way but is, in fact, far easier than trying to retrofit tests to existing code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top