0

何が間違っているのかわかりません。私はこの例に従おうとしています: https://docs.djangoproject.com/en/1.6/topics/testing/advanced/#module-django.test.client

テストを作成しましたが、戻り値が奇妙です。

tests.py:

from django.contrib.auth.models import User
from django.test import TestCase
from django.test.client import RequestFactory
from project_name.app_name.views import ViewName

class UrlsViewsTest(TestCase):
    def setUp(self):
        # every test needs access to the request RequestFactory
        self.factory = RequestFactory()
        self.user = User.objects.create_user(username='dave', email='dave@mail.com', password='top_secret')

    def tearDown(self):
        # Delete those objects that are saved in setup
        self.user.delete()

    def test_view_name(self):
        #Create an instance of a GET request
        request = self.factory.get('/app/')

        # Recall that middleware are not suported. You can simulate a
        # logged-in user by setting request.user manually.
        request.user = self.user

        # Test ViewName() as if it were deployed at /app/
        response = ViewName(request)
        self.assertEqual(response.status_code, 200)

結果:

Creating test database for alias 'default'...
E
======================================================================
ERROR: test_view_name (project_name.app_name.tests.UrlsViewsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/dave/sandbox/project_name/project_name/app_name/tests.py", line 25, in test_view_name
    response = ViewName(request)
TypeError: __init__() takes exactly 1 argument (2 given)

----------------------------------------------------------------------
Ran 1 test in 0.168s

FAILED (errors=1)
Destroying test database for alias 'default'...

次の意味がわかりません。

TypeError: __init__() takes exactly 1 argument (2 given)

それが何を意味するのかをどのように整理し、どのように修正するのですか?

私は Django Google Groups とここで SO を見てきました。例は見ていません。

4

1 に答える 1