Пример #1
0
class RunTest(object):
    def __init__(self):
        self.common_util = CommonUtil()
        self.send_email = SendEmail()
        self.connect_db = OperationMySQL()
        self.run_method = RunMethod()
        self.op_json = OperationJson()

    def run(self):
        res = None
        pass_count = []
        fail_count = []
        rows_count = self.connect_db.get_count()
        print(rows_count)
        for i in range(0, rows_count):
            run = self.connect_db.search('run', i)
            if run:
                url = self.connect_db.search('url', i)
                request_method = self.connect_db.search('request_method', i)
                request_data = self.op_json.get_data(
                    self.connect_db.search('request_data', i))
                expect = self.connect_db.search('expect', i)
                print(expect)
                res = self.run_method.run_main(request_method, url,
                                               request_data)
                print(res)
                if self.common_util.is_contain(expect, res) == 1:
                    self.connect_db.write('pass', i + 1)
                    pass_count.append(i + 1)
                    print(pass_count)
                else:
                    self.connect_db.write(res, i + 1)
                    fail_count.append(i + 1)
                    print(fail_count)
        self.send_email.send_main(pass_count, fail_count)
 def __init__(self):
     self.run = RunMethod()
     self.data = GetData()
     self.com_util = CommonUtil()
     self.send_mail = SendEmail()
     self.log = UserLog()
     self.logger = UserLog.get_log()
Пример #3
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.equeal = equeal()
        self.sendmail = SendEmail()

    #程序执行
    def go_on_run(self):
        pass_list = []
        fail_list = []
        res = None
        rows_count = self.data.get_case_lines()
        for i in range(1, rows_count):
            url = self.data.get_url(i)
            method = self.data.get_request_methon(i)
            is_run = self.data.get_is_run(i)
            data = self.data.get_data_for_json(i)
            headers = self.data.get_header_json(i)
            expect = self.data.get_except_data(i)
            print(expect)
            if is_run:
                res = self.run_method.run_main(method, url, data, headers)
                if self.equeal.is_contain(expect, res):
                    self.data.write_result(i, 'pass')
                    pass_list.append(i)
                else:
                    print("测试失败")
                    self.data.write_result(i, res)
                    fail_list.append(i)
        self.sendmail.send_content(pass_list, fail_list)
def send_alert(hostaddress, hostname, servicename, attemptno, date, time,
               message, alertlevel):
    try:
        lower_case_alertlevel = str(alertlevel).lower()
        message_type = ALERT_LEVEL_MAPPING[lower_case_alertlevel]
    except KeyError:
        if servicename is None:
            message_type = ALERT_LEVEL_MAPPING['invalid_host']
        else:
            message_type = ALERT_LEVEL_MAPPING['invalid_service']
    remarks = 'No Remarks'
    if message_type == 'host_check':
        subject_args = (hostaddress, alertlevel, attemptno)
        body_args = (hostaddress, alertlevel, attemptno, message, remarks,
                     SHINKEN_URL, hostname, date, time)
    elif message_type == 'service_check':
        subject_args = (servicename, hostaddress, alertlevel, attemptno)
        body_args = (servicename, alertlevel, hostaddress, attemptno, message,
                     remarks, SHINKEN_URL, hostname, servicename, date, time)
    else:
        print 'Invalid message_type: %s. Aborting!'
        return
    # Send email
    email_sender = SendEmail()
    email_sender.send(message_type, subject_args=subject_args,
                      body_args=body_args)
    return
Пример #5
0
class RunTest:
    def __init__(self):
        """
        初始化RunTest类
        """
        self.run_method = RunMain()
        self.data = GetData()
        self.common_util = CommonUtil()
        self.send_email = SendEmail()

    def go_on_run(self):
        """
        执行测试用例
        :return: 通过用例和失败用例
        """
        pass_list = []
        fail_list = []
        rows_count = self.data.get_case_num()
        for i in range(1, rows_count):
            is_run = self.data.is_run(i)
            if is_run:
                url = self.data.get_request_url(i)
                method = self.data.get_method(i)
                data = self.data.get_data_for_json(i)
                cookie = self.data.is_cookie(i)
                header = self.data.is_header(i)
                expect = self.data.get_expect_data(i)
                if isinstance(expect, float):
                    expect = str(int(expect))
                depend_case = self.data.is_depend(i)
                if depend_case is not None:
                    depend_data = DependentData(depend_case)
                    # 获取依赖响应的返回数据
                    depend_response_data = depend_data.get_data_for_key(i)
                    # # 使用mock-test模拟请求
                    # depend_response_data = mock_test(self.run_method.run_main, data, url, "POST", order)
                    # 获取依赖的字段
                    depend_field = self.data.get_depend_field(i)
                    # 更新
                    data[depend_field] = depend_response_data
                if cookie == 'write':
                    res = self.run_method.run_main(method, url, data, header)
                    opera_cookie = OperationCookie(res)
                    opera_cookie.write_cookie()
                elif cookie == 'yes':
                    op_json = OperationJson('../data_config/cookie.json')
                    cookie = op_json.get_data('ASP.NET_SessionId')
                    cookies = {'ASP.NET_SessionId': cookie}
                    res = self.run_method.run_main(method, url, data, cookies)
                else:
                    res = self.run_method.run_main(method, url, data)
                if self.common_util.is_contain(expect, res.text):
                    # print("PASS")
                    pass_list.append(i)
                    self.data.write_result(i, 'PASS')
                else:
                    # print("FAILED")
                    fail_list.append(i)
                    self.data.write_result(i, 'FAILED')
        self.send_email.send_main(pass_list, fail_list)
