import unittest
from utils.SignUtils import sign
from utils.request import HttpRequest
from configgg.conf import test_env,host
from utils.ResultUtil import get_value_by_json
class StuInfoApi(unittest.TestCase):
path=host.get(test_env)
# 封装出来一个api
def stu_info(self, data, headers=None):
uri = "/api/user/stu_info"
headers=headers
req = HttpRequest(url=self.path + uri, headers=headers, data=data)
return req.get()
class TestManyCase(unittest.TestCase):
def test_two_api(self):
#多个api调用
#自己进行实例化
stuInfo=StuInfoApi()
teacherInfo=TeacherInfoApi()
class TeacherInfoApi(unittest.TestCase):
pass
#继承,然后直接使用
class TestStuInfoCase(StuInfoApi):
def test_user_sys(self):
data = {"name": "小黑"}
result=self.stu_info(data)
# self.assertEqual(get_value_by_json(result,"name"), get_value_by_json(data,"name"))
self.assertEqual(get_value_by_json(result,"status"),300)
def test_user_not_in_sys(self):
data = {"name": "小黑"}
result=self.stu_info(data)
self.assertEqual(get_value_by_json(result,"status"),300)
def test_user_sys(self):
#如何去判断多环境 prod test
uri="/api/user/stu_info"
data = {"name": "小黑"}
result = self.stu_info(data)
headers={"token":sign()}
# data={"name":"小黑"}
self.assertEqual(get_value_by_json(result,"name"), get_value_by_json(data,"name"))
unittest.main()
# import unittest
# from utils.SignUtils import sign
# from utils.request import HttpRequest
# from configgg.conf import test_env,host
# from utils.ResultUtil import get_value_by_json
# from configgg.conf import log
#
#
# class StuInfoApi(unittest.TestCase):
# path = host.get(test_env)
#
# # 封装出来一个api
# def stu_info(self, data, headers=None):
# uri = "/api/user/stu_info"
# req = HttpRequest(url=self.path + uri, headers=headers, data=data)
# return req.get()
#
# def check_stu_info(self, data, check_value):
# new = data.get('')
# self.assertEqual(new, check_value)
#
#
# class TeacherInfoApi(unittest.TestCase):
# pass
#
#
# class TestManyCase(unittest.TestCase):
#
# # 多个api调用
# def test_two_api(self):
# stuInfo = StuInfoApi()
# teacherInfo = TeacherInfoApi()
# data = {"name": "小黑"}
# headers = {"token": sign()}
# stu_result = stuInfo.stu_info(data, headers)
# log.info("检查小黑是否在系统中,token是:%s" % headers)
# self.assertEqual(get_value_by_json(stu_result, "status"), 0)
# self.assertEqual(get_value_by_json(stu_result, "name"), get_value_by_json(data, "name"))
#
#
# class TestStuInfoCase(StuInfoApi):
#
# def test_user_in_sys(self):
# # 如何去判断多环境
# # prod 、 test
# data = {"name": "小黑"}
# headers = {"token": sign()}
# result = self.stu_info(data, headers)
# log.info("检查小黑是否在系统中,token是:%s" % headers)
#
# self.assertEqual(get_value_by_json(result, "status"), 0)
# self.assertEqual(get_value_by_json(result, "name"), get_value_by_json(data, "name"))
#
# def test_user_not_in_sys(self):
# # 如何去判断多环境
# # prod 、 test
#
# data = {"name": "小黑1"}
# headers = {"token": sign()}
#
# result = self.stu_info(data, headers)
# log.info("检查小黑是否在系统中,token是:%s" % headers)
# self.assertEqual(get_value_by_json(result, "status"), 300)
# self.assertNotEqual(get_value_by_json(result, "name"), get_value_by_json(data, "name"))
#
# unittest.main()
输出结果
老师的优化: