2015-11-03 82 views
1

我有嘗試運行的Django 的考驗,這是我的模型文件類型錯誤:__init __()採用最多2個參數(給出4)

class MountPoint(models.Model): 
     name = models.CharField(max_length=100) 
     backend = models.CharField(max_length=200,default=DEFAULT_BACKEND) 
     path = models.CharField(max_length=300) 

     def __unicode__(self): 
      return self.name 

代碼和這裏的時候錯誤消息是類我投入測試

class MountPoint(TestCase): 
     def create_mountpoint(self): 
      name = "test" 
      backend = "test" 
      path = user_root 
      return MountPoint(name, backend, path) 

     def test_mountpoint_creation(self): 
      m = self.create_mountpoint() 
      self.assertTrue(isinstance(m, MountPoint)) 
      self.assertEqual(m.__unicode(), m.name) 

和我得到的錯誤消息是在下面。它說我有比預期更多的投入。

回溯(最近通話最後一個): 文件 「/Users/xihui/Documents/WebProgramming/django/ece264site/filesystem/tests.py」 18行,在test_mountpoint_creation M = self.create_mountpoint() 文件「/Users/xihui/Documents/WebProgramming/django/ece264site/filesystem/tests.py」,第15行,在create_mountpoint中 返回MountPoint(名稱,後端,路徑) TypeError:init()至多需要2個參數4給定)


冉1測試0.009s

失敗(錯誤= 1)

+3

測試類的名稱陰影模型類的名稱,所以當您嘗試實例化一個模型實際上,它試圖創建一個測試類的新實例,顯然它採用了不同的參數。順便說一句,您的測試類重命名爲'TestMountPoint' – andrean

+0

,DEFAULT_BACKEND ='filesystem.backend.HDWrapper.DirectionHDWrapper,filesystem.backend.HDWrapper.DocumentHDWrapper' –

回答

1

我認爲你必須使用關鍵字ARGS:

return MountPoint(name=name, backend=backend, path=path) 
相關問題