Пример #6
0
	def __init__(self):
		self.run_method = RunMethod()
		self.data = GetData()
		self.com_util = CommonUtil()
		self.send_mai = SendEmail()  #不带文件发送
		self.send_email=Email()  #带文件发送
		get_user_log=UserLog()
		self.logger = get_user_log.get_log()
Пример #7
0
 def __init__(self):
     self.json_file = "/Users/mac/Desktop/测试资料/蜗牛家产品线/woniujia_cc_jiekou/woniujia_cc_jiekou_git/woniujia_cc_project/dataconfig/request_pram.json"
     self.sheet_name = "客户模块"
     self.sheet_id = 5
     self.data = GetData(self.json_file, self.sheet_name, self.sheet_id)
     self.run_method = RunMethod()
     self.util = CommonUtil()
     self.email = SendEmail()
Пример #8
0
 def __init__(self):
     """
     初始化RunTest类
     """
     self.run_method = RunMain()
     self.data = GetData()
     self.common_util = CommonUtil()
     self.send_email = SendEmail()
Пример #9
0
class RunTest():
	def __init__(self):
		self.run_method = RunMethod()
		self.data = GetData()
		self.com_util = CommonUtil()
		self.send_mai = SendEmail()  #不带文件发送
		self.send_email=Email()  #带文件发送
		get_user_log=UserLog()
		self.logger = get_user_log.get_log()
	#程序执行的
	def go_on_run(self):
		res = None
		pass_count = []
		fail_count = []
		#10  0,1,2,3
		rows_count = self.data.get_case_lines()
		for i in range(1,rows_count):
			is_run = self.data.get_is_run(i)
			if is_run:
				url = self.data.get_request_url(i)
				method = self.data.get_request_method(i)
				request_data = self.data.get_data_for_json(i)
				expect = self.data.get_expcet_data(i)
				header = self.data.is_header(i)
				depend_case = self.data.is_depend(i)
				case_name=self.data.get_case_name(i)
				if depend_case != None:
					self.depend_data = DependdentData(depend_case)
					#获取的依赖响应数据
					depend_response_data = self.depend_data.get_data_for_key(i)
					#获取依赖的key
					depend_key = self.data.get_depend_field(i)
					request_data[depend_key] = depend_response_data
				if header == 'write':
					res = self.run_method.run_main(method,url,request_data)
					op_header = OperationHeader(res)
					op_header.write_cookie()

				elif header == 'yes':
					op_json = OperetionJson('./dataconfig/cookie.json')
					cookie = op_json.get_data('apsid')
					# cookies = {
					# 	'apsid':cookie
					# }
					res = self.run_method.run_main(method,url,request_data,cookie)
					self.logger.info("用例名称:"+case_name+"--->返回值:"+res)
					#print(res)
				else:
					res = self.run_method.run_main(method,url,request_data)
					self.logger.info("用例名称:" + case_name + "--->返回值:" + res)
					#print(res)
				if self.com_util.is_contain(expect,res) == True:
					self.data.write_result(i,'pass')
					pass_count.append(i)
				else:
					self.data.write_result(i,res)
					fail_count.append(i)
		self.send_mai.send_main(pass_count,fail_count)  #不带文件发送
