Beispiel #1
0
class Other(mytest.MyTokenTest):
    """其他模块相关"""

    # @unittest.skipIf(True, '调试不执行')
    @data(*get_test_case_data(data_info, 'other'))
    def test_api(self, data):
        logger.info(data)
        method = data['method']
        url = self.url + data['url']
        send_data = data['send_data']
        assert_info = data['assert_info']
        rownum = data['rownum']
        logger.info(self.headers)
        if method == 'post':
            r = SendRequest().send_json_post(url=url,
                                             dict=send_data,
                                             header=self.headers)
        if method == 'get':
            r = SendRequest().send_get_request(url=url, header=self.headers)
        # print('url:{}\r\nmethod:{}\r\nrequest_data:{}\r\nresponse:{}'.format(url,method, send_data, r))
        write_res(rownum, json.dumps(r, indent=2,
                                     ensure_ascii=False))  # 接口返回值写入表格
        self.assertEqual(r['status'],
                         assert_info['status'])  # 断言status==status
        self.assertEqual(r['info'], assert_info['info'])  # 断言info==info
Beispiel #2
0
class Other(mytest.MyTokenTest):
    """其他需要验证token的接口"""
    @data(*get_test_case_data(data_info, file, 'other'))
    def test_api(self, data):
        r = self.send_requests.send_request_all(data)
        assert_info = data['assert_info']
        self.assertEqual(r['code'], assert_info['code'])
        self.assertEqual(r['msg'], assert_info['msg'])
Beispiel #3
0
class Login(mytest.MyTest):
    """登录模块"""
    @data(*get_test_case_data(data_info, file, 'login'))
    def test_login(self, data):
        "登录接口"
        r = self.send_requests.send_request_all(data)
        assert_info = data['assert_info']
        self.assertEqual(r['code'], assert_info['code'])
        self.assertEqual(r['msg'], assert_info['msg'])
Beispiel #4
0
class Other(mytest.MyTokenTest):
    """其他需要验证token的接口"""

    @data(*get_test_case_data(data_info, 'other'))
    def test_api(self, data):
        method = data['method']
        url = self.url + '/api' + data['url']
        send_data = data['send_data']
        assert_info = data['assert_info']
        logger.info(self.headers)
        if method == 'post':
            r = SendRequest().send_json_post(url=url, dict=send_data, header=self.headers)
        if method == 'get':
            r = SendRequest().send_get_request(url=url,header=self.headers)
        self.assertEqual(r['code'], assert_info['code'])
        self.assertEqual(r['msg'], assert_info['msg'])
Beispiel #5
0
class Login(mytest.MyTest):
    """登陆模块"""

    @data(*get_test_case_data(data_info, 'login'))
    def test_login(self, data):
        "登陆接口"
        method = data['method']
        url = self.url + data['url']
        send_data = data['send_data']
        assert_info = data['assert_info']
        logger.info(url)
        logger.info(send_data)
        logger.info(self.headers)
        if method == 'post':
            r = SendRequest().send_json_post(url=url, dict=send_data, header=self.headers)
        if method == 'get':
            r = SendRequest().send_get_request(url=url,header=self.headers)
        self.assertEqual(r['code'], assert_info['code'])
        self.assertEqual(r['msg'], assert_info['msg'])
Beispiel #6
0
class Other(mytest.MyTokenTest):
    """其他需要验证token的接口"""
    @data(*get_test_case_data(data_info, 'other'))
    def test_api(self, data):
        logger.info(data)
        method = data['method']
        url = self.url + data['url']
        logger.info(url)
        send_data = data['send_data']
        assert_info = data['assert_info']
        rownum = data['rownum']
        if method == 'post':
            r = SendRequest().send_json_post(url=url,
                                             dict=send_data,
                                             header=self.headers)
        if method == 'get':
            r = SendRequest().send_get_request(url=url, header=self.headers)
        logger.info(r)
        # print('url:{}\r\nmethod:{}\r\nrequest_data:{}\r\nresponse:{}'.format(url,method, send_data, r))
        write_res(rownum, json.dumps(r, indent=2, ensure_ascii=False))
        self.assertEqual(r['code'], assert_info['code'])
        self.assertEqual(r['msg'], assert_info['msg'])
