今天我在学习用Django编写测试用例,并编写了一个用于检查有效用户身份验证的测试用例。
from django.test import TestCase
from django.http import HttpRequest
from aptly_dash.views import newRepo, homePage
from selenium import webdriver
from django.test import Client
class MyTestCase(TestCase):
def setUp(self):
self.client = Client()
self.browser = webdriver.Firefox()
#
def tearDown(self):
self.browser.quit()
def test_redirect(self):
response = self.client.get('/admin/')
self.assertRedirects(response, '/admin/login/?next=/admin/')
def test_login(self):
# Issue a GET request.
response = self.client.login(username='rakesh', password='ranjan')
print response
我已经创建了一个username='rakesh',password='ranjan'但response即将推出 be False。我对编写测试用例相当陌生,如果有人能告诉我我的test_login功能出了什么问题,我将不胜感激。我还想编写一个测试用例来检查 django URL 是否 403 禁止未经身份验证的用户,以及 403 禁止经过身份验证但不是员工用户。谁能给我一个好的文档。