Пример #10
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.commonutil = Commonutil()
        self.sendmail = SendEmail()

    def go_on_run(self):  # 程序执行
        pass_count = []
        fail_count = []
        rows_count = self.data.get_case_lines()
        for i in range(1, rows_count):
            is_run = self.data.get_is_run(i)
            if is_run:
                url = self.data.get_request_url(i)
                method = self.data.get_request_method(i)
                data = self.data.get_data_for_json(i)
                # expect = self.data.get_expect_data(i)  # Excel写入预期结果
                expect = self.data.get_expect_data_for_mysql(i)
                header = self.data.is_header(i)
                depend_case = self.data.is_depend(i)
                res = self.run_method.run_main(method, url, data, header)
                values = {"resultCode": res["resultCode"]}
                # print(res["resultData"]["access_id"])
                value = json.dumps(values)  # 字典转字符串匹配
                if depend_case is not None:
                    self.depend_data = DependentDate(depend_case)
                    # 依赖响应数据
                    depend_response_data = self.depend_data.get_data_for_key(i)
                    # 获取依赖的key
                    data = json.loads(data)
                    depend_key = self.data.get_depend_field(i)
                    data[depend_key] = depend_response_data
                if header == 'write':
                    res = self.run_method.run_main(method, url, data)
                    op_header = OperationHeader(res)
                    op_header.write_cookie()

                elif header == 'yes':
                    op_json = OperationJson('../dataconfig/cooking.json')
                    cookie = op_json.get_data('apsid')
                    cookies = {
                        'apsid': cookie
                    }
                    value = self.run_method.run_main(method, url, data, cookies)
                else:
                    value = self.run_method.run_main(method, url, data)
                if self.commonutil.is_equal_dict(expect, value):
                    self.data.write_result(i, '通过')
                    pass_count.append(i)
                    print('测试通过')
                else:
                    self.data.write_result(i, '失败')
                    fail_count.append(i)
                    print('测试失败')

                print(pass_count, fail_count)
        self.sendmail.send_main(pass_count, fail_count)
Пример #11
0
class RunTest:
    def __init__(self):
        self.run = RunMethod()
        self.data = GetData()
        self.com_util = CommonUtil()
        self.send_mail = SendEmail()
        self.log = UserLog()
        self.logger = UserLog.get_log()

    # 程序执行的主入口
    def go_on_run(self):
        res = None
        pass_count = []
        fail_count = []
        rows_count = self.data.get_case_lines()
        for i in range(1,rows_count):
            is_run = self.data.get_is_run(i)
            if is_run:
                url = self.data.get_request_url(i)
                # if i == 7:
                #     print("已经成年")
                # url = 'http://192.168.2.81:10003/shop/goods/new-list'
                method = self.data.get_request_method(i)
                is_run = self.data.get_is_run(i)
                data = self.data.get_data_for_json(i)
                expect = self.data.get_expcet_data(i)
                # expect = self.data.get_expcet_data_for_mysql(i)
                # data = {'pageNum': 1, 'pageSize': 10}
                header = self.data.is_header(i)
                depend_case = self.data.is_depend(i)
                # header = {'Content-Type': 'application/json'}
                if depend_case != None:
                    self.depend_data = DependentData(depend_case)
                    # 获取的依赖响应数据
                    depend_response_data = self.depend_data.get_data_for_key(i)
                    print("this is dependResponseData = ",depend_response_data)
                    # 获取依赖的key
                    depend_key = self.data.get_depend_fileld(i)
                    print("*************this is depend_key = ",depend_key)
                    # 根据获取的依赖key,将depend_kay更新成depend_response_data
                    data[depend_key] = depend_response_data
                    print("*************this is data[depend_key]",data[depend_key])

                res = self.run.run_main(method, url, data, header)
                if self.com_util.is_contain(expect,res):
                    self.data.write_result(i,'Pass')
                    pass_count.append(i)
                else:
                    self.data.write_result(i,res)
                    fail_count.append(i)
            else:
                self.data.write_result(i, 'N/A')
                continue
            # print(res)
            #     print(len(pass_count))
            #     print(len(fail_count))
        self.send_mail.send_main(pass_count,fail_count)
Пример #12
0
class RunText:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.common_util = CommonUtil()
        self.sendmail = SendEmail()
        # 执行程序的主入口

    def go_on_run(self, pr=None):
        res = None
        pass_count = []
        fail_count = []
        row_count = self.data.get_case_lines()
        for i in range(1, row_count):
            url = self.data.get_request_url(i)
            method = self.data.get_request_method(i)
            data = self.data.get_data_for_json(i)
            is_run = self.data.get_is_run(i)
            header = self.data.get_data_header_json(i)
            expect = self.data.get_expect_data(i)
            depend_case = self.data.is_depend(i)
            # if depend_case != None:
            #     self.depend_data = DependdentData(depend_case)
            #     #获取相应数据的依赖
            #     depend_response_data = self.data.get_depend_key(i)
            #     #获取依赖的key
            #     depend_key = self.data.get_depend_field(i)
            #     data[depend_key] = depend_response_data
            # res = self.run_method.run_main(method,url,header,data)
            # print res'''
            '''if header == 'write':
                res = self.run_method.run_main(method, url, request_data)
                op_header = OperationHeader(res)
                op_header.write_cookie()

            elif header == 'yes':
                op_json = OperetionJson('../dataconfig/cookie.json')
                cookie = op_json.get_data('apsid')
                cookies = {
                    'apsid': cookie
                }
                res = self.run_method.run_main(method, url, request_data, cookies)
            else:
                res = self.run_method.run_main(method, url, request_data)'''

            if is_run:
                res = self.run_method.run_main(method, url, header, data)
                if self.common_util.is_contain(expect, res):
                    # print "测试通过"
                    print self.data.write_value(i, "pass")
                    pass_count.append(i)
                else:
                    # print "测试失败"
                    print self.data.write_value(i, res)
                    fail_count.append(i)

        self.sendmail.send_main(pass_count, fail_count)
