def test_user_sign_eid_phone_error(self): # 手机号与发布会不匹配 payload = {'eid': '1', 'phone': 13511001102} r = requests.post(self.base_url, data=payload) self.result = r.json() self.assertEqual(self.result['status'], 10026) self.assertEqual(self.result['message'], 'user did not participate in the conference') def test_user_sign_has_sign_in(self): # 已签到 payload = {'eid': '1', 'phone': 13511001101} r = requests.post(self.base_url, data=payload) self.result = r.json() self.assertEqual(self.result['status'], 10027) self.assertEqual(self.result['message'], 'user has sign in') def test_user_sign_success(self): # 签到成功 payload = {'eid': '1', 'phone': 13511001100} r = requests.post(self.base_url, data=payload) self.result = r.json() self.assertEqual(self.result['status'], 200) self.assertEqual(self.result['message'], 'sign success') if __name__ == '__main__': test_data.init_data() # 初始化接口测试数据 unittest.main()
# @unittest.skip('无条件的跳过这条用例') def test_add_event_name_exists(self): '''name已经存在''' r = requests.post(self.url,data={'eid': 106, 'name': '红米Pro发布会', 'guest_limit': 20000, 'address': '北京小米基地1', 'status': 0, 'start_time': '2021-11-11 20:00:00', 'create_time': '2021-01-01 20:00:00'}) self.result = r.json() self.assertEqual(self.result['status'],10023) self.assertEqual(self.result['message'],'event name already exists') # @unittest.skip('无条件的跳过这条用例') def test_add_event_time_error(self): '''时间格式不对''' r = requests.post(self.url,data={'eid': 107, 'name': '云之家发布会', 'guest_limit': 20000, 'address': '金蝶软家园', 'status': 0, 'start_time': '2021:11:11 20:00:00', 'create_time': '2021-01-01 20:00:00'}) self.result = r.json() self.assertEqual(self.result['status'],10024) self.assertEqual(self.result['message'],'error') # @unittest.skip('无条件的跳过这条用例') def test_add_event_success(self): '''发布会添加成功''' r = requests.post(self.url,data={'eid': 108, 'name': '红米Note发布会', 'guest_limit': 20000, 'address': '北京小米基地1', 'status': 0, 'start_time': '2021-11-11 20:00:00', 'create_time': '2021-01-01 20:00:00'}) self.result = r.json() self.assertEqual(self.result['status'],200) self.assertEqual(self.result['message'],'add event success') if __name__ == '__main__': test_data.init_data() unittest.main()
import sys import time import unittest sys.path.append('./interface') sys.path.append('./db_fixture') from pyrequest.HTMLTestRunner import HTMLTestRunner # from unittest import defaultTestLoader from pyrequest.db_fixture import test_data # 指定测试用例为当前文件夹下的 interface 目录 test_dir = './interface' discover = unittest.defaultTestLoader.discover(test_dir, pattern='*_test.py') if __name__ == '__main__': test_data.init_data() # 初始化接口数据 now = time.strftime("%Y-%m-%d %H_%M_%S") filename = './report/' + now + '_result.html' fp = open(filename, 'wb') runner = HTMLTestRunner(stream=fp, title='Guest Manage System Interface Test Report', description='Implementation Example with:') runner.run(discover) fp.close()