Esempio n. 1
0
 def __init__(self,
              host=host,
              port=int(port),
              user=user,
              passwd=passwd,
              db=dbname):
     self.log = Log().getlog()
     self.host = host
     self.port = port
     self.user = user
     self.passwd = passwd
     self.db = db
Esempio n. 2
0
class TestOrganizationManage:
    log = Log().getlog()
    db = DB_config()
    data = get_test_data('../TestCaseData/organizeManage.yml', "tests1")
    data2 = get_test_data('../TestCaseData/organizeManage.yml', "test2")

    def setup_class(self):
        global_param.ALL_PARAM['CURRENTPAGE'] = 1
        global_param.ALL_PARAM['COMPANY_LIST'] = 1

    @allure.severity("normal")
    @pytest.mark.parametrize("case,http,expected", data[1], ids=data[0])
    @allure.story("XX用例集合")
    @allure.title("{case}")
    def test_getCompanyList(self, env, loginAdmin_session, case, http,
                            expected):
        self.log.info("用例名称:{}".format(case))
        url = env['adminurl'] + http['path']
        reqData = GetReqData().convert(http['data'])
        r = loginAdmin_session.sendRequest(url=url,
                                           methord=http['method'],
                                           headers=http['headers'],
                                           data=reqData)
        response = r.json()
        assert assertResult(expected, response)
Esempio n. 3
0
class TestOrganizationManage2:
    log = Log().getlog()
    db = DB_config()
    data = get_test_data('../TestCaseData/organizeManage.yml', "tests1")
    caseids = data[0]
    casedata = list(data[1])


    data2 = get_test_data('../TestCaseData/organizeManage.yml', "test2")
    case2ids = data2[0]
    case2data = list(data2[1])
    def setup_class(self):
        self.base = loginAdmin(usr=Config().adminuser, pwd=Config().adminpwd)  # 用同一个登录成功后的session

    @pytest.mark.parametrize("casename,http,expected", casedata, ids=caseids)
    @allure.title("查看机构列表接口")
    def test_1(self, casename, http, expected):
        httpmethod = http['method']
        apipath = http['path']
        headers = http['headers']
        data = http['data']
        expected = expected['response']
        r = self.base.sendRequest(apipath, httpmethod, headers=headers, data=data)
        response = r.json()

        if expected.get('part_verify', None):
            assert response['page']['list'][0]['id'] == expected['part_verify']['id']
            assert response['page']['list'][0]['name'] == expected['part_verify']['name']
        # global_param.COMPANY_LISAT=response['page']['list']
        global_param.ALL_PARAM['companyList'] = response['page']['list']

    def test_2(self):
        # if global_param.COMPANY_LIST==None:
        #     pytest.skip("依赖接口的数据获取失败")
        # else:
        #     print(global_param.COMPANY_LIST)

        if global_param.ALL_PARAM.get('companyList', None) == None:
            pytest.skip("依赖接口的数据获取失败")
        else:
            print(global_param.ALL_PARAM.get('companyList'))

    # @pytest.mark.parametrize("casename,http,expected", casedata, ids=caseids)
    def test_3(self):
        # paramData=self.case2data[0][1]['data']['getdata']
        # if paramData.startswith("$") and paramData.endswith("$"):
        #     paramData=global_param.ALL_PARAM['companyList']
        # print(paramData)
        paramData=self.case2data[0][1]['data']['search']
        print(paramData)
        print(type(paramData))

        paramData=self.case2data[0][1]['data']['search2']
        print(paramData)
        print(type(paramData))
