【问题标题】:How to write a Test in django如何在 django 中编写测试
【发布时间】:2013-11-14 08:45:14
【问题描述】:

我在下面给出了我的观点和模型,我需要为以下内容编写测试用例 这是我的看法:

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),)

我的模型.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 的新手
测试。请帮助

【问题讨论】:

    标签: django django-testing django-tests


    【解决方案1】:

    一开始这对我帮助很大:

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

    通过不同的方法为您的模型测试和安装固定装置。

    将来你真的应该首先考虑编写测试,如果你没有这样工作,这似乎违反直觉,但实际上比尝试对现有代码进行改进测试要容易得多。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-20
      • 2010-10-02
      • 1970-01-01
      • 2011-11-10
      • 1970-01-01
      • 2018-05-10
      相关资源
      最近更新 更多