import hashlib from django.test import TestCase from .models import User from django.test import Client # Create your tests here. class simpleCase(TestCase): ????# 测试之前 ????def setUp(self): ????????# 测试模型 ????????sha256 = hashlib.sha256() ????????sha256.update('12345678'.encode('utf-8')) ????????comparePwd = sha256.hexdigest() ????????User.objects.create(username='lili',password=comparePwd,email='270108125@qq.com',is_active=False) ????????self.client = Client() ????def test_model_add(self): ????????user = User.objects.get(username='lili') ????????self.assertIsNot(user,None) ????def test_get_login(self): ????????response = self.client.get('/login/') ????????self.assertEqual(response.status_code,200) ????def test_post_login_1(self): ????????self.client.post('/login/', {'user_name': 'lili', 'pwd': '12345678'}) ????????sess = self.client.session.get('is_login', None) ????????self.assertEqual(sess, 1) ????def test_post_login_2(self): ????????self.client.post('/login/', {'user_name': 'yuanyuan1', 'pwd': '12345678'}) ????????sess = self.client.session.get('is_login', None) ????????self.assertEqual(sess, None) |