Пример #13
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.com_util = CommonUtil()
        self.send_mai = SendEmail()

    #程序执行的
    def go_on_run(self):
        res = None
        pass_count = []
        fail_count = []
        #10  0,1,2,3
        rows_count = self.data.get_case_lines()
        for i in range(1, rows_count):
            is_run = self.data.get_is_run(i)
            if is_run:
                url = self.data.get_request_url(i)
                method = self.data.get_request_method(i)
                request_data = self.data.get_data_for_json(i)
                #通过数据库获取预期结果
                #expect = self.data.get_expcet_data_for_mysql(i)
                expect = self.data.get_expcet_data(i)

                header = self.data.is_header(i)
                depend_case = self.data.is_depend(i)
                if depend_case != None:
                    self.depend_data = DependdentData(depend_case)
                    #获取的依赖响应数据
                    depend_response_data = self.depend_data.get_data_for_key(i)
                    #获取依赖的key
                    depend_key = self.data.get_depend_field(i)
                    request_data[depend_key] = depend_response_data
                if header == 'write':
                    res = self.run_method.run_main(method, url, request_data)
                    op_header = OperationHeader(res)
                    op_header.write_cookie()

                elif header == 'yes':
                    op_json = OperetionJson('../dataconfig/cookie.json')
                    cookie = op_json.get_data('apsid')
                    cookies = {'apsid': cookie}
                    res = self.run_method.run_main(method, url, request_data,
                                                   cookies)
                else:
                    res = self.run_method.run_main(method, url, request_data)

                if self.com_util.is_equal_dict(expect, res) == 0:
                    self.data.write_result(i, 'pass')
                    pass_count.append(i)
                    res = pass_count

                else:
                    self.data.write_result(i, res)
                    fail_count.append(i)
                    res = fail_count
        self.send_mai.send_main(pass_count, fail_count)
Пример #14
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.com_util = CommonUtil()
        self.send_email = SendEmail()

    # 程序执行的主入口
    def go_on_run(self):
        #rows_count = self.data.get_case_lines()
        rows_count = 2
        pass_count = []
        fail_count = []
        res = None
        for i in range(1, rows_count):
            url = self.data.get_request_url(i)
            method = self.data.get_request_method(i)
            is_run = self.data.get_is_run(i)
            request_data = self.data.get_data_for_json(i)
            header = self.data.get_is_header(i)
            expect = self.data.get_expect_data_for_sql(i)
            print(expect)
            print(type(expect))
            depend_case = self.data.is_depend(i)
            '''if depend_case != '':
                self.depend_data = DependentData(depend_case)
                #获取依赖的响应数据
                depend_response_data = self.depend_data.get_data_for_key(i)
                #获取依赖的key
                depend_key = self.data.get_depend_field(i)
                request_data[depend_key] = depend_response_data
                res = self.run_method.run_main(method,url,request_data,header)'''
            #res = self.run_method.run_main(method, url, request_data, header)
            request_data1 = {
                "id": 1,
                "username": "******",
                "password": "******",
                "email": "*****@*****.**",
                "age": 18
            }
            ress = mock_test(
                self.run_method.run_main(method, url, request_data, header),
                request_data, url, method, request_data1)
            print(ress)
            print(type(ress))
            if is_run:
                if self.com_util.is_equal_dict(expect, ress):
                    self.data.write_result(i, 'pass')
                    pass_count.append(i)
                else:
                    self.data.write_result(i, ress)
                    fail_count.append(i)
        self.send_email.send_main(pass_count, fail_count)
Пример #15
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.com_util = CommonUtil()
        self.send_mai = SendEmail()

    # 程序执行的
    def go_on_run(self):
        res = None
        pass_count = []
        fail_count = []
        # 10  0,1,2,3
        rows_count = self.data.get_case_lines()
        for i in range(1, rows_count):
            is_run = self.data.get_is_run(i)
            if is_run:
                url = self.data.get_request_url(i)
                method = self.data.get_request_method(i)
                request_data = self.data.get_data_for_json(i)
                expect = self.data.get_expcet_data_for_mysql(i)
                header = self.data.is_header(i)
                depend_case = self.data.is_depend(i)
                if depend_case != None:
                    self.depend_data = DependdentData(depend_case)
                    # 获取的依赖响应数据
                    depend_response_data = self.depend_data.get_data_for_key(i)
                    # 获取依赖的key
                    depend_key = self.data.get_depend_field(i)
                    request_data[depend_key] = depend_response_data
                if header == 'write':
                    res = self.run_method.run_main(method, url, request_data)
                    op_header = OperationHeader(res)
                    op_header.write_cookie()

                elif header == 'yes':
                    op_json = OperetionJson('../dataconfig/cookie.json')
                    cookie = op_json.get_data('apsid')
                    cookies = {
                        'apsid': cookie
                    }
                    res = self.run_method.run_main(method, url, request_data, cookies)
                else:
                    res = self.run_method.run_main(method, url, request_data)

                if self.com_util.is_equal_dict(expect, res) == 0:
                    self.data.write_result(i, 'pass')
                    pass_count.append(i)
                else:
                    self.data.write_result(i, res)
                    fail_count.append(i)
        self.send_mai.send_main(pass_count, fail_count)
