import unittest,requests
from AddStu.help_method import *
from AddStu.database import *
class TestAddStu(unittest.TestCase):
test_status = 'smoke_test1'
# 类执行前,设置类的初始化条件
@classmethod
def setUpClass(cls):
# 连接sqlite数据库,创建游标
cls.conn, cls.cur = create_conn_and_cur('C:\\Users\Administrator\Documents\\Navicat\MySQL\servers\mysite\mysite.sql')
# 类执行后,销毁类的初始化环境
@classmethod
def tearDownClass(cls):
# 关闭连接和游标
close_conn_and_cur(cls.conn, cls.cur)
# 测试用例执行前,设置初始化条件
def setUp(self):
# 先创建一个session对象
self.se = requests.Session()
# 添加登录信息
self.data = login('hzdltest', 'hzdltest')
# 创建学生数据
self.data1 = create_random_stu()
# print(self.data1)
# 测试用例执行后,销毁环境
def tearDown(self):
# 删除数据库里,stu_id>18的数据
# execute_other(self.conn,self.cur,'delete from hello_student where stu_id > 18;')
# 关闭session对象
self.se.close()
#添加成功
def test_add_stu_success_2000(self):
# 登录接口
self.se.post('http://127.0.0.1:8000/stu/loginsys/', data=self.data)
r1 = self.se.post('http://127.0.0.1:8000/stu/addstu/', data=self.data1)
# # 断言响应状态码和业务状态码
assert_code(r1, 200, 2000)
@unittest.skipIf(test_status == 'smoke_test', '通过性验证不必测!')
#添加失败
def test_add_stu_failed_2001(self):
self.se.post('http://127.0.0.1:8000/stu/loginsys/', data=self.data)
self.data1['stu_name'] = None
r1 = self.se.post('http://127.0.0.1:8000/stu/addstu/', data=self.data1)
# # 断言响应状态码和业务状态码
assert_code(r1, 200, 2001)
@unittest.skipIf(test_status == 'smoke_test', '通过性验证不必测!')
def test_add_stu_failed_2002(self):
self.se.post('http://127.0.0.1:8000/stu/loginsys/', data=self.data)
data1 = {'stu_name': '张三2369', 'stu_class': '8班', 'stu_sex': '男', 'stu_phone': '13359602337','stu_email': '13359602337@qq.com'}
r1 = self.se.post('http://127.0.0.1:8000/stu/addstu/', data=data1)
# print(r1.json())
# # 断言响应状态码和业务状态码
assert_code(r1, 200, 2002)
@unittest.skipIf(test_status == 'smoke_test', '通过性验证不必测!')
def test_add_stu_failed_2003(self):
self.se.post('http://127.0.0.1:8000/stu/loginsys/', data=self.data)
data1 = { 'stu_class': '8班', 'stu_sex': '男', 'stu_phone': '13359602337','stu_email': '13359602337@qq.com'}
r1=self.se.post('http://127.0.0.1:8000/stu/addstu/', data=data1)
# print(r1.json())
# # 断言响应状态码和业务状态码
assert_code(r1, 200, 2003)
if __name__ == '__main__':
TestAddStu()
TestAddStu
最新推荐文章于 2024-08-23 16:53:34 发布