目录如下:
这里有使用
HTMLTestRunner和 echarts.common.min.js文件[见百度网盘,这里给自己留个记录便于查询]
unit_test.py代码如下:
import unittest
import requests
import time
import os.path
from common import HTMLTestRunner
class TestLogin(unittest.TestCase):
def setUp(self):
# 获取session对象
self.session = requests.session()
# 登录url
self.url = 'http://XXXXXX/oauth/oauth/token'
def test_login_success(self):
data = {
'grant_type': 'password',
'username': 'iu',
'password': '111',
'client_id': 'web',
'client_secret': 'web-secret'
}
r = self.session.post(url=self.url, data=data)
try:
self.assertEqual(r.json()['token_type'])
except AssertionError as e:
print(e)
def test_username_not_exit(self):
data = {
'grant_type': 'password',
'username': '322u',
'password': '8',
'client_id': 'web',
'client_secret': 'web-secret'
}
r = self.session.post(url=self.url, data=data)
try:
self.assertEqual("用户名或密码错误", r.json()["error_description"])
except AssertionError as e:
print(e)
def test_password_error(self):
data = {
'grant_type': 'password',
'username': '2u',
'password': '888ssss888',
'client_id': 'web',
'client_secret': 'web-secret'
}
r = self.session.post(url=self.url, data=data)
try:
self.assertEqual("用户名或密码错误", r.json()["error_description"])
except AssertionError as e:
print(e)
def tearDown(self):
self.session.close()
if __name__ == '__main__':
# unittest.main()
test = unittest.TestSuite()
test.addTest(TestLogin('test_login_success'))
test.addTest(TestLogin('test_username_not_exit'))
test.addTest(TestLogin('test_password_error'))
rq = time.strftime('%Y%m%d%H%M', time.localtime(time.time()))
file_path = os.path.abspath('.') + '\\report\\' + rq + '-result.html'
file_result = open(file_path, 'wb')
runner = HTMLTestRunner.HTMLTestRunner(stream=file_result, title=u'测试报告', description=u'用例执行情况')
runner.run(test)
file_result.close()
运行产生报告查看报告:
您可能感兴趣的文章:Python中__repr__和__str__区别详解Python 基础教程之str和repr的详解python使用str & repr转换字符串详解Python中__str__和__repr__方法的区别python str与repr的区别Python StringIO如何在内存中读写strpython 实现list或string按指定分段Python3 使用map()批量的转换数据类型,如str转float的实现详细整理python 字符串(str)与列表(list)以及数组(array)之间的转换方法通过实例了解Python str()和repr()的区别