Django 没有为以下测试加载夹具。
from django.test import TestCase
class DevViewsTests(TestCase):
fixtures = ['device/fixtures/test_device.json']
def setUp(self):
self.client = Client()
self.username = 'cws'
self.email = 'alain.sturzenegger@gmail.com'
self.password = 'cws123'
self.test_user = User.objects.create_user(self.username, self.email, self.password)
login = self.client.login(username=self.username, password=self.password)
self.assertEqual(login, True)
def test_device_list(self):
url = reverse('device-overview')
response = self.client.get(url)
logger.debug('GET[%s]:[%s]', url, response.status_code)
self.assertQuerysetEqual(response.context['device_list'], ['<device: Device Test 1>'])
这指向以下视图但从该视图我无法检索 device_list
def overview(request):
device_list = device.objects.all()
print "List of devices"
print device_list # getting blank list []
context = {'device_list': device_list}
return render(request, 'device/index.html', context)
我的 test_device.json 文件如下
[
{
"pk": 1,
"model": "device.device",
"fields": {
"owner": 1,
"phone": "+41765687755",
"name": "Device Test 1",
"access_code": "1234"
}
}
]
文件结构是
cws
--device
--fixtures
----test_device.json
知道我做错了什么吗?请提供建议..