Beispiel #1
0
    def GetGroupManagerId(self):
        """
        获取用户组ID
        :return:
        """
        self.get_url = common.get_url_from_xml('testGetGroupManager')
        configHttp.set_url(self.get_url)
        # print(self.get_url)

        # set headers
        cookie = str(self.cookie)
        header = {"Cookie": cookie}
        configHttp.set_headers(header)

        # test interface
        self.return_json = configHttp.post()
        #判断登录超时
        if self.return_json.json() == 4:
            businessCommon.login()
            # 重新设置cookie
            self.newcookie = localReadConfig.get_headers('cookie')
            # set headers
            newcookie = str(self.newcookie)
            header = {"Cookie": newcookie}
            configHttp.set_headers(header)
            # 重新请求
            self.return_json = configHttp.post()
        # self.info = self.return_json.json()
        self.message = self.return_json.json()
        try:
            self.newid = self.message['data']['list'][-1]['id']
            return self.newid
        except IndexError:
            self.log.build_case_line(self.case_name, self.code, '用户组不存在')
    def testEditStudent(self):
        """
        编辑学生
        :param self:
        :return:
        """
        self.getStudentId()
        self.get_url = common.get_url_from_xml('editStudent')
        configHttp.set_url(self.get_url)

        # 设置请求头
        cookie = str(self.cookie)
        header = {'cookie': cookie}
        configHttp.set_headers(header)

        # set data
        data = {"pageNum": 1, "pageSize": 10}
        configHttp.set_data(data)

        # 测试接口
        self.return_json = configHttp.post()
        # 登录超时则重新调用登录
        if self.return_json.json()['code'] == 4:
            businessCommon.login()
            # 重新设置cookie
            self.newcookie = localReadConfig.get_headers('cookie')
            # set headers
            newcookie = str(self.newcookie)
            header = {"Cookie": newcookie}
            configHttp.set_headers(header)
            # 重新请求
            self.return_json = configHttp.post()

        self.info = self.return_json.json()
    def getGrade(self):
        """
        获取班级年级ID
        :return:
        """
        self.get_url = common.get_url_from_xml("getGrade")
        configHttp.set_url(self.get_url)

        #设置请求头
        cookie = str(self.cookie)
        header = {"cookie": cookie}
        configHttp.set_headers(header)

        #发送请求
        self.return_json = configHttp.post()
        # 登录超时则重新调用登录
        if self.return_json.json()['code'] == 4:
            businessCommon.login()
            # 重新设置cookie
            self.newcookie = localReadConfig.get_headers('cookie')
            # set headers
            newcookie = str(self.newcookie)
            header = {"Cookie": newcookie}
            configHttp.set_headers(header)
            # 重新请求
            self.return_json = configHttp.post()
Beispiel #4
0
    def testGetGrade(self):
        """
        获取班级ID并写入excel
        :return:
        """
        self.get_url = common.get_url_from_xml('getGrade')
        configHttp.set_url(self.get_url)

        #设置请求头
        cookie = str(self.cookie)
        header = {'cookies': cookie}
        configHttp.set_headers(header)

        #set data
        data = {}
        configHttp.set_data(data)

        #test interface
        self.return_json = configHttp.post()
        # 登录超时则重新调用登录
        if self.return_json.json()['code'] == 4:
            businessCommon.login()
            # 重新设置cookie
            self.newcookie = localReadConfig.get_headers('cookie')
            # set headers
            newcookie = str(self.newcookie)
            header = {"Cookie": newcookie}
            configHttp.set_headers(header)
            # 重新请求
            self.return_json = configHttp.post()

        self.info = self.return_json.json()

        #判断请求是否成功
        if self.info['code'] == 0:
            self.assertEqual(self.info['code'], self.code)
            self.assertEqual(self.info['msg'], self.msg)
            #判断返回的gradeId是否为空,不为空则写入excel
            self.allGrade = self.info['data']
            if len(self.allGrade) != 0:
                for i in range(len(self.allGrade)):
                    self.gradeId.append(self.allGrade[i]['id'])
                    # print(self.gradeId)
                common.write_xls('saveData.xls', 'grade', self.gradeId,
                                 'gradeId')
            else:
                self.log.build_case_line(self.case_name, self.code,
                                         'the Grade is null')
        else:
            self.log.build_case_line(self.case_name, self.code,
                                     'the code doesn\'t exist')
    def testAddGroupManager(self):
        '''
        set url
        :return:
        '''
        self.url = common.get_url_from_xml('testAddGroupManager')
        configHttp.set_url(self.url)
        print(self.url)

        #set headers
        cookie = str(self.cookie)
        header = {"Cookie": cookie}
        # print(header)
        configHttp.set_headers(header)

        #set data
        data = {
            "id": self.newid,
            "name": self.name,
            "remarks": self.remarks,
            "authoritys": self.authoritys
        }
        configHttp.set_data(data)
        print('第三步:设置发送请求的参数')

        #test interface
        self.return_json = configHttp.post()
        #判断是否登录超时
        if self.return_json.json()['code'] == 4:
            #重新设置cookie
            businessCommon.login()
            #重新获取cookie
            # time.sleep(2)
            self.newcookie = localReadConfig.get_headers('cookie')
            # set headers
            newcookie = str(self.newcookie)
            header = {"Cookie": newcookie}
            configHttp.set_headers(header)
            #重新请求
            self.return_json = configHttp.post()

        self.url = self.return_json.url
        method = str(self.return_json.request
                     )[int(str(self.return_json.request).find('[')) +
                       1:int(str(self.return_json.request).find(']'))]
        print("第四步:发送请求\n\t\t请求方法:" + method)

        #check result
        self.checkResult()
