Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法使用django allauth中的单元测试登录_Python_Django_Unit Testing_Django Views_Django Allauth - Fatal编程技术网

Python 无法使用django allauth中的单元测试登录

Python 无法使用django allauth中的单元测试登录,python,django,unit-testing,django-views,django-allauth,Python,Django,Unit Testing,Django Views,Django Allauth,我试着用unittest这样测试我的观点 class TestClassroomView(TestCase): def test_classroom_view(self): auth_headers = {'HTTP_AUTHORIZATION': 'Basic ' + base64.b64encode('test@tst.com:test')} response = self.client.get('/classroom/3/', follow=True, **auth_he

我试着用unittest这样测试我的观点

class TestClassroomView(TestCase):

def test_classroom_view(self):
    auth_headers = {'HTTP_AUTHORIZATION': 'Basic ' + base64.b64encode('test@tst.com:test')}
    response = self.client.get('/classroom/3/', follow=True, **auth_headers)
    self.assertContains(response, 'Course progress')
    self.assertEqual(response.status_code, 200)
这是:

class TestClassroomView(TestCase):
 def test_classroom(self):
    self.client.login(username='test@tst.com', password='test')
    response = self.client.get('/classroom/3/', follow=True)
    self.assertEqual(response.status_code, 200)
    self.assertTemplateUsed(response, 'web/dashboard.html')
response.redirect\u chain
始终显示此信息

[('http://testserver/?next=/classroom/3/”,302)]

如果我只留下
status\u code
检查,然后测试通过,但实际上他们什么也不测试。 我正在使用django allauth身份验证系统 请帮我找出我做错了什么


另外,我如何在测试开始时加载装置?

这就是帮助我进行身份验证的原因

from django.contrib.auth import get_user_model 

class TestParent(TestCase):

  def setUp(self):
    username = 'testuser'
    password = 'testpass'
    User = get_user_model()
    user = User.objects.create_user(username, password=password)
    logged_in = self.client.login(username=username, password=password)
    self.assertTrue(logged_in)