フィクスチャをロードしていないように見える TestCase があります。
テスト データベースの構築中に次のエラーが表示されます。
No fixtures found.
.............................................Problem installing fixture '/Users/Bryan/work/CNPROG/forum/fixtures/forum_fixtures.json': Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/commands/loaddata.py", line 169, in handle
obj.save(using=using)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/serializers/base.py", line 165, in save
models.Model.save_base(self.object, using=using, raw=True)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/models/base.py", line 543, in save_base
created=(not record_exists), raw=raw)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/dispatch/dispatcher.py", line 162, in send
response = receiver(signal=self, sender=sender, **named)
File "/Users/Bryan/work/CNPROG/forum/models.py", line 656, in record_ask_event
activity = Activity(user=instance.author, active_at=instance.added_at, content_object=instance, activity_type=TYPE_ACTIVITY_ASK_QUESTION)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/models/fields/related.py", line 302, in __get__
rel_obj = QuerySet(self.field.rel.to).using(db).get(**params)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/models/query.py", line 341, in get
% self.model._meta.object_name)
DoesNotExist: User matching query does not exist.
class UserProfileTestCases(TestCase):
"""These are tests to verify that refactoring of UserProfile is correct"""
fixtures = ['forum_fixtures.json'] # apparently this needs to be in fixtures/ directory.
def setUp(self):
self.client = Client()
if self.client.login(username='DickCheney', password='test'):
print "client.login DickCheney successful";
else:
print "client.login FAILED"
何らかの理由でフィクスチャがロードされていません。
フィクスチャは次の場所にあります:
forum/fixtures/forum_fixtures.json
フィクスチャがロードされていない理由を出力するにはどうすればよいですか?
トレースバックは、ここで何かが起こっていることを示唆しています:
file "/Users/Bryan/work/CNPROG/forum/models.py", line 656, in record_ask_event
しかし、それがフィクスチャの読み込みに影響する理由は想像できません。コードを見てみると、post_save イベント経由で record_ask_events が呼び出されています。
うまく設定できたmanage.py loaddata forum_fixtures
ので、正しく設定できたと思います。