我刚开始用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处理的事情,我应该相信它会起作用吗?如果我应该测试它,我应该测试什么?在
我认为这仍然值得测试,但可能是在功能测试的级别。也就是说,在测试中创建一些数据,然后使用测试客户机请求相关页面并断言它包含您期望的文本。在
相关问题 更多 >
编程相关推荐