问题描述
我已经为我正在开发的Django项目编写测试,但是一个特定的灯具无法加载。夹具是使用dumpdata生成的,我根本就没有装满它。
我可以使用manage.py在该夹具上加载数据,而不会出现错误。我已经验证了使用shell实际加载的数据并查询数据。
这是驱动我坚果,任何帮助将不胜感激。
这是我的测试文件(删除不相关的部分):
class ViewsFromUrls(TestCase):
fixtures = [
'centers / fixtures / test_data.json',
'intranet /fixtures/test_data.json',
'training / fixtures / test_data.json',#无法加载
]
def setUp(self):
self.c = Client()
self.c.login(username ='USER',password ='PASS')
...
def test_ViewBatch(self):
b = Batch.objects.all()[0] .ticket_number
response = self.c.get(reverse('training.views.view_batch',kwargs = {'id ':b}))
self.assertTrue(response.status_code,200)
...
我不知道这是否解决了您的问题,但在本网站上:
我发现了一个有趣的话:
应用此(将appname重命名为文件名中的前缀)解决了我的问题我有同样的问题,如这里所述)
I have written tests for a Django project that i am working on, but one particular fixture fails to load.The fixture is generated using dumpdata and i havent fiddled with it at all.I can load the data using manage.py on that fixture without errors. I have verified that the data actually loaded using shell and querying the data.This is driving me nuts, any help would be much appreciated.
Here is my test file (irrelevant portions removed):
class ViewsFromUrls(TestCase):
fixtures = [
'centers/fixtures/test_data.json',
'intranet/fixtures/test_data.json',
'training/fixtures/test_data.json', #The one that fails to load
]
def setUp(self):
self.c = Client()
self.c.login(username='USER', password='PASS')
...
def test_ViewBatch(self):
b = Batch.objects.all()[0].ticket_number
response = self.c.get(reverse('training.views.view_batch', kwargs={'id':b}))
self.assertTrue(response.status_code, 200)
...
I Am not sure if this fixes your problem, but on this site:
https://code.djangoproject.com/wiki/Fixtures
I found an interesting remark:
Applying this (renaming the fixtures with appname as prefix in the filename), solved my problem (I had the same issue as described here)
这篇关于Django测试没有加载灯具数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!