Пример #16
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.com_util = CommonUtil()
        self.send_mai = SendEmail()

    #程序执行的主入口
    def go_on_run(self):
        res = None
        pass_count = []
        fail_count = []
        #10 0,1,2,3,4,5,6......  第一行不需要
        rows_count = self.data.get_case_lines()
        for i in range(1, rows_count):
            url = self.data.get_request_url(i)
            method = self.data.get_request_method(i)
            is_run = self.data.get_is_run(i)
            data = self.data.get_data_for_json(i)
            #不能调用get_request_data()方法
            expect = self.data.get_expect_data(i)
            header = self.data.is_header(i)
            depend_case = self.data.is_depend(i)
            # 有依赖后  需要把需要的数据组装起来  返回结果
            if depend_case != None:
                self.sepend_data = DependentData()
                #获取的依赖相应数据
                depend_response_data = self.depend_data.get_data_for_key(i)
                #获取依赖的key
                depend_key = self.data.get_depend_filed(i)
                request_data[depend_key] = depend_response_data
            res = self.run_method.run_main(method, url, data, header)

            if is_run:
                #method,url,data=None,header=None  run_main里边变量的顺序不能错
                res = self.run_method.run_main(method, url, data, header)
                # print (type(res))
                if self.com_util.is_contain(expect, res):
                    # print ("测试通过")
                    self.data.write_result(i, 'pass')
                    pass_count.append(i)
                    print(pass_count)
                    print(len(pass_count))
                else:
                    # print ("测试失败")
                    self.data.write_result(i, 'fail')
                    fail_count.append(i)
                    # print (len(fail_count))
                    print(fail_count)
            return res
            self.send_mai.send_main([1, 2], [1])
        self.send_mai.send_main([1, 2], [1])
Пример #17
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.com_util = CommonUtil()
        self.send_mai = SendEmail()

    #程序执行的
    def go_on_run(self):
        res = None
        pass_count = []
        fail_count = []
        rows_count = self.data.get_case_lines()
        flat = 1
        while(flat):
            for i in range(1,rows_count):
                is_run = self.data.get_is_run(i)
                if is_run:
                    url = self.data.get_request_url(i)
                    method = self.data.get_request_method(i)
                    request_data = self.data.get_data_form_json(i)
                    expect = self.data.get_expect_data(i)
                    header = self.data.is_header(i)
                    depend_case = self.data.is_depend(i)   #数据依赖
                    if depend_case != None:
                        self.depend_data = DependData()
                        #依赖的响应数据
                        depend_response_data =self.depend_data.get_data_for_key(i)
                        #获取依赖的key
                        depend_key = self.data.get_depend_field(i)
                        request_data[depend_key] = depend_response_data

                    # method,url,data=None,header=None  顺序不可以颠倒
                    try:
                        res = self.run_method.run_main(method,url,request_data,header)
                    except ConnectionError:
                        pass
                    if res == None:
                        time.sleep(600)
                    else:
                        if self.com_util.is_contain(expect,res):
                            log_pass('success!!!')
                            print(flat)
                            time.sleep(20)
                            flat += 1
                            # self.data.write_result(i,'pass')
                            # pass_count.append(i)
                        else:
                            log_error('fail!!!')
                            self.send_mai.send_main()
                            time.sleep(600)
