1
votes

i got error message when trying to run the test of django this is my code for the model file

   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

and here is the class i put in test

  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)

and the error message i got is below. it said i have more inputs than expected.

Traceback (most recent call last): File "/Users/xihui/Documents/WebProgramming/django/ece264site/filesystem/tests.py", line 18, in test_mountpoint_creation m = self.create_mountpoint() File "/Users/xihui/Documents/WebProgramming/django/ece264site/filesystem/tests.py", line 15, in create_mountpoint return MountPoint(name, backend, path) TypeError: init() takes at most 2 arguments (4 given)


Ran 1 test in 0.009s

FAILED (errors=1)

1
The name of the test class shadows the name of your model class, so when you try to instantiate a model instance, it actually tries to create a new instance of the test class, which takes different args obviously. Rename your test class to TestMountPointandrean
by the way, DEFAULT_BACKEND = 'filesystem.backend.HDWrapper.DirectionHDWrapper,filesystem.backend.HDWrapper.DocumentHDWrapper'Nicholas Wang

1 Answers

1
votes

I think you must use keyword args:

return MountPoint(name=name, backend=backend, path=path)