Esempio n. 4
0
class TestOrganizationManage:
    log = Log().getlog()
    db = DB_config()
    # test = Assertions()
    data = get_test_data('../TestCaseData/organizeManage.yml', "tests1")
    print(data)
    print(data[0])

    # caseids=data[0]
    # casedata=data[1]
    # print(casedata)
    def setup_class(self):
        self.base = loginAdmin(usr=Config().adminuser,
                               pwd=Config().adminpwd)  # 用同一个登录成功后的session
        # pass
    @allure.severity("normal")
    @pytest.mark.parametrize("casename,http,expected", data[1], ids=data[0])
    @allure.title("查看机构列表接口")
    def test_getCompanyList(self, casename, http, expected):
        # print(env)
        httpmethod = http['method']
        apipath = http['path']
        headers = http['headers']
        data = http['data']
        # sql=jsonpath.jsonpath(expected.get('verifty'), "$.sql")
        # print(sql)
        # if sql:print(expected.get('verifty').get("sql"))
        expected = expected['response']
        # data['search']=json.dumps(data['search'])
        r = self.base.sendRequest(apipath,
                                  httpmethod,
                                  headers=headers,
                                  data=data)
        response = r.json()
        # print(response)
        print(expected)

        #校验方法一
        # if expected.get('part_verify',None):
        #     assert response['page']['list'][0]['id']==expected['part_verify']['id']
        #     assert response['page']['list'][0]['name']==expected['part_verify']['name']
        # print('111111111111111111')

        #校验方法二,jsonpath
        for key, value in expected.items():
            print(key, value)
            if key.startswith("$") and not key.endswith("$"):
                print(expected[key], jsonpath.jsonpath(response, key)[0])
                assert expected[key] == jsonpath.jsonpath(response, key)[0]
            else:
                assert expected[key] == response[key]
Esempio n. 5
0
class DB_config:
    def __init__(self,
                 host=host,
                 port=int(port),
                 user=user,
                 passwd=passwd,
                 db=dbname):
        self.log = Log().getlog()
        self.host = host
        self.port = port
        self.user = user
        self.passwd = passwd
        self.db = db

    def connectDB(self):
        try:
            self.con = pymysql.connect(host=self.host,
                                       port=self.port,
                                       user=self.user,
                                       passwd=self.passwd,
                                       db=self.db,
                                       charset='utf8')
        except Exception as e:
            self.log.error("数据库连接失败%s" % e, exc_info=True)
        self.cur = self.con.cursor()

    def connectDB_otherdb(self, otherdbname):
        try:
            self.con = pymysql.connect(host=self.host,
                                       port=self.port,
                                       user=self.user,
                                       passwd=self.passwd,
                                       db=otherdbname,
                                       charset='gb2312')

        except Exception as e:
            self.log.error("数据库连接失败%s" % e, exc_info=True)
        self.cur = self.con.cursor()

    def excute_otherdb(self, sql, otherdbname):
        self.connectDB_otherdb(otherdbname)  # 连接不同的数据库名称
        try:
            self.cur.execute(sql)
            if 'INSERT' in sql.upper() or 'UPDATE' in sql.upper(
            ) or 'DELETE' in sql.upper():
                # print('需要进行commit操作')
                self.con.commit()
            else:
                pass
        except Exception as e:
            print('执行SQL语句失败', e)

    def excute(self, sql):
        self.connectDB()
        try:
            self.cur.execute(sql)
            if 'INSERT' in sql.upper() or 'UPDATE' in sql.upper(
            ) or 'DELETE' in sql.upper():
                # self.log.info('需要进行commit操作')
                self.con.commit()
            else:
                pass
        except Exception as e:
            print('执行SQL语句失败', e)

    def get_all(self):
        desc = self.cur.description
        print(desc)
        return self.cur.fetchall()

    def get_one(self):
        return self.cur.fetchone()

    def close(self):
        return self.con.close()

    def get_sqlResultDic(self):
        """
        组装sql语句结果成一个字典返回
        :return:
        """
        desc = self.cur.description
        keyList = []
        for key in desc:
            keyList.append(key[0])
        results = self.cur.fetchall()
        resultDic = []
        if results and results != ():
            for result in results:
                data = dict(zip(keyList, result))
                resultDic.append(data)
        return resultDic
Esempio n. 6
0
'''
@author: yanghong
@file: conftest.py
@time: 2020/7/23 11:56
@desc:
'''
import os

import pytest
from ruamel import yaml

from test.Common.DB import DB_config
from test.Common.Log import Log
from test.Common.base import Base

log = Log().getlog()


#钩子函数,用于用例执行时,打印用例名称到log
@pytest.hookimpl(hookwrapper=True, tryfirst=True)
def pytest_runtest_makereport():
    outcome = yield
    call_info = outcome.get_result()
    if call_info.when == 'setup':
        print(call_info.nodeid)
        log.info("当前运行的用例为:{}".format(call_info.nodeid.split("::")[-1]))


def pytest_addoption(parser):
    parser.addoption("--env",
                     action="store",