PCpublicMethods.py 5.82 KB

from atdd.PcPost import PcPost


class PCpublicMethods(PcPost):

    def setUp(self):
        self.do_login(self.host, self.mobile, self.psw, self.domain)

    # 岗位list——岗位管理页面
    def test_getJobList(self):
        interfaceUrl = "/Contact/Apicp/Job/List"
        data = {
            "page": 1,
            "limit": 10
        }
        r = self.PcPost(interfaceUrl,data)
        return r

    # 根据岗位名称获取岗位ID
    def getJobID(self, jobName):

        self.do_login(self.host, self.mobile, self.psw, self.domain)

        jobList = self.test_getJobList()['result']['list']
        for i in range(len(jobList)):
            if (jobList[i]['jobName'] == jobName):
                return jobList[i]['jobId']
        else:
            print("不存在'" + jobName + "'")


    #角色list——角色管理页面
    def test_getRoleList(self):
        interfaceUrl = "/Contact/Apicp/Role/List"
        data = {
            "page": 1,
            "limit": 10
        }
        r = self.PcPost(interfaceUrl,data)
        return r

    # 根据角色名称获取角色ID
    def getRoleID(self, roleName):

        self.do_login(self.host, self.mobile, self.psw, self.domain)

        roleList = self.test_getRoleList()['result']['list']
        for i in range(len(roleList)):
            if (roleList[i]['roleName'] == roleName):
                return roleList[i]['roleId']
        else:
            print("不存在'" + roleName + "'")


    # 获取员工的积分信息(组织、岗位、角色、积分等级。。。)-员工积分页面
    def getMemberInfo(self, memUsername):

        self.do_login(self.host, self.mobile, self.psw, self.domain)

        interfaceUrl = "/Integral/Apicp/Integral/MemberList"
        data = {
            "memUsername": memUsername
        }
        result = self.PcPost(interfaceUrl, data)
        return result


    #根据组织名字获取组织ID,返回组织ID
    def get_dpID(self,dpName):

        self.do_login(self.host, self.mobile, self.psw, self.domain)

        interfaceUrl = "/contact/Apicp/Department/Search"

        data = {
            "keyword": dpName
        }
        result = self.PcPost(interfaceUrl, data)
        dpId = result['result']['list'][0]['department_id']
        return dpId

    # 获取该员工组织的ID,以list格式返回
    def member_dpID(self):

        result = self.getMemberInfo("小红红")
        memberInfo = result['result']['list'][0]
        dpName = memberInfo['dpName']
        dpNameList = dpName.split(';')  #将字符串转化为数组

        dpIdList = []

        for i in range(len(dpNameList)):
            dpId = self.get_dpID(dpNameList[i]).split()
            # 将dpId加入到dpIdList中
            dpIdList[len(dpIdList):len(dpIdList)] = dpId

        return dpIdList


    # 积分策略:获取业务应用的触发行为的key和触发条件的key,并构造成字典
    # 参数:businessKey
    def getTriggerKey(self,businessKey):

        self.do_login(self.host, self.mobile, self.psw, self.domain)
        interfaceUrl = "/Integral/Apicp/Integral/DefaultList"
        data = {
            "businessKey": businessKey
        }
        r = self.PcPost(interfaceUrl, data)
        result = r['result']

        dictTriggersKey = {}  # 构造字典
        for i in range(len(result)):
            businessAct = result[i]['businessAct']  # 触发行为
            triggers = result[i]['triggers']  # 获得triggers数据
            triggerKeyList = []  # 清空上一条数组数据

            for j in range(len(triggers)):
                triggerKey = triggers[j]['triggerKey'].split()  # 获取单个key
                triggerKeyList[len(triggerKeyList):len(triggerKeyList)] = triggerKey  # 将单个key组成数组

            dictTriggersKey[businessAct] = triggerKeyList  #构造成字典

        return dictTriggersKey

    # 积分策略:获取业务应用的触发行为的value,并构造成字典
    # 参数:businessKey
    def getTriggerValue(self, businessKey):

        self.do_login(self.host, self.mobile, self.psw, self.domain)
        interfaceUrl = "/Integral/Apicp/Integral/DefaultList"
        data = {
            "businessKey": businessKey
        }
        r = self.PcPost(interfaceUrl, data)
        result = r['result']

        dictTriggersValue = {}  # 构造字典
        for i in range(len(result)):
            businessAct = result[i]['businessAct']  # 触发行为
            triggers = result[i]['triggers']  # 获得triggers数据
            for j in range(len(triggers)):
                triggerKey = triggers[j]['triggerKey']  # 获取单个key
                triggerValue = triggers[j]['triggerValue'] # 获取单个value
                triggerdic = businessAct + "-" + triggerKey
                dictTriggersValue[triggerdic] = triggerValue  #构造成字典
        return dictTriggersValue


    # 积分策略:获取业务应用的触发行为的limitConditions,并构造成字典
    # 参数:businessKey
    def getLimitConditions(self, businessKey):

        self.do_login(self.host, self.mobile, self.psw, self.domain)
        interfaceUrl = "/Integral/Apicp/Integral/DefaultList"
        data = {
            "businessKey": businessKey
        }
        r = self.PcPost(interfaceUrl, data)
        result = r['result']

        dictLimitConditions = {}  # 构造字典
        for i in range(len(result)):
            businessAct = result[i]['businessAct']  # 触发行为
            triggers = result[i]['triggers']  # 获得triggers数据
            for j in range(len(triggers)):
                triggerKey = triggers[j]['triggerKey']  # 获取单个key
                limitConditions = triggers[j]['limitConditions'] # 获取单个value
                triggerdic = businessAct + "-" + triggerKey
                dictLimitConditions[triggerdic] = limitConditions  #构造成字典
        return dictLimitConditions