Пример #18
0
class RunTest(object):
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.common_util = CommonUtil()
        self.send_email = SendEmail()

    def run(self):
        res = None
        pass_count = []
        fail_count = []
        rows_count = self.data.get_case_lines()
        for i in range(1, rows_count):
            run = self.data.get_run(i)
            if run:
                url = self.data.get_url(i)
                request_method = self.data.get_request_method(i)
                request_data = self.data.get_data_for_json(i)
                expect = self.data.get_expect(i)
                print(expect)
                header = self.data.get_header(i)
                # case_depend = self.data.get_case_depend(i)
                # if case_depend != None:
                #     self.depend_data = DependentData(case_depend)
                #     depend_response_data = self.depend_data.get_data_for_key(i)
                #     depend_key = self.data.get_depend_response_data(i)
                #     request_data[depend_key] = depend_response_data
                if header == 'write':
                    res = self.run_method.run_main(request_method, url,
                                                   request_data)
                    op_header = OperationHeader(res)
                    op_header.write_cookie()
                elif header == 'yes':
                    op_json = OperationJson('../dataconfig/cookie.json')
                    cookie = op_json.get_data('apsid')
                    cookies = {'apsid': cookie}
                    res = self.run_method.run_main(request_method, url,
                                                   request_data, cookies)
                else:
                    res = self.run_method.run_main(request_method, url,
                                                   request_data)
                    print(res)
                if self.common_util.is_contain(expect, res) == 1:
                    self.data.write_result(i, 'pass')
                    pass_count.append(i)
                    print(pass_count)
                else:
                    self.data.write_result(i, res)
                    fail_count.append(i)
                    print(fail_count)
        self.send_email.send_main(pass_count, fail_count)
Пример #19
0
 def __init__(self, methodName='runTest', parame=None):
     super(ParameTestCase, self).__init__(methodName)
     self.run_method = RunMethod()
     self.data = GetData()
     self.com_util = CommonUtil()
     self.send_mai = SendEmail()
     self.operation = OperetionJson()
Пример #20
0
 def __init__(self):
     unittest.TestCase.__init__(self)
     xiao_iron = 'E:/xt/xironbardepend/xironbackend/'
     self.run_method = RunMethod()
     self.data = GetData(xiao_iron + 'dataconfig/interfacebar1.xlsx', 2)
     self.send_mai = SendEmail()
     self.read_int = ReadIni()
Пример #21
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.com_util = CommonUtil()
        self.send_mai = SendEmail()

    # 程序执行流程
    def go_on_run(self):
        res = None
        pass_count = []
        fail_count = []
        # 获取所有行
        roes_count = self.data.get_case_lines()
        # 跳过1在行里循环
        for i in range(1, roes_count):
            is_run = self.data.get_is_run(i)
            if is_run:  #执行
                urls = self.data.get_url(i)  #接口地址
                url = host_api + urls
                method = self.data.git_method_way(i)  #请求方
                former = self.data.get_api_data(i)  #请求数据
                expect = self.data.get_expcet_data(i)  #预期结果
                header = operation_header.gain_herder()  #获取header
                depend_case = self.data.is_depend(i)  #获取是否有数据依赖
                if depend_case != None:  #判断数据依赖不是空
                    self.depend_data = DependdentData(
                        depend_case)  #实列化depend_data
                    data = self.depend_data.get_data_for_key(
                        i, former)  #获取依赖返回data
                    print(type(data), i)
                res = self.run_method
                if is_run:  #判断是否执行
                    if method != 'Post' and data != None:
                        datas = eval(data)
                    else:
                        datas = data
                    res = self.run_method.run_main(method, url, datas, header)
                    self.data.write_api_return_data(i, res)
                    if self.com_util.is_contain(expect, res):  #判断预期结果
                        self.data.write_resuit(i, "测试通过")
                        pass_count.append(i)
                    else:
                        self.data.write_resuit(i, "测试失败")
                        fail_count.append(i)
        self.send_mai.send_main(pass_count, fail_count)
Пример #22
0
 def __init__(self):
     unittest.TestCase.__init__(self)
     xiao_iron = 'E:/xt/xtcontract/xironbackend/dataconfig/'
     self.run_method = RunMethod()
     self.data = GetData(xiao_iron + 'interfacebar1.xlsx', 8)
     self.send_mai = SendEmail()
     self.read_int = ReadIni()
     self.statistic = Dict()
     self.excel_prop = Dict()
Пример #23
0
 def __init__(self, json_file, sheet_name, sheet_id, sql_base=None):
     self.json_file = json_file
     self.sheet_name = sheet_name
     self.sheet_id = sheet_id
     self.sql_base = sql_base
     self.data = GetData(self.json_file, self.sheet_name)
     self.run_method = RunMethod()
     self.util = CommonUtil()
     self.email = SendEmail()
Пример #24
0
 def __init__(self, json_file, sheet_name, sheet_id):
     # self.excel_file = excel_file
     self.json_file = json_file
     self.sheet_name = sheet_name
     self.sheet_id = sheet_id
     self.data = GetData(self.json_file, self.sheet_name)
     self.run_method = RunMethod()
     self.util = CommonUtil()
     self.email = SendEmail()
