无法在 Django 测试中加载固定装置数据
我有一个名为 pta.apps.users 的应用程序,它加载在我的 settings.py 的“已加载应用程序”设置中。
该应用程序工作正常,我现在想测试它,并将 json 文件放置在我的用户应用程序内的装置目录中。
我有一个运行良好的测试,但装置无法加载。
from django.test import TestCase
from django.test.client import Client
from BeautifulSoup import BeautifulSoup
class SimpleTest(TestCase):
fixtures = ['user.json']
def setUp(self):
self.c = Client()
def test_parse_html(self):
response = self.c.get('/users/login/', follow=True)
soup = BeautifulSoup(response.content)
self.assertEquals(soup.h1.renderContents(), 'Entrance')
我只是在输出中得到 No Fixtures found.
。我正在使用 Django 1.2.1。任何帮助将不胜感激。
I have an app called pta.apps.users which is loaded in the Loaded apps setting in my settings.py.
The app works fine, I now want to test it and have placed json files in the fixtures directory inside my users app.
I have a test which runs fine but the fixtures wont load.
from django.test import TestCase
from django.test.client import Client
from BeautifulSoup import BeautifulSoup
class SimpleTest(TestCase):
fixtures = ['user.json']
def setUp(self):
self.c = Client()
def test_parse_html(self):
response = self.c.get('/users/login/', follow=True)
soup = BeautifulSoup(response.content)
self.assertEquals(soup.h1.renderContents(), 'Entrance')
I just get No fixtures found.
in my output. I am using Django 1.2.1. Any help would be appreciatted.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你把你的灯具放在哪里?
灯具应放置在您的应用程序目录中:
或者您必须在 settings.py 中指定外部灯具目录:
where did you placed your fixtures?
The fixtures should placed in your app directory:
Or you hav to specify a external fixtures directory in your settings.py:
要加载夹具,我很确定您必须使用
loaddata
手动调用它(就像您所做的那样),或者专门调用它“initial_data”,例如initial_data.sql
、initial_data.json
、initial_data.yaml
等,并将其存储在应用程序的fixtures目录中。https://docs.djangoproject。 com/en/dev/howto/initial-data/#automatically-loading-initial-data-fixtures
To load a fixture, I'm pretty sure you have to either call it manually with
loaddata
(like you did), or call it specifically "initial_data," e.g.initial_data.sql
,initial_data.json
,initial_data.yaml
, etc., and store it in the fixtures directory of your app.https://docs.djangoproject.com/en/dev/howto/initial-data/#automatically-loading-initial-data-fixtures