我在下面给出了我的观点和模型,我需要为以下内容编写测试用例 这是我的观点:
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,)
我需要为这个函数编写测试用例,对django和django来说是个新人 testing.Please Help
答案 0 :(得分:0)
这对我起初很有帮助:
http://toastdriven.com/blog/2011/apr/10/guide-to-testing-in-django/
通过不同的方法为您模拟测试和安装灯具。
将来你应该首先考虑编写测试,如果你没有那样工作,这似乎是违反直觉的,但实际上,比试图将测试改进现有代码要容易得多。