Пример #25
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.com_util = CommonUtil()
        self.send_mail = SendEmail()

    #程序入口
    def go_on_run(self):
        res = None
        pass_count = []
        fail_count = []
        rows_count = self.data.get_case_lines()
        for i in range(1, rows_count):
            is_run = self.data.get_is_run(i)
            if is_run:
                url = self.data.get_request_url(i)
                method = self.data.get_request_method(i)
                request_data = self.data.get_data_for_json(i)
                expect = self.data.get_expcet_data(i)
                header = self.data.is_header(i)
                depend_case = self.data.is_depend(i)

                if depend_case != None:
                    self.depend_data = DependentData()
                    #获取的依赖响应数据
                    depend_response_data = self.depend_data.get_data_for_key(i)
                    #获取依赖的key
                    depend_key = self.data.get_depend_field(i)
                    request_data[depend_key] = depend_response_data
                res = self.run_method.run_main(method, url, request_data,
                                               header)

                if self.com_util.is_contain(expect, res):
                    self.data.write_result(i, 'pass')
                    pass_count.append(i)
                    #print("测试通过")
                else:
                    #print("测试失败")
                    self.data.write_result(i, res)
                    fail_count.append(i)
        print(len(pass_count))
        print(len(fail_count))
        self.send_mail.send_main(pass_count, fail_count)
Пример #26
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.dataexcel = OpertionExcel
        self.commonutil = CommonUtil
        self.sendemail = SendEmail()
    #程序执行主入口
    def go_on_run(self):
        pass_count = []
        fail_count = []
        rows_count = self.data.get_case_lines()
        for i in range(1,rows_count):
            url = self.data.get_url(i)
            method = self.data.get_request_way(i)
            is_run = self.data.get_is_run(i)
            data = self.data.get_data_for_json(i)
            header = self.data.is_header(i)
            expect = self.data.get_expcet_data(i)
            depend_case = self.data.is_depend(i)
            if depend_case != None:
                 # print("`````11`")
                 self.depend_data = DependentData(depend_case)
                 #获取返回结果里面的依赖
                 depend_respones_data = self.depend_data.get_data_for_key(i)
                 #获取依赖的key
                 depend_data = self.data.get_depend_field(i)
                 #将返回结果里面的依赖赋值给依赖数据
                 data[depend_data] = depend_respones_data

            if is_run == True:
                run_main = self.run_method.run_main(method,url,data,header)
                # print(type(run_main))
                # print(type(expect))
                print(run_main)
                if expect in run_main:
                     self.data.write_result(i,"pass")
                     pass_count.append(i)
                else:
                     self.data.write_result(i,run_main)
                     fail_count.append(i)
        self.sendemail.send_main(pass_count,fail_count)
Пример #27
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.com_util = CommonUtil()
        self.send_mail = SendEmail()

    def go_on_run(self):
        res = None
        pass_count = []
        fail_count = []
        rows_count = self.data.get_case_lines()
        print(rows_count)
        for i in range(1, rows_count):
            #获取excel表格中的数据
            url = self.data.get_request_url(i)
            method = self.data.get_request_method(i)
            is_run = self.data.get_is_run(i)
            data = self.data.get_request_data(i)
            header = self.data.is_header(i)
            expect = self.data.get_expcet_data(i)
            print(url, method, is_run, data, header, expect)
            #判断是否执行
            if is_run:
                res = self.run_method.run_main(method, url, data, header)
                info(res)
                #print(res)
                #判断预期结果和实际结果
                if self.com_util.is_contain(expect, res['data']):
                    #如果通过就把行号写入定义的列表中
                    pass_count.append(i)
                    #在excel表中的实际结果中输入测试结果
                    self.data.write_result(i, "pass")
                    print("测试通过")
                else:
                    print("测试失败")
                    #把执行失败的行号写入定义的列表中
                    fail_count.append(i)

        print(len(pass_count))
        print(len(fail_count))
        self.send_mail.send_main(pass_count, fail_count)
Пример #28
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.com_util = CommonUtil()
        self.send_mai = SendEmail()

    #程序执行的
    def go_on_run(self):

        pass_count = []
        fail_count = []
        rows_count = self.data.get_case_lines()
        #遍历case按行和列取
        for i in range(1, rows_count):
            url = self.data.get_request_url(i)
            method = self.data.get_request_method(i)
            is_run = self.data.get_is_run(i)
            data = self.data.get_data(i)
            expect = self.data.get_expect_data(i)
            header = self.data.is_header(i)
            name = self.data.get_name(i)
            # print name,'接口测试结果为:'
            if is_run:
                res = self.run_method.run_main(method, url, header, data)
                if self.com_util.is_contain(expect, res):
                    self.data.write_result(i, 'pass')
                    pass_count.append(i)
                    # print "测试通过"
                    # print type(expect)
                    # print type(res)
                    # print res
                else:
                    self.data.write_result(i, res)
                    fail_count.append(i)
                    # print "测试失败"
                    # print type(res)
                    # print res
        print len(pass_count)
        print len(fail_count)
        self.send_mai.send_main(pass_count, fail_count)