Beispiel #7
0
class Login(mytest.MyTest):
    """登陆模块"""
    @data(*get_test_case_data(data_info, 'login'))
    def test_login(self, data):
        "登陆接口"
        method = data['method']
        url = self.url + data['url']
        send_data = data['send_data']
        assert_info = data['assert_info']
        rownum = data['rownum']
        # logger.info(url)
        # logger.info(send_data)
        # logger.info(self.headers)
        if method == 'post':
            r = SendRequest().send_json_post(url=url,
                                             dict=send_data,
                                             header=self.headers)
        if method == 'get':
            r = SendRequest().send_get_request(url=url, header=self.headers)
        # print('url:{}\r\nmethod:{}\r\nrequest_data:{}\r\nresponse:{}'.format(url,method, send_data, r))
        write_res(rownum, json.dumps(r, indent=2, ensure_ascii=False))
        self.assertEqual(r['code'], assert_info['code'])
        self.assertEqual(r['msg'], assert_info['msg'])
Beispiel #8
0
class Product(mytest.MyTokenTest):
    """设备产品模块的接口"""
    @data(*get_test_case_data(data_info, 'add_product'))
    def test_001_add_project(self, data):
        method = data['method']
        url = data['url']
        url = self.url + url
        code = fake_en.word() + str(random.randint(1, 1000))
        name = fake.word() + str(random.randint(1, 1000)) + '- 产品'
        send_data = data["send_data"]
        send_data = self.replace_dict(send_data, '#code', code)
        send_data = self.replace_dict(send_data, '#name', name)
        assert_info = data['assert_info']
        rownum = data['rownum']
        # logger.info(self.headers)
        if method == 'post':
            r = SendRequest().send_json_post(url=url,
                                             dict=send_data,
                                             header=self.headers)
        if method == 'get':
            r = SendRequest().send_get_request(url=url, header=self.headers)
        # print('url:{}\r\nmethod:{}\r\nrequest_data:{}\r\nresponse:{}'.format(url,method, send_data, r))
        write_res(rownum, json.dumps(r, indent=2, ensure_ascii=False))  # 写入返回值
        self.assertEqual(r['code'], assert_info['code'])
        self.assertEqual(r['msg'], assert_info['msg'])

    @data(*get_test_case_data(data_info, 'get_product_list'))
    def test_002_get_product_list(self, data):
        method = data['method']
        url = data['url']
        url = self.url + url
        assert_info = data['assert_info']
        send_data = data['send_data']
        rownum = data['rownum']
        # logger.info(self.headers)
        if method == 'post':
            r = SendRequest().send_json_post(url=url,
                                             dict=send_data,
                                             header=self.headers)
        if method == 'get':
            r = SendRequest().send_get_request(url=url, header=self.headers)
        # print('url:{}\r\nmethod:{}\r\nrequest_data:{}\r\nresponse:{}'.format(url,method, send_data, r))
        write_res(rownum, json.dumps(r, indent=2, ensure_ascii=False))  # 写入返回值
        self.assertEqual(r['code'], assert_info['code'])
        self.assertEqual(r['msg'], assert_info['msg'])

    @data(*get_test_case_data(data_info, 'get_product_detail'))
    def test_003_get_product_detail(self, data):
        method = data['method']
        url = data['url']
        rely_num = data['rely_num']  # 依赖接口所在行数
        res_data = get_specific_num(num=rely_num[0] - 1)  # 找到对应行数,取出依赖接口返回值
        # logger.info(res_data)
        product_id = res_data['data'][0]['id']  # 取出依赖Id
        url = self.url + url + product_id  # 组成Url
        send_data = data['send_data']
        assert_info = data['assert_info']
        rownum = data['rownum']
        # logger.info(self.headers)
        if method == 'post':
            r = SendRequest().send_json_post(url=url,
                                             dict=send_data,
                                             header=self.headers)
        if method == 'get':
            r = SendRequest().send_get_request(url=url, header=self.headers)
        # print('url:{}\r\nmethod:{}\r\nrequest_data:{}\r\nresponse:{}'.format(url,method, send_data, r))
        write_res(rownum, json.dumps(r, indent=2, ensure_ascii=False))  # 写入返回值
        self.assertEqual(r['code'], assert_info['code'])
        self.assertEqual(r['msg'], assert_info['msg'])

    @data(*get_test_case_data(data_info, 'enable_product'))
    def test_004_enable_product(self, data):
        method = data['method']
        url = data['url']
        send_data = data['send_data']
        rely_num = data['rely_num']  # 依赖接口所在行数
        res_data = get_specific_num(num=rely_num[0] - 1)  # 找到对应行数,取出依赖接口返回值
        # logger.info(res_data)
        project_id = res_data['data'][0]['id']  # 取出依赖Id
        url = self.url + url + project_id  # 组成Url
        assert_info = data['assert_info']
        rownum = data['rownum']
        # logger.info(self.headers)
        if method == 'post':
            r = SendRequest().send_json_post(url=url,
                                             dict=send_data,
                                             header=self.headers)
        if method == 'get':
            r = SendRequest().send_get_request(url=url, header=self.headers)
        # print('url:{}\r\nmethod:{}\r\nrequest_data:{}\r\nresponse:{}'.format(url,method, send_data, r))
        write_res(rownum, json.dumps(r, indent=2, ensure_ascii=False))  # 写入返回值
        self.assertEqual(r['code'], assert_info['code'])
        self.assertEqual(r['msg'], assert_info['msg'])

    @data(*get_test_case_data(data_info, 'get_category_list'))
    def test_005_get_category_list(self, data):
        method = data['method']
        url = data['url']
        send_data = data['send_data']
        rely_num = data['rely_num']  # 依赖接口所在行数
        res_data = get_specific_num(num=rely_num[0] - 1)  # 找到对应行数,取出依赖接口返回值
        # logger.info(res_data)
        industry_id = res_data['data'][0]['id']  # 取出依赖Id
        url = self.url + url + industry_id  # 组成Url
        assert_info = data['assert_info']
        rownum = data['rownum']
        # logger.info(self.headers)
        if method == 'post':
            r = SendRequest().send_json_post(url=url,
                                             dict=send_data,
                                             header=self.headers)
        if method == 'get':
            r = SendRequest().send_get_request(url=url, header=self.headers)
        # print('url:{}\r\nmethod:{}\r\nrequest_data:{}\r\nresponse:{}'.format(url,method, send_data, r))
        write_res(rownum, json.dumps(r, indent=2, ensure_ascii=False))  # 写入返回值
        self.assertEqual(r['code'], assert_info['code'])
        self.assertEqual(r['msg'], assert_info['msg'])

    @data(*get_test_case_data(data_info, 'get_category_ids'))
    def test_006_get_categoryids(self, data):
        method = data['method']
        url = data['url']
        send_data = data['send_data']
        rely_num = data['rely_num']  # 依赖接口所在行数
        res_data = get_specific_num(num=rely_num[0] - 1)  # 找到对应行数,取出依赖接口返回值
        # logger.info(res_data)
        category_ids = res_data['data'][0]['id']  # 取出依赖Id
        url = self.url + url + category_ids  # 组成Url
        assert_info = data['assert_info']
        rownum = data['rownum']
        # logger.info(self.headers)
        if method == 'post':
            r = SendRequest().send_json_post(url=url,
                                             dict=send_data,
                                             header=self.headers)
        if method == 'get':
            r = SendRequest().send_get_request(url=url, header=self.headers)
        # print('url:{}\r\nmethod:{}\r\nrequest_data:{}\r\nresponse:{}'.format(url,method, send_data, r))
        write_res(rownum, json.dumps(r, indent=2, ensure_ascii=False))  # 写入返回值
        self.assertEqual(r['code'], assert_info['code'])
        self.assertEqual(r['msg'], assert_info['msg'])

    @data(*get_test_case_data(data_info, 'save_functions'))
    def test_007_save_functions(self, data):
        method = data['method']
        url = data['url']
        send_data = data['send_data']
        rely_num = data['rely_num']  # 依赖接口所在行数
        product_list_data = get_specific_num(num=rely_num[0] -
                                             1)  # 找到对应行数,取出依赖接口返回值
        # logger.info(res_data)
        product_id = product_list_data['data'][0]['id']  # 取出依赖Id
        categoryids = get_specific_num(num=rely_num[1] - 1)
        normal = [categoryids['data'][0]['id']]
        lis = [product_id, normal]
        keys = ['#id', '#normal']
        for i in range(len(lis)):
            send_data = self.replace_dict(send_data, keys[i], lis[i])
        url = self.url + url
        assert_info = data['assert_info']
        rownum = data['rownum']
        # logger.info(self.headers)
        if method == 'post':
            r = SendRequest().send_json_post(url=url,
                                             dict=send_data,
                                             header=self.headers)
        if method == 'get':
            r = SendRequest().send_get_request(url=url, header=self.headers)
        # print('url:{}\r\nmethod:{}\r\nrequest_data:{}\r\nresponse:{}'.format(url,method, send_data, r))
        write_res(rownum, json.dumps(r, indent=2, ensure_ascii=False))  # 写入返回值
        self.assertEqual(r['code'], assert_info['code'])
        self.assertEqual(r['msg'], assert_info['msg'])
