我想测试我的基于类的视图。
这是models.py文件:
class TodoList(models.Model):
todoitem = models.CharField(max_length=200)
description = models.TextField()
pub_date = models.DateField(auto_now_add=True)
这是我的views.py文件
class ListTodoView(ListView):
model = TodoList
template_name = 'todolist_listview.html'
这是我的单元测试:
class TestToDoListView(TestCase):
def test_list_view(self):
url = reverse('notes-list')
resp = self.client.get(url)
self.assertEquals(resp.status_code, 200)
data = json.loads(resp.content) # getting error here No JSON object could be decoded
self.assertEquals(len(data), 1)
我在做什么错误?我已经确定,我已经把所有的进口货都放好了。
这是堆栈跟踪:
======================================================================
ERROR: test_list_view
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/.../tests/test_views.py", line 21, in test_list_view
data = json.loads(resp.content)
File "/usr/lib/python2.7/json/__init__.py", line 326, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 384, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded