我下面這個http://pythonhosted.org/Flask-MongoKit/作爲一個例子瓶MongoKit「合集」對象不是可調用
我只是試圖讓文件的實例編寫單元測試,但它不工作。下面是測試代碼:
import unittest
from tests import app, db, ctx
from word.models import Word
class ModelWordTestCase(unittest.TestCase):
def setUp(self):
pass
def test_model_word(self):
print db.Word
word = db.Word()
self.assertIsNotNone(word)
def tearDown(self):
pass
詞類
from flask.ext.mongokit import Document
from core import db
@db.register
class Word(Document):
__collection__ = 'words'
use_dot_notation = True
STATUS = {
"approved" : 1,
"pending" : 0,
"rejected" : -1,
}
structure = {
'lang': unicode,
'local': unicode,
'pronunciation' : unicode,
'meaning': unicode,
}
令人驚訝與print db.Word
結印時db.Word存在,但它不能被稱爲創建一個新的實例作爲完成我上面提到的教程。下面是測試的輸出:
Collection(Database(MongoClient('localhost', 27017), u'words_test'), u'Word')
E
======================================================================
ERROR: test_model_word (tests.model_tests.ModelWordTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "tests/model_tests.py", line 14, in test_model_word
word = db.Word()
File "/usr/local/lib/python2.7/dist-packages/mongokit/collection.py", line 64, in __call__
self.__name)
TypeError: 'Collection' object is not callable. If you meant to call the 'Word' method on a 'Database' object it is failing because no such method exists.
----------------------------------------------------------------------
Ran 1 test in 0.002s
FAILED (errors=1)
我怎樣才能解決這個問題,讓Word文檔的情況下,這樣我可以創建並保存記錄。
請編輯您的問題,包括代碼你在哪裏定義'Word'。 –
用代碼編輯了這個問題。現在檢查 – codefreak