class Project(mytest.MyTokenTest):
    """项目管理模块的接口"""
    @data(*get_test_case_data(data_info, file, 'add_curriculum'))
    def test_001_add_curriculum(self, data):
        r = self.send_requests.send_request_all(data)
        assert_info = data['assert_info']
        self.assertEqual(r['code'], assert_info['code'])
        self.assertEqual(r['msg'], assert_info['msg'])

    @data(*get_test_case_data(data_info, file, 'get_curriculum_all'))
    def test_002_get_curriculum_all(self, data):
        r = self.send_requests.send_request_all(data)
        assert_info = data['assert_info']
        self.assertEqual(r['code'], assert_info['code'])
        self.assertEqual(r['msg'], assert_info['msg'])

    @data(*get_test_case_data(data_info, file, 'get_curriculum_detail'))
    def test_003_get_curriculum_detail(self, data):
        r = self.send_requests.send_request_all(data)
        assert_info = data['assert_info']
        self.assertEqual(r['code'], assert_info['code'])
        self.assertEqual(r['msg'], assert_info['msg'])

    @data(*get_test_case_data(data_info, file, 'rm_curriculum'))
    def test_003_rm_curriculum(self, data):
        r = self.send_requests.send_request_all(data)
        assert_info = data['assert_info']
        self.assertEqual(r['code'], assert_info['code'])
        self.assertEqual(r['msg'], assert_info['msg'])

    @data(*get_test_case_data(data_info, file, 'delete_curriculum'))
    def test_004_delete_curriculum(self, data):
        r = self.send_requests.send_request_all(data)
        assert_info = data['assert_info']
        self.assertEqual(r['code'], assert_info['code'])
        self.assertEqual(r['msg'], assert_info['msg'])

    @data(*get_test_case_data(data_info, file, 'upload'))
    def test_005_upload(self, data):
        self.headers = None
        url = data['url']
        rely_num = data['rely_num']  # 依赖接口名称
        rely_parameter = data['rely_parameter']  # 依赖接口参数
        keys = data['update_data']
        values = finddata(case_name=rely_num, rely_parameter=rely_parameter)
        k_v_list = self.send_requests.construct_dict(keys, values)
        send_data = data['send_data']
        send_data = self.send_requests.update_data2(send_data, [k_v_list])
        rownum = data['rownum']
        r = self.send_requests.send_file_data(
            url=url,
            dict=send_data,
            file_name={"file": ("img", open(r"D:/6.png", "rb"), "img/png")})
        write_res(rownum, json.dumps(r, indent=2, ensure_ascii=False))  # 写入返回值
        self.assertTrue('hash' in json.dumps(r, indent=2, ensure_ascii=False))
        self.assertTrue('key' in json.dumps(r, indent=2, ensure_ascii=False))

    @data(*get_test_case_data(data_info, file, 'form_data_login'))
    def test_006_upload(self, data):
        r = self.send_requests.send_request_all(data)

    @data(*get_test_case_data(data_info, file, 'application_login'))
    def test_007_application_login(self, data):
        r = self.send_requests.send_request_all(data)