Пример #29
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.common = CommonUtil()
        self.send_email = SendEmail()

    #程序执行入口:
    def go_on_run(self):
        #统计通过用例数
        pass_count = []
        #统计失败用例数
        fail_count = []
        #取出Excel用例的总行数
        rows_count = self.data.get_case_line()
        #循环读取Excel表里各行列数据
        for i in range(1, rows_count):
            url = self.data.get_request_url(i)
            method = self.data.get_request_method(i)
            is_run = self.data.get_is_run(i)
            data = self.data.get_request_data_for_json_keyword(i)
            headers = self.data.get_is_header(i)
            expect = self.data.get_expect_data(i)
            #如果该条用例需要执行,就执行接口方法
            if is_run:
                res = self.run_method.run_main(method, url, data, headers)
                #判断如果期望结果在实际结果中
                if self.common.is_contains(expect, res):
                    #则将实际结果写入实际结果里
                    self.data.write_result(i, "pass")
                    pass_count.append(i)
                else:
                    self.data.write_result(i, res)
                    fail_count.append(i)
        #发送测试结果邮件
        self.send_email.send_main(pass_count, fail_count)
Пример #30
0
 def __init__(self):
     self.run_method = RunMethod()
     self.data = GetData()
     self.com_util = CommonUtil()
     self.send_mai = SendEmail()
#!/usr/bin/env python
#
# Utility for sending event alert emails in shinken
# Author: Rohit - @rohit01
#

from optparse import OptionParser
from util.send_email import SendEmail
import re

email_sender = SendEmail()
SHINKEN_URL = email_sender.get_server_url()
NOTIFICATION_EMAIL = email_sender.get_notification_email()

MESSAGE_TYPE = "event_triggered"
REGEX_FILTERS = [
    ## Filter unwanted messages to be sent as an email ##
    "^Connection refused by host.*$",
    "^Connection refused or timed out.*$",
    "^Timeout while attempting connection.*$",
    "^UNKNOWN.*$",
    "^CHECK_NRPE: Error - Could not complete SSL handshake.*$",
    "^[     ]*$",
]

## Command line arguments
OPTIONS = {
    "a": "hostaddress;Address of host server",
    "H": "hostname;Hostname defined in shinken",
    "s": "servicename;Service description name defined in shinken",
    "n": "attemptno;No of attempts",
Пример #32
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.com_util = CommonUtil()
        self.send_email = SendEmail()

    # 程序执行的主入口
    def go_on_run(self):
        # 10  0,1,2,3,
        res = None
        pass_count = []
        fail_count = []
        rows_count = self.data.get_case_lines()
        print(rows_count)
        for i in range(1, rows_count):
            is_run = self.data.get_is_run(i)
            if is_run:
                url = self.data.get_request_url(i)
                print(i, url)
                method = self.data.get_request_method(i)
                request_data = self.data.get_data_for_json(i)
                expect = self.data.get_expect_data(i)
                header = self.data.is_header(i)
                depend_case = self.data.is_depend(i)
                # res = self.run_method.run_main(method, url, data, header)
                # if is_run:
                # method,url,data=None,header=None
                if depend_case != None:
                    # self.depend_data = DependentData(depend_case)
                    print("depend_case is" + " --- " + depend_case)
                    self.depend_data = DependentData(depend_case)
                    # 获取的依赖响应数据
                    depend_response_data = self.depend_data.get_data_for_key(i)
                    #     获取依赖的key
                    print(depend_response_data)
                    depend_key = self.data.get_depend_field(i)
                    print(depend_key)
                    request_data[depend_key] = depend_response_data
                if header == "write":
                    res = self.run_method.run_main(method, url, request_data)
                    op_header = OperationHeader(res)
                    op_header.write_cookie()
                elif header == 'yes':
                    op_json = OperationJson('../dataconfig/cookie.json')
                    cookie = op_json.get_data('apsid')
                    cookies = {'apsid': cookie}
                    # cookie = op_header.get_data()
                    # cookie = ../dataconfig/cookie.json ../dataconfig/cookie.json
                    res = self.run_method.run_main(method, url, request_data,
                                                   cookies)
                else:
                    res = self.run_method.run_main(method, url, request_data)

                # res = self.run_method.run_main(method,url,request_data,header)
                # print(res)
                if self.com_util.is_contain(expect, res):
                    # print("测试通过")
                    self.data.write_result(i, 'pass')
                    pass_count.append(i)
                else:
                    # print("测试失败")
                    # self.data.write_result(i, 'fail')
                    self.data.write_result(i, res)
                    fail_count.append(i)
        self.send_email.send_main(pass_count, fail_count)
Пример #33
0
 def __init__(self):
     # self.addmerchantfun = AddMerchantFun()   #实例化
     self.data = GetData()  #实例化
     self.send_mai = SendEmail()  #实例化
Пример #34
0
 def __init__(self):
     self.run_method = RunMethod()
     self.data = GetData()
     self.com_util = CommonUtil()
     self.send_mai = SendEmail()