测试受密码保护的页面django



我想编写关于密码保护页面的测试用例。我有/管理/编辑页面。这是需要登录的页面。我的测试用例目前喜欢下面,但它失败了。我期望得到200,但我没有得到重定向(302(Tests.py来自django.test导入TestCase,客户端

# Admin panel Test cases

class PageTest(TestCase):
# it will redirect user to loginpage
def test_admin_page(self):
response = self.client.get("/management/")
self.assertEquals(response.status_code, 302)
def test_edit(self):
c = Client()
c.login(username='admin', password='admin')
response = c.get("/management/edit/")
self.assertEquals(response.status_code,200)

我用force_login替换了登录

c = self.client
testuser = User.objects.create_user(username='useresu', password='666pass')
c.force_login(testuser)

最新更新