Beispiel #10
0
class Project(mytest.MyTokenTest):
    """项目管理模块的接口"""
    @data(*get_test_case_data(data_info, 'add_curriculum'))
    def test_001_add_curriculum(self, data):
        label = fake.word()  # 生成随机课程名称
        name = "脚本修改" + fake.word() + str(random.randint(
            1, 1000)) + "课程"  # 生成随机Name  # 生成随机课程标签
        objector = fake.word()  # 生成随机目标学员
        income = fake.sentence(nb_words=6, variable_nb_words=True)  # 生成随机学习目标
        intro = fake.sentence(nb_words=6, variable_nb_words=True)  # 生成随机课程综述
        keys = ["num1", "num2", "num3", "num4", "num5"]
        values = [label, name, objector, income, intro]

        k_v_list = [self.send_requests.construct_dict(keys, values)]
        r = self.send_requests.send_request_all(data,
                                                random_parameters=k_v_list)
        assert_info = data['assert_info']
        self.assertEqual(r['code'], assert_info['code'])
        self.assertEqual(r['msg'], assert_info['msg'])

    @data(*get_test_case_data(data_info, 'get_curriculum_all'))
    def test_002_get_curriculum_all(self, data):
        r = self.send_requests.send_request_all(data)
        assert_info = data['assert_info']
        self.assertEqual(r['code'], assert_info['code'])
        self.assertEqual(r['msg'], assert_info['msg'])

    @data(*get_test_case_data(data_info, 'rm_curriculum'))
    def test_003_rm_curriculum(self, data):
        r = self.send_requests.send_request_all(data)
        assert_info = data['assert_info']
        self.assertEqual(r['code'], assert_info['code'])
        self.assertEqual(r['msg'], assert_info['msg'])

    @data(*get_test_case_data(data_info, 'delete_curriculum'))
    def test_004_delete_curriculum(self, data):
        r = self.send_requests.send_request_all(data)
        assert_info = data['assert_info']
        self.assertEqual(r['code'], assert_info['code'])
        self.assertEqual(r['msg'], assert_info['msg'])

    @data(*get_test_case_data(data_info, 'upload'))
    def test_005_upload(self, data):
        self.headers = None
        url = data['url']
        rely_num = data['rely_num']  # 依赖接口名称
        rely_parameter = data['rely_parameter']  # 依赖接口参数
        keys = data['update_data']
        values = finddata(case_name=rely_num, rely_parameter=rely_parameter)
        k_v_list = self.send_requests.construct_dict(keys, values)
        send_data = data['send_data']
        send_data = self.send_requests.update_data2(send_data, [k_v_list])
        rownum = data['rownum']
        r = self.send_requests.send_file_data(
            url=url,
            dict=send_data,
            file_name={"file": ("img", open(r"D:/6.png", "rb"), "img/png")})
        write_res(rownum, json.dumps(r, indent=2, ensure_ascii=False))  # 写入返回值
        self.assertTrue('hash' in json.dumps(r, indent=2, ensure_ascii=False))
        self.assertTrue('key' in json.dumps(r, indent=2, ensure_ascii=False))

    @data(*get_test_case_data(data_info, 'form_data_login'))
    def test_006_upload(self, data):
        r = self.send_requests.send_request_all(data)

    @data(*get_test_case_data(data_info, 'application_login'))
    def test_007_application_login(self, data):
        r = self.send_requests.send_request_all(data)
