【发布时间】:2016-05-10 15:50:01
【问题描述】:
我刚开始使用 Django,我真的很想养成测试所有我应该做的事情的习惯。我现在的大多数类都是基于类的通用视图,例如列表视图。这是一个这样的:
class CellView(ListView):
"""
Class that determines list view for all Cells
Inherits from Django GenericView ListView Class
Attributes:
model: Overrided attribute that indicates that
cell is the model to be displayed
template_name: Overrided attribute that indicates
which html template to use
queryset: Overrided attribute that indicates a python
queryset of all cell objects to be displated
context_object_name: Overrided attribute that indicates
string to name the context object in the template
"""
model = Cell
template_name = "CellView.html"
query_set = Cell.objects.all()
context_object_name = "Cells"
我没有任何自定义方法,我在这里所做的只是定义属性。我应该在这里测试这段代码吗?或者这一切真的算作 Django 处理的事情,我应该相信它会起作用吗?如果我应该测试它,我应该具体测试什么?
【问题讨论】:
标签: python django django-class-based-views django-testing