0

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) 
2
  • 3
    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 TestMountPoint Commented Nov 3, 2015 at 6:22
  • by the way, DEFAULT_BACKEND = 'filesystem.backend.HDWrapper.DirectionHDWrapper,filesystem.backend.HDWrapper.DocumentHDWrapper' Commented Nov 3, 2015 at 6:23

2 Answers 2

1

I think you must use keyword args:

return MountPoint(name=name, backend=backend, path=path) 
Sign up to request clarification or add additional context in comments.

Comments

0

MountPoint is a model? or a TestCase? define the model import with as, you are creating a instance of your test case. Example:

from .models import MountPoint as MountPointModel 

Or rename u'r test case:

class MountPointTest(TestCase) ... 

1 Comment

This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.