Beispiel #11
0
class Project(mytest.MyTokenTest):
    """项目管理模块的接口"""
    @data(*get_test_case_data(data_info, 'add_curriculum'))
    def test_001_add_curriculum(self, data):
        method = data['method']
        url = self.url + data['url']
        # logger.info(url)
        label = fake.word()  # 生成随机课程名称
        name = "脚本修改" + fake.word() + str(random.randint(
            1, 1000)) + "课程"  # 生成随机Name  # 生成随机课程标签
        objector = fake.word()  # 生成随机目标学员
        income = fake.sentence(nb_words=6, variable_nb_words=True)  # 生成随机学习目标
        intro = fake.sentence(nb_words=6, variable_nb_words=True)  # 生成随机课程综述
        lis = [label, name, objector, income, intro]
        keys = ['#label', '#name', '#objector', '#income', '#intro']
        send_data = data["send_data"]
        for i in range(5):
            send_data = self.replace_dict(send_data, keys[i], lis[i])  # 替换请求值
        # logger.info(send_data)
        assert_info = data['assert_info']
        rownum = data['rownum']  # 获取当前接口所在行数
        # logger.info(self.headers)
        if method == 'post':
            r = SendRequest().send_json_post(url=url,
                                             dict=send_data,
                                             header=self.headers)
        if method == 'get':
            r = SendRequest().send_get_request(url=url, header=self.headers)
        # print('url:{}\r\nmethod:{}\r\nrequest_data:{}\r\nresponse:{}'.format(url,method, send_data, r))
        write_res(rownum, json.dumps(r, indent=2, ensure_ascii=False))  # 写入返回值
        self.assertEqual(r['code'], assert_info['code'])
        self.assertEqual(r['msg'], assert_info['msg'])

    @data(*get_test_case_data(data_info, 'rm_curriculum'))
    def test_002_rm_curriculum(self, data):
        method = data['method']
        url = self.url + data['url']
        # logger.info(url)
        rely_num = data['rely_num']  # 依赖接口所在行数
        res_data = get_specific_num(num=rely_num[0] - 1)  # 找到对应行数,取出依赖接口返回值
        # logger.info(res_data)
        curriculum_id = res_data['data']['id']  # 取出依赖Id
        send_data = data['send_data']
        send_data = self.replace_dict(send_data, '#curriculum_id',
                                      curriculum_id)
        # logger.info(send_data)
        assert_info = data['assert_info']
        rownum = data['rownum']
        # logger.info(self.headers)
        if method == 'post':
            r = SendRequest().send_json_post(url=url,
                                             dict=send_data,
                                             header=self.headers)
        if method == 'get':
            r = SendRequest().send_get_request(url=url, header=self.headers)
        # print('url:{}\r\nmethod:{}\r\nrequest_data:{}\r\nresponse:{}'.format(url,method, send_data, r))
        write_res(rownum, json.dumps(r, indent=2, ensure_ascii=False))  # 写入返回值
        self.assertEqual(r['code'], assert_info['code'])
        self.assertEqual(r['msg'], assert_info['msg'])

    @data(*get_test_case_data(data_info, 'delete_curriculum'))
    def test_003_delete_curriculum(self, data):
        method = data['method']
        url = self.url + data['url']
        # logger.info(url)
        rely_num = data['rely_num']  # 依赖接口所在行数
        res_data = get_specific_num(num=rely_num[0] - 1)  # 找到对应行数,取出依赖接口返回值
        # logger.info(res_data)
        curriculum_id = res_data['data']['id']  # 取出依赖Id
        send_data = data['send_data']
        send_data = self.replace_dict(send_data, '#curriculum_id',
                                      curriculum_id)
        # logger.info(send_data)
        assert_info = data['assert_info']
        rownum = data['rownum']
        # logger.info(self.headers)
        if method == 'post':
            r = SendRequest().send_json_post(url=url,
                                             dict=send_data,
                                             header=self.headers)
        if method == 'get':
            r = SendRequest().send_get_request(url=url, header=self.headers)
        # print('url:{}\r\nmethod:{}\r\nrequest_data:{}\r\nresponse:{}'.format(url,method, send_data, r))
        write_res(rownum, json.dumps(r, indent=2, ensure_ascii=False))  # 写入返回值
        self.assertEqual(r['code'], assert_info['code'])
        self.assertEqual(r['msg'], assert_info['msg'])