def test_get_token_null_service(self): ex_service = '' ex_data = { 'username': username, 'password': password, 'loginMode': loginMode, 'service': ex_service } response = ApiRequest.ApiTest('POST', url, ex_data) self.assertIn('error', response.apicall()[1])
def test_get_token_ex_passwd(self): ex_password = password + 'exception' ex_data = { 'username': username, 'password': ex_password, 'loginMode': loginMode, 'service': service } response = ApiRequest.ApiTest('POST', url, ex_data) self.assertIn('error', response.apicall()[1]) '''password为空情况'''
def test_get_token_ex_loginMode(self): ex_loginMode = random.randint(0, 100) ex_data = { 'username': username, 'password': password, 'loginMode': ex_loginMode, 'service': service } response = ApiRequest.ApiTest('POST', url, ex_data) self.assertIn('error', response.apicall()[1]) '''loginMode为空情况'''
class APIGetAdList(unittest.TestCase): def setUp(self): log.getInfo('初始化测试数据') def test_circle(self): log.getInfo('开始执行测试') for i in range(1, row): try: URL = str(excel.get_content(XLS, index, i, url))[6:].replace("'", "") METHOD = str( str(excel.get_content(XLS, index, i, method))[6:].replace("'", "")) DATA = str(excel.get_content(XLS, index, i, data))[7:-1] '''加入标签,便于定位传参''' TAG = str(excel.get_content(XLS, index, i, tag)) except IOError, e: log.getErrorInfo('NO SUCH DIRECTORY' + e) except BaseException, e: log.getErrorInfo(e) '''获取组织结构列表get_orglist''' if 'get_orglist' in TAG: URL_RE = URL.replace('{access_token}', BaseParam.AscToken().get_acstoken()) try: response = ApiRequest.ApiTest(METHOD, URL_RE, eval(DATA)) except BaseException, e: log.getErrorInfo(e) try: style = xlwt.easyxf( 'font:height 240, color-index red, bold on;align: wrap on, vert centre, horiz center' ) '''写入状态返回码''' excel.input_content(XLS, index, i, status_code, response.apicall()[0], style) '''补充增加实际返回结果,解决字符编码问题''' excel.input_content(XLS, index, i, result, response.apicall()[1].decode('utf-8'), style) except IOError, e: log.getErrorInfo('NO SUCH DIRECTORY')
def test_get_token_ex_url(self): ex_url = url + 'exception' response = ApiRequest.ApiTest('POST', ex_url, data) self.assertIn('error', response.apicall()[1]) '''username异常情况'''
def test_get_token(self): response = ApiRequest.ApiTest('POST', url, data) self.assertIn('success', response.apicall()[1]) '''url异常情况'''
excel.input_content(XLS, index, i, result, response.apicall()[1].decode('utf-8'), style) except IOError, e: log.getErrorInfo('NO SUCH DIRECTORY') except BaseException, e: log.getErrorInfo(e) '''获取组织结构列表异常情况get_orglist_exception''' elif 'get_orglist_exception' in TAG: pass '''刷新用户token:ssotoken_refresh''' elif 'ssotoken_refresh' in TAG: URL_RE = URL.replace('{token}', BaseParam.User_Token().get_token()) try: response = ApiRequest.ApiTest(METHOD, URL_RE, eval(DATA)) except BaseException, e: log.getErrorInfo(e) try: style = xlwt.easyxf( 'font:height 240, color-index red, bold on;align: wrap on, vert centre, horiz center' ) '''写入状态返回码''' excel.input_content(XLS, index, i, status_code, response.apicall()[0], style) '''补充增加实际返回结果,解决字符编码问题''' excel.input_content(XLS, index, i, result, response.apicall()[1].decode('utf-8'), style) except IOError, e: log.getErrorInfo('NO SUCH DIRECTORY')
import time cfgfile = '/Users/fanglujie/Documents/Project/Api_Test/config.ini' username = excuteCFG.ConfigRead(cfgfile, 'GET_TOKEN', 'username').CfgRead() url = excuteCFG.ConfigRead(cfgfile, 'GET_ACCESS_TOKEN', 'url').CfgRead() password = excuteCFG.ConfigRead(cfgfile, 'GET_TOKEN', 'password').CfgRead() loginMode = excuteCFG.ConfigRead(cfgfile, 'GET_TOKEN', 'loginMode').CfgRead() service = excuteCFG.ConfigRead(cfgfile, 'GET_TOKEN', 'service').CfgRead() content_type = excuteCFG.ConfigRead(cfgfile, 'GET_TOKEN', 'content-type').CfgRead() client_ip = excuteCFG.ConfigRead(cfgfile, 'GET_TOKEN', 'client_ip ').CfgRead() client_id = excuteCFG.ConfigRead(cfgfile, 'GET_ACCESS_TOKEN', 'client_id').CfgRead() client_secret = excuteCFG.ConfigRead(cfgfile, 'GET_ACCESS_TOKEN', 'client_secret').CfgRead() grant_type = excuteCFG.ConfigRead(cfgfile, 'GET_ACCESS_TOKEN', 'grant_type').CfgRead() data = { 'client_id': client_id, 'client_secret': client_secret, 'grant_type': grant_type } print client_id print client_secret print grant_type print url response = ApiRequest.ApiTest('POST', url, data) print response.apicall()[1]