Esempio n. 1
0
    def get_host(self, host_name):
        """

        :param host_name: option name under [host_test], [host_pre], [host_prod], eg: sup
        :return:
        """
        ini = IniUtil()
        test_env = ini.get_value_of_option("Env", "Env")
        section = "host_" + test_env
        host = ini.get_value_of_option(section, host_name)
        return host
Esempio n. 2
0
 def get_json_path(self):
     """
     获取json文件的路径
     """
     ini = IniUtil()
     # 从ini文件获取当前要测试的环境
     test_env = ini.get_value_of_option("Env", "Env")
     # json文件的名称
     file_name = self.name + ".json"
     file_path = os.path.join(RESOURCE_FOLDER, test_env, file_name)
     return file_path
Esempio n. 3
0
 def get_db_connections(self, connection_name):
     """
     connection_name也以system的名称命名,所以此参数也是sys_name
     :param connection_name: option name under [db_test], [db_pre],[db_prod], eg: sup, b2b, b2c.
     :return:
     """
     ini = IniUtil()
     test_env = ini.get_value_of_option("Env", "Env")
     section = "db_" + test_env
     con = ini.get_value_of_option(section, connection_name)
     connection = json.loads(con)
     return connection
Esempio n. 4
0
def send_report(file_new, to_addr, subject=u'接口自动化测试报告'):

    with open(file_new, 'rb') as f:
        mail_body = f.read()

    # to_addr = IniUtil().get_value_of_option('to_list', 'to_list_sup')
    to_lists = to_addr.strip(',').split(
        ',')  # 这里需要是list类型   split 按,分割放在一个list中
    smtp_server = IniUtil().get_value_of_option('mail', 'server')
    from_addr = IniUtil().get_value_of_option('mail', 'send_addr')
    password = IniUtil().get_value_of_option('mail', 'password')

    # 邮件对象
    msg = MIMEMultipart()
    msg['Subject'] = Header(subject, 'utf-8')
    # msg['From'] = from_addr
    msg['From'] = Header(u"FBBC自动化测试专用邮箱", 'utf-8')
    msg['To'] = ";".join(to_lists)  # 接收string,邮箱之间用分号;隔开  以; 符号把list拼装起来
    print(msg['To'])
    # 邮件正文
    msg.attach(MIMEText(mail_body, 'html', 'utf-8'))

    # 附件
    att = MIMEText(mail_body, "base64", "utf-8")
    att["Content-Type"] = 'application/octet-stream'
    att["Content-Disposition"] = 'attachment;filename= "test_report.html"'
    msg.attach(att)

    try:
        smtp = smtplib.SMTP(smtp_server, 25)  # 链接server
        # smtp.starttls()
    except (gaierror and error) as e:
        Log().error(u'发送邮件失败,无法链接到SMTP服务器,检查网络以及SMTP服务器. %s' % e)
    else:
        try:
            smtp.login(from_addr, password)  # 登陆邮箱
        except smtplib.SMTPAuthenticationError as e:
            Log().error('用户名密码验证失败! %s' % e)
        else:
            smtp.sendmail(from_addr, to_lists, msg.as_string())
            Log().info(u'邮件发送成功!若没收到邮件,请检查垃圾箱,同时检查收件人地址是否正确')
        finally:
            smtp.quit()  # 断开链接
Esempio n. 5
0
    def get_endpoints(self, host_name, sys_name, resource_name):
        """

        :param host_name: option name under [host_test], [host_pre], [host_prod], eg: sup
        :param sys_name: system name, eg: sup, b2b, b2c
        :param resource_name: option name under [resource_b2b],[resource_sup], eg: login
        :return:
        """
        host = self.get_host(host_name)
        resource_section = "resource_" + sys_name
        resource = IniUtil().get_value_of_option(resource_section,
                                                 resource_name)
        endpoint = host + resource
        return endpoint
Esempio n. 6
0
"""购物车 共9个接口,已完成9个"""

import unittest
from TestProject.common.data_operation import DataOperation
from ddt import ddt, data
from TestProject.common.common_methods import CommonMethod
from time import sleep
from TestProject.common.log import Log
from TestProject.common.fileReader import IniUtil

# add_to_cart = [False, False, False, False, False, False, False, False, False]
# cart_detail = [False,False,False]
# cart_submit = False
# order_generate = False

evn = IniUtil().get_value_of_option('Env', 'env')


@unittest.skipIf(evn == 'prod', '生产环境跳过加购物车下单的测试用例')
@ddt
class TestCart(unittest.TestCase):
    """测试购物车"""
    @classmethod
    def setUpClass(cls):
        Log().info("""
        ====================================执行模块【购物车】=============================================
        """)
        cls.com = DataOperation('sup')
        # 登录
        cls.com.get_response("login")
Esempio n. 7
0
# coding=utf-8
"""kong接口通过性,1个接口,已完成1个"""

import unittest
from TestProject.common.log import Log
from TestProject.common.data_operation import DataOperation
from TestProject.common.fileReader import IniUtil

evn = IniUtil().get_value_of_option('host_test', 'b2c')


class testkongpass(unittest.TestCase):
    """获取access_token"""
    @classmethod
    def setUpClass(cls):
        Log().info(
            """======================获取access_token===================""")
        cls.com = DataOperation('b2c')  #定义cls.com
        #XXX
        cls.com.get_response("getToken")

    @classmethod
    def tearDownClass(cls):
        cls.com.close_session()

    def test_01_testKongPass(self):
        """测试kong通过性"""
        name = "testPass"  #接口名称
        result = self.com.get_result(name)
        self.assertEqual(True, result[0], result[1])