def __init__(self, charset="utf-8"): self.host = Config().db self.user = Config().db_user self.password = Config().db_password self.port = int(Config().db_port) self.database = Config().db_name self.charset = charset
def __init__(self, user=None, pwd=None): self.S = requests.Session() self.host = Config().roadSide_host if user == None and pwd == None: self.user = Config().getValue("roadSide_user") self.password = Config().getValue("roadSide_pwd") else: self.user = user self.password = pwd
def __init__(self, zby_user=None, zby_pwd=None): self.S = requests.Session() self.host = Config().zby_host if zby_user == None and zby_pwd == None: self.user = Config().getValue("zby_user") self.password = Config().getValue("zby_pwd") else: self.user = zby_user self.password = zby_pwd
def __init__(self, user=None, pwd=None): self.conf = Config() self.host = self.conf.host self.Seesion = requests.Session() if user == None and pwd == None: self.user = Config().getValue("user") self.password = Config().getValue("password") else: self.user = user self.password = pwd
def test_payleave_account(self): """ 用例描述:付费离场(余额支付) """ A = ApiCase(carNum=Config().common_carNum) A.car_run_inside() P = ChargesPage() P.pay_charges(Config().common_carNum) result = P.submit_pay() assert result == True A.car_run_outside()
def test_payleave_weixin(self): """ 用例描述:付费离场(微信支付) """ A = ApiCase(carNum=Config().common_carNum) A.car_run_inside() self.P.pay_charges(Config().common_carNum) result = self.P.submit_pay(type="微信") assert result == True A.pay_charge() A.car_run_outside()
def test_lock_and_unlock(self): """ 用例描述:车辆锁定-解锁 """ A = ApiCase(carNum=Config().common_carNum) A.car_run_inside() P = ChargesPage() result = P.lock_car(Config().common_carNum) assert result == True P.unlock_car(Config().common_carNum) A.pay_charge() A.car_run_outside() P.web_refresh()
def test_001(self): ''' 参数信息 :return: ''' #实例化配置文件读取类、断言类、测试数据类 config = Config() data = Test() _assert = Assert.Assert() request = Requests.Request() #读取host,读取url,data,headers host = config.activity_front_host urls = data.url params = data.data allure.attach('用例参数:{0}'.format(params)) with allure.step("测试步骤调用"): allure.attach('失败', '期望结果') api_url = host + urls[0] response = request.post(url=api_url, data=params[0][0]) setattr(Reflex.Reflex_api, 'num', 1000) print(response['response_code']) assert _assert.assert_status(response['response_code'], 200)
class TestProcess(object): config = Config() noti = notify() log = Log.MyLog() data = Process() case_data = data.case_data test = Assert.Assertions() # ids = [ # " 测试:{} ==> 预期结果:状态码={} ". # format(case['test_name'], case['expected']) for case in case_data # ] @allure.feature('Home') @allure.severity('blocker') @allure.story('Process') @allure.issue(config.test04_unified_url) @allure.testcase(config.test04_unified_url) # @pytest.mark.flaky(reruns=3) # @pytest.mark.parametrize('case', case_data, ids=ids) @pytest.mark.parametrize('case', case_data) def test_process(self, case): TestProcess.test_process.__doc__ = case['test_name'] self.log.info('demo, utl={}, data={}, header={}'.format( case['url'], case['data'], case['header'])) # 判断请求方法 result = self.noti.notify_result(case['mode'], case['url'], case['data'], case['header']) self.log.info('响应结果:%s' % result) print(result) parser(result, case['parser'], case['expected']) # self.test.assert_in_text(result,case['expected']),True) allure.attach.file((BASE_PATH + '/Log/log.log'), '附件内容是: ' + '老王调试日志', '我是附件名', allure.attachment_type.TEXT) Consts.RESULT_LIST.append('True')
class TestBasic(object): log = Log.MyLog() data = Basic() case_data = data.case_data request = Request.Request() test = Assert.Assertions() config = Config() noti = notify() # ids = [ # "测试:{}". # format(case['test_name']) for case in case_data # ] @allure.feature('Home') @allure.severity('blocker') @allure.story('Basic') @allure.issue('https://baidu.com') @allure.testcase('https://baidu.com') @pytest.mark.flaky(reruns=3) # @pytest.mark.parametrize('case', case_data, ids=ids) @pytest.mark.parametrize('case', case_data) def test_login(self,case): """ 小程序登录 """ self.log.info('demo, utl={}, data={}, header={}'.format(case['url'], case['data'], case['header'])) if case['method'] == 'post_request_urlencoded': result = self.request.post_request_urlencoded(case['url'], case['data'], case['header']) # 写入配置文件 self.config.set_conf('parameter', 'token', result['data']['token']) assert self.test.assert_text(result['status'], 0) self.log.info('配置文件中token ={}'.format(self.config.get_conf('parameter', 'token'))) allure.attach.file(BASE_PATH+'/Log/log.log', '附件内容是: ' + '老王调试日志', '我是附件名', allure.attachment_type.TEXT) Consts.RESULT_LIST.append('True')
def test_getusermenu_01(self, action): """ 用例描述:systemId、terminalType正常 """ conf = Config() data = GetUserMenu() test = Assert.Assertions() request = Request.Request(action) host = conf.host_base req_url = 'http://' + host urls = data.url params = data.data headers = data.header he = { 'Content-Type': 'application/json;charset=UTF-8', 'token': "fbe62213-d9f6-4805-b239-1c232c5f2a9f" } api_url = req_url + urls[0] response = request.post_request(api_url, json.dumps(he), headers[0]) print(json.dumps(he)) assert test.assert_code(response['body']['code'], '1003') # assert test.assert_body(response['body'], 'description', '密码错误') # assert test.assert_time(response['time_consuming'], 200) Consts.RESULT_LIST.append('True')
def get_Graph(): """ 返回图 :return: 图 """ from Config.Config import Config config = Config('neo4j').getInfo() return Graph(config['url2'], auth=(config['name'], config['password']))
def __init__(self, Session=None): super(Req, self).__init__() self.conf = Config() self.host = self.conf.host if Session == None: self.Session = requests.Session() else: self.Session = Session
def __init__(self, user=None, pwd=None): self.S = requests.Session() self.C = Config() self.host = self.C.zby_host if user == None and pwd == None: self.user = self.C.zby_user self.password = self.C.zby_pwd else: self.user = user self.password = pwd
def __init__(self, user=None, pwd=None): self.conf = Config() self.host = self.conf.weiXin_host self.S = requests.session() if user == None and pwd == None: self.user = self.conf.weiXin_user self.password = self.conf.weiXin_pwd else: self.user = user self.password = pwd
def action(): # 定义环境 env = Consts.API_ENVIRONMENT_RELEASE # 定义报告中environment conf = Config() host = conf.host_release tester = conf.tester_release allure.environment(environment=env) allure.environment(hostname=host) allure.environment(tester=tester) return env
def test_setting_often_carNum(self): """ 用例描述:设置常用车牌 """ P = ChargesPage() carCode = P.create_carNum() P.binding_carCode(carCode) P.set_often_carNum(carCode) result = P.set_often_carNum(Config().common_carNum) P.del_carCode(carCode) assert result == True
def clone_fn(batch_queue): network_config = Config(weight_decay=FLAGS.weight_decay) images, labels = batch_queue.dequeue() logits, endpoints = network_fn(images, network_config) # loss = tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(labels=labels, logits=logits, name='loss')) loss = weighted_softmax_loss(logits, labels) # loss = dice_loss(logits, labels) slim.losses.add_loss(loss) endpoints['images'] = images endpoints['labels'] = labels return endpoints
def __init__(self, carNum=None): self.url = Config().vems_host self.carNum = carNum self.usernameToken = self.get_center_people_token() self.realTimeCarSeq = "" self.stopTime = "" self.basicFee = "" self.taxPay = "" self.chargingTime = "" self.enterTime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time() - 1800))
def __init__(self, Session=None): # super(Req, self).__init__() super().__init__() self.conf = Config() self.host = self.conf.host self.monitor_host = self.conf.monitor_host self.zby_host = self.conf.zby_host self.aomp_host = self.conf.aomp_host self.weiXin_host = self.conf.weiXin_host self.openYDT_host = self.conf.openYDT_host self.mock_host = self.conf.mock_host self.roadSide_host = self.conf.roadSide_host if Session == None: self.Session = requests.Session() else: self.Session = Session
def __init__(self): self.host = Config().aomp_host seccodeUrl = self.host + "/getValidateCode.do" checkLoginUrl = self.host + "/checkLogin.do" headers = { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" } self.S = requests.Session() self.S.get(seccodeUrl) data = { "user": "******", "pwd": "123456", "isOnLine": "isOnLine", "flag": -1, "validateCode": 9999 } result =self.S.post(checkLoginUrl, data, headers=headers)
def test_personal_02(self, action): """ 用例描述:登陆状态下更新Personal个人简介 """ conf = Config() data = Personal() request = Request.Request(action) host = conf.host_debug req_url = 'http://' + host urls = data.url params = data.data headers = data.header api_url = req_url + urls[1] response = request.post_request(api_url, params[1][0], headers[1]) assert response['code'] == 200 Consts.RESULT_LIST.append('True')
def __init__(self): self.host = Config().pomp_host seccodeUrl = self.host + "/mgr/normal/authz/seccode.do" verify_seccode = self.host + "/mgr/normal/authz/verify_seccode.do" loginURl = self.host + "/mgr/normal/ajax/login.do" headers = { "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8" } self.S = requests.Session() self.S.get(seccodeUrl) seccodeData = {"seccode": 9999} self.S.post(verify_seccode, data=seccodeData) data = { "username": "******", "password": "******", "seccode": 9999 } self.S.post(loginURl, data, headers=headers)
def test_collections_02(self, action): """ 用例描述:查看用户'95c34f9cc50c'的Collections """ conf = Config() data = Collections() test = Assert.Assertions() request = Request.Request(action) host = conf.host_debug req_url = 'http://' + host urls = data.url params = data.data headers = data.header api_url = req_url + urls[1] response = request.post_request(api_url, params[1], headers[1]) assert test.assert_code(response['code'], 208) assert test.assert_in_text(response['body'], '每日一篇技术文') Consts.RESULT_LIST.append('True')
def test_collections_01(self, action): """ 用例描述:查看用户'da1677475c27'的Collections """ conf = Config() data = Collections() test = Assert.Assertions() request = Request.Request(action) host = conf.host_debug req_url = 'http://' + host urls = data.url params = data.data headers = data.header api_url = req_url + urls[0] response = request.post_request(api_url, params[0], headers[0]) assert test.assert_code(response['code'], 200) assert test.assert_in_text(response['body'], '软件测试-各种技能集合') Consts.RESULT_LIST.append('True')
def test_basic_02(self, action): """ 用例描述:登陆状态下查看基础设置 """ conf = Config() data = Basic() test = Assert.Assertions() request = Request.Request(action) host = conf.host_debug req_url = 'http://' + host urls = data.url params = data.data headers = data.header api_url = req_url + urls[1] response = request.post_request(api_url, params[1], headers[1]) assert test.assert_code(response['code'], 401) assert test.assert_text(response['text'], '{"error":"继续操作前请注册或者登录."}') Consts.RESULT_LIST.append('True')
def test_basic_01(self, action): """ 用例描述:未登陆状态下查看基础设置 """ conf = Config() data = Basic() test = Assert.Assertions() request = Request.Request(action) host = conf.host_debug req_url = 'http://' + host urls = data.url params = data.data headers = data.header api_url = req_url + urls[0] response = request.get_request(api_url, params[0], headers[0]) assert test.assert_code(response['code'], 401) assert test.assert_body(response['body'], 'error', u'继续操作前请注册或者登录.') assert test.assert_time(response['time_consuming'], 100) Consts.RESULT_LIST.append('True')
def test_login_02(self, action): """ 用例描述:账户正确密码错误 登录失败 """ conf = Config() data = Login() test = Assert.Assertions() request = Request.Request(action) host = conf.host_base req_url = 'http://' + host urls = data.url params = data.data headers = data.header api_url = req_url + urls[0] response = request.post_request(api_url, params[1], headers[0]) assert test.assert_code(response['body']['code'], '1005') assert test.assert_body(response['body'], 'description', '密码错误') assert test.assert_time(response['time_consuming'], 200) Consts.RESULT_LIST.append('True')
def __init__(self): self.config = Config() self.log = Log.MyLog()
def ctl_and_report_emma( syslist=["stock", "sku", "trade"], conf=Config("../Config/dev.conf"), webroot='/data/tp/test/InterfaceTestFrameworkWeb/webroot', uri='http://10.0.18.31'): """ 重置emma,并重新插装。 最好是重启系统。 :param syslist: :param conf: :return: """ ret_url_dict = {} #init ret_url_dict for syskey in syslist: ret_url_dict[syskey] = {} ret_url_dict[syskey]['url'] = "None" tmp_dir = "/home/wangjiliang" for value in syslist: ip = conf.conf_dict[value]['host_addr'] port = int(conf.conf_dict[value]['ssh_port']) username = conf.conf_dict[value]['ssh_user'] password = conf.conf_dict[value]['ssh_passwd'] base_dir = conf.conf_dict[value]['base_dir'] # java_src = conf.conf_dict[value]['java_src'] # java_src_list = java_src.split(',') # java_src_final_str = "" # for srcvalue in java_src_list: # java_src_final_str += "%s%s," % (base_dir, srcvalue) # java_src_final_str = java_src_final_str[:-1] java_src_final_str = "%s/%s/%s-dao/src/main/java,%s/%s/%s-engine/src/main/java,%s/%s/%s-service/src/main/java" % ( base_dir, value, value, base_dir, value, value, base_dir, value, value) ctime = UsualTools.get_current_time_numstr() renamereportpath = "reportfor%s%s" % (value, ctime) shell_list = """source /etc/profile; cd %s; rm -rf log/test.ec; java emma ctl -connect localhost:47653 -command coverage.get,log/test.ec; #generate report html rm -rf report/*; #-sp /xxxx/xxxx/javaSources report have src java emma report -r html -sp %s -in log/test.em,log/test.ec -Dreport.html.out.file=report/test.html; #copy to webserver cp -r report %s; scp -P50022 -r %s [email protected]:%s/emma/%s/; rm -rf reportfor*; """ % (tmp_dir, java_src_final_str, renamereportpath, renamereportpath, webroot, value) try: # 生成ssh客户端实例 s = paramiko.SSHClient() s.set_missing_host_key_policy(paramiko.AutoAddPolicy()) s.connect(ip, port, username, password, timeout=10) #初始化环境变量 #开始执行shell命令 先加载环境变量 stdin, stdout, stderr = s.exec_command( "cd %s;rm -rf tctlreportcp.sh;echo '%s' > tctlreportcp.sh;chmod +x tctlreportcp.sh;" % (tmp_dir, shell_list)) geneshstr = stdout.read() stdin, stdout, stderr = s.exec_command("cd %s;ls;" % tmp_dir) lsstr = stdout.read() if "tctlreportcp.sh" not in lsstr: logging.debug("ERROR: tctlreportcp.sh not generate!") stdin, stdout, stderr = s.exec_command("cd %s;./tctlreportcp.sh;" % tmp_dir) emmactlstr = stdout.read() if "EMMA: coverage.get: command completed in" in emmactlstr and "writing [html] report to [/home/wangjiliang/report/test.html]" in emmactlstr: url = "%s/emma/%s/%s/test.html" % (uri, value, renamereportpath) logging.debug( "SUCCESS: REPORT generate and send to remote webserver. report url:%s" % url) ret_url_dict[value]['url'] = url else: logging.debug("ERROR: REPORT generate failed; LOG:%s" % emmactlstr) s.close() except Exception, e: logging.debug(UsualTools().get_current_time() + u"=>run.py: ctl_and_report_emma: 发生异常。MSG:%s" % e)