【发布时间】:2021-04-15 11:01:22
【问题描述】:
测试用例 setUp() 首先创建一个用户并尝试强制对用户进行身份验证,但发生有线错误...
TypeError:force_authenticate() 缺少 1 个必需的位置参数:'self'
class PrivateUserApiTest(TestCase):
""" Test API that require authentication """
def setUp(self):
self.user = create_user(
email="test@test.com",
password="testpass",
name="testName"
)
print(self.user)
self.client = APIClient
self.client.force_authenticate(user=self.user) # <--
【问题讨论】:
-
应该有self.client=APIClient()
-
先检查你的force_authenticate方法是否有第一个参数self,如:
def force_authenticate(self, user, other, arguments):。
标签: python django django-models django-rest-framework tdd