Beispiel #6
0
    def setUp(self):
        """

        :return:
        """
        self.log = Log.MyLog.get_log()
        self.logger = self.log.get_logger()
        self.login_token = businessCommon.login()
    def getStudentId(self):
        '''
        获取学生ID
        :param self:
        :return:z
        '''
        self.get_url = common.get_url_from_xml('getStudentId')
        configHttp.set_url(self.get_url)

        # 设置请求头
        cookie = str(self.cookie)
        header = {'cookie': cookie}
        configHttp.set_headers(header)

        # set data
        data = {"pageNum": 1, "pageSize": 10}
        configHttp.set_data(data)

        # 测试接口
        self.returnMessage_json = configHttp.post()
        # 登录超时则重新调用登录
        if self.returnMessage_json.json()['code'] == 4:
            businessCommon.login()
            # 重新设置cookie
            self.newcookie = localReadConfig.get_headers('cookie')
            # set headers
            newcookie = str(self.newcookie)
            header = {"Cookie": newcookie}
            configHttp.set_headers(header)
            # 重新请求
            self.returnMessage_json = configHttp.post()

        self.info = self.returnMessage_json.json()

        self.studentMessage = self.info['data']['list'][0]
        # 判断列表是否有学生
        try:
            self.studentId = self.studentMessage['id']
            self.schoolCode = self.studentMessage['cardCode']
        except IndexError:
            self.log.build_case_line(self.case_name, self.code, '学生列表为空')
    def GetAccountId(self):
        '''
        获取用户
        :return:
        '''

        get_url = common.get_url_from_xml("getAccountManager")
        configHttp.set_url(get_url)

        #设置请求头
        cookie = str(self.cookie)
        header = {"Cookie": cookie}
        configHttp.set_headers(header)

        #设置data
        data = {"pageNum": self.pageNum, "pageSize": self.pageSize}
        configHttp.set_data(data)

        #test interface
        self.return_json = configHttp.post()
        # 登录超时判断
        if self.return_json.json() == 4:
            businessCommon.login()
            # 重新设置cookie
            self.newcookie = localReadConfig.get_headers('cookie')
            # set headers
            newcookie = str(self.newcookie)
            header = {"Cookie": newcookie}
            configHttp.set_headers(header)
            # 重新请求
            self.return_json = configHttp.post()

        self.message = self.return_json.json()

        #获取用户id
        try:
            self.userId = str(self.message['data']['list'][0]['id'])
            return self.userId
        except IndexError:
            self.log.build_case_line(self.case_name, self.code, '用户不存在')
Beispiel #9
0
    def testAddStudent(self):
        """
        set url
        :return:
        """
        self.url = common.get_url_from_xml('testAddStudent')
        configHttp.set_url(self.url)

        #set headers
        cookie = str(self.cookie)
        header = {"Cookie": cookie}
        configHttp.set_headers(header)

        #set data
        data = {
            "name": self.name,
            "schoolCode": self.schoolCode,
            "schoolNumber": self.schoolNumber,
            "startDate": self.startDate,
            "gradeId": self.gradeId,
            "classId": self.classId,
            "address": self.address
        }
        configHttp.set_data(data)

        #test interface
        self.return_json = configHttp.post()

        #判断是否登录超时,超时重新登录
        if self.return_json.json()['code'] == 4:
            businessCommon.login()
            # 重新设置cookie
            self.newcookie = localReadConfig.get_headers('cookie')
            newcookie = str(self.newcookie)
            header = {"Cookie": newcookie}
            configHttp.set_headers(header)
            # 重新请求
            self.return_json = configHttp.post()

        self.checkResult()
    def testGetList(self):
        """
        set url
        :return:
        """
        self.url = self.parameter
        print(self.url)
        configHttp.set_url(self.url)

        #set header
        cookie = str(self.cookie)
        header = {"Cookie": cookie}
        configHttp.set_headers(header)

        #判断页数是否为空,为空则data为空
        #区别最后一个接口,不带参数
        if self.pageNum == '':
            data = {}
            configHttp.set_data(data)
        else:
            data = {"pageNum": self.pageNum, "pageSize": self.pageSize}
            configHttp.set_data(data)

        #test interface
        self.return_json = configHttp.post()

        #判断cookie是否失效
        if self.return_json.json()['code'] == 4:
            businessCommon.login()
            # 重新设置cookie
            self.newcookie = localReadConfig.get_headers('cookie')
            newcookie = str(self.newcookie)
            header = {"Cookie": newcookie}
            configHttp.set_headers(header)
            # 重新请求
            self.return_json = configHttp.post()

        self.checkResult()
    def GetGroup(self):
        '''
        获取用户组列表
        :return:
        '''
        get_url = common.get_url_from_xml('testGetAllGroup')
        configHttp.set_url(get_url)

        #设置请求头
        cookie = str(self.cookie)
        header = {"Cookie": cookie}
        configHttp.set_headers(header)

        # test interface
        self.return_json = configHttp.post()
        #登录超时判断
        if self.return_json.json()['code'] == 4:
            businessCommon.login()
            # 重新设置cookie
            self.newcookie = localReadConfig.get_headers('cookie')
            # set headers
            newcookie = str(self.newcookie)
            header = {"Cookie": newcookie}
            configHttp.set_headers(header)
            # 重新请求
            self.return_json = configHttp.post()
            print(self.return_json.json())

        self.message = self.return_json.json()


        #获取groupIds
        try:
            self.groupIds = self.message['data'][0]['id']
            return self.groupIds
        except IndexError:
            self.log.build_case_line(self.case_name, self.code, '用户组不存在')