いくつかの単体テストを作成しようとしており、この目的のためにいくつかのダミー オブジェクトを作成しています。speaker
私は部分的にこのように見えるモデルを持っています:
class speaker(models.Model):
name = models.CharField(max_length=255)
email = models.CharField(max_length=255, primary_key=True)
...
talk
部分的に次のように見えるクラス:
class talk(models.Model):
title = models.CharField(max_length = 255)
...
speakers = models.ManyToManyField('speaker')
...
私のテスト設定は次のようになります。
class TalkTest(TestCase):
def setUp(self):
speaker.objects.create(
name = "John Smith",
email = "john@john.com"
)
talk.objects.create(
title = "Writing unit tests",
summary = "How to write unit tests",
speakers = "john@john.com"
)
def test_talk_URLs(self):
testSpeak = speaker.objects.get(name="John Smith")
testTalk = talk.objects.get(title="Writing unit tests")
self.assertEqual(testSpeak.email, "john@john.com")
ただし、次のトレースバックエラーが発生します
======================================================================
ERROR: test_talk_URLs (core.tests.TalkTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/rony/Documents/rehab-lightning-talks/core/tests.py", line 43, in setUp
speakers = "1"
File "/home/rony/Documents/rehab-lightning-talks/venv/local/lib/python2.7/site-packages/django/db/models/manager.py", line 149, in create
return self.get_query_set().create(**kwargs)
File "/home/rony/Documents/rehab-lightning-talks/venv/local/lib/python2.7/site-packages/django/db/models/query.py", line 414, in create
obj = self.model(**kwargs)
File "/home/rony/Documents/rehab-lightning-talks/venv/local/lib/python2.7/site-packages/django/db/models/base.py", line 415, in __init__
raise TypeError("'%s' is an invalid keyword argument for this function" % list(kwargs)[0])
TypeError: 'speakers' is an invalid keyword argument for this function
----------------------------------------------------------------------
外部キーを正しく参照していませんか?