Example #1
0
    def setup_class(self):
        # todo:数据清理的过程,把测试数据清空或者还原

        # 还原数据库,如果可以还原数据库,那么测试用例中是可以使用一些变化的tagid。否则不要硬编码这些tagid,一旦数据被清空,tagid就会失效。
        # 使用接口去清理数据
        # 使用接口去构建测试数据

        self.tag = Tag()
        self.tag.get_token()
        self.tag.clear_all()
        self.update_index = 0
        print("update_index")
        print(self.update_index)
Example #2
0
class TestTag:
    def setup_class(self):
        self.tag = Tag()

    @pytest.mark.parametrize("tag_id,tag_name", [
        ['eteTbfCwAAkiQsjOWc6j8_oQCyF8-Xhw', 'tag1_new_'],
        ['eteTbfCwAAkiQsjOWc6j8_oQCyF8-Xhw', 'tag1中文'],
        ['eteTbfCwAAkiQsjOWc6j8_oQCyF8-Xhw', 'tag1[中文]']
    ])
    # 修改标签
    def test_tag(self, tag_id, tag_name):
        tag_name = tag_name + str(datetime.datetime.now().strftime("%Y%m%d%H%M%S"))

        r = self.tag.list()
        r = self.tag.update(tag_id, tag_name)
        r = self.tag.list()

        assert jsonpath(r.json(), f"$..[?(@.name=='{tag_name}')]")[0]['name'] == tag_name

    @pytest.mark.parametrize("group_name,tag", [
        ['testlc123', [{'name': '1'}, {'name': '2'}, {'name': '3'}]],
        ['test中文123', [{'name': '你好'}, {'name': 'hello'}, {'name': '你好hi'}]],
        ['test_中文123', [{'name': 'tag1[中文]'}, {'name': 'testliucheng'}]]
    ])
    # 添加用户
    def test_add(self, group_name, tag):
        # group_name = group_name + str(datetime.datetime.now().strftime("%Y%m%d%H%M%S"))
        r = self.tag.add(group_name, tag)
        assert r.status_code == 200
        assert r.json()['errcode'] == 0

    @pytest.mark.parametrize("group_name,tag", [
        ['testlc123', [{'name': '1'}, {'name': '2'}, {'name': '3'}]],
        ['test中文123', [{'name': '你好'}, {'name': 'hello'}, {'name': '你好hi'}]],
        ['test_中文123', [{'name': 'tag1[中文]'}, {'name': 'testliucheng'}]]
    ])
    # 添加用户
    def test_add_and_detect(self, group_name, tag):
        # group_name = group_name + str(datetime.datetime.now().strftime("%Y%m%d%H%M%S"))
        r = self.tag.add_and_detect(group_name, tag)
        assert r

    # 删除标签 通过tagid
    def test_delete_tagid(self):
        tag_id = ['eteTbfCwAAj5NKwvQi6K836Nac-KIcfA']
        r = self.tag.delete_tagid(tag_id)

    # 删除标签 通过groupid
    def test_delete_groupid(self):
        group_id = ['eteTbfCwAAyMz2fkubaFi-XbCwyM2OeQ']
        r = self.tag.delete_groupid(group_id)

    def test_delete_and_detect_group(self):
        r = self.tag.delete_and_detect_group(["eteTbfCwAAfN8_nUnj1hasyLJpPpYR6A"])
        assert r.json()['errcode'] == 0
Example #3
0
class TestTag():

    def setup_class(self):
        # 初始化Tag
        self.tag = Tag()
        # 拿到token
        self.tag.get_token()

    def test_tag_list(self):
        # 获取新列表 进行校验
        r = self.tag.list()
        assert r.status_code == 200
        assert r.json()['errcode'] == 0

    #参数化
    @pytest.mark.parametrize("group_name,tag_names",[
        ["group_demo_leemandy2",[{'name': 'tag_demo_leemandy2'}]],
        ["group_demo_leemandy2",[{'name': 'tag_demo_leemandy2'}]],
        ["group_demo_leemandy2",[{'name': 'tag_demo_leemandy2'},{'name': 'tag_demo_leemandy3'}]],

    ])
    def test_tag_add(self,group_name,tag_names):
        #增加标签组
        r= self.tag.add(group_name, tag_names)
        assert r.status_code == 200

        #python列表表达式
        #校验 找taggroup下面有没有新建的groupname
        group=[group for group in r.json()['tag_group'] if group['group_name'] == group_name][0]
        #校验 找taggroup下tag下的name是不是我刚刚新建的
        tags=[{'name':tag['name']} for tag in group['tag'] if tag['name']]
        print(group)
        print(tags)
        assert group['group_name'] == group_name
        assert tags == tag_names


    #tagname超过31个字符回会报错
    def test_tag_fail(self):
        pass

    @pytest.mark.parametrize("",[
        #删除单个标签
        #删除多个标签
        #删除不存在的标签
        #删除标签组
    ]

    )
    def test_tag_delete(self,group_id,tag_id):
        self.tag.delete()
Example #4
0
class TestTag:
    def setup(self):
        self.tag = Tag()

    #查询标签
    def test_list(self):
        r = self.tag.list()
        # print(r.json(),type(r.json()))
        assert r.json()['errcode'] == 0

    #更新标签
    @pytest.mark.parametrize("tag_id,tag_name",
                             get_datas()[0],
                             ids=get_datas()[1])
    def test_update_and_detect(self, tag_id, tag_name):
        tag_name = tag_name + str(
            datetime.datetime.now().strftime('%Y%m%d%H%M%S'))
        r = self.tag.update_and_detect(id=tag_id, tag_name=tag_name)
        assert r.json()['errcode'] == 0
        r = self.tag.list()
        print(r.json())
        assert jsonpath(r.json(),
                        f"$..[?(@.name=='{tag_name}')]")[0]['name'] == tag_name

    #添加标签
    @pytest.mark.parametrize('group_name,tag',
                             get_datas()[2],
                             ids=get_datas()[3])
    def test_add_and_detect(self, group_name, tag):
        r = self.tag.add_and_detect(group_name=group_name, tag=tag)
        assert r

    #删除标签组
    @pytest.mark.parametrize('group_id', get_datas()[4])
    def test_delete_and_detect_group(self, group_id):
        r = self.tag.delete_and_detect_group(group_id)
        print(r.json(), type(r.json()))
        assert r.json()['errcode'] == 0

    #删除标签
    @pytest.mark.parametrize('tag_id', get_datas()[5])
    def test_delete_and_detect_tag(self, tag_id):
        r = self.tag.delete_and_detect_tag(tag_id)
        assert r.json()['errcode'] == 0
Example #5
0
class TestTag:
    def setup_class(self):
        ##资源初始化
        self.tag = Tag()
        self.tagid = ''
        self.group_id = 'etWtwhEQAAX_WVyJDmfF_Nx3nX2al-Og'

    def teardown_class(self):
        ##资源恢复
        pass

    #
    # @pytest.mark.parametrize("tag_id,tag_name",[
    #                          ['etWtwhEQAAUZvpV2eI58HtpYFSBR5nuQ','ukulele']
    #                          ,['etWtwhEQAAUZvpV2eI58HtpYFSBR5nuQ','ukulele-中文']
    #                          ,['etWtwhEQAAUZvpV2eI58HtpYFSBR5nuQ','ukulele-  ']])
    RESULT_LINK = 'https://github.com/yanli27/TestFramwork'

    @pytest.mark.parametrize("tag_id,tag_name",
                             yaml.load(open('tag_par.yaml', 'r'),
                                       Loader=yaml.FullLoader))
    @allure.story("测试tag的编辑")
    @allure.testcase(RESULT_LINK, '链接')
    @allure.title("测试tag的编辑")
    def test_tag_edit(self, tag_id, tag_name):
        tagname = tag_name + str(
            datetime.datetime.now().strftime("%Y%m%d%H%M"))
        print('tagname', tagname)
        group_name = 'uku group'
        id = tag_id
        # r=self.tag.list()
        with allure.step("更新tagname"):
            r = self.tag.update(id, tagname)
        with allure.step("列出更新后的tag列表"):
            r = self.tag.list()

        tags = [
            tag for group in r.json()['tag_group']
            if group['group_name'] == group_name for tag in group['tag']
            if tag['name'] == tagname
        ]
        # print('tags',r.json()['tag_group'])
        with allure.step("判断是否更新成功"):
            assert tags != []
            assert jsonpath(
                r.json(), f"$..[?(@.name=='{tagname}')]")[0]['name'] == tagname
        newTagname = str(jsonpath(r.json(), f"$..[?(@.name=='{tagname}')]"))
        allure.attach('插入txt:' + newTagname,
                      'tag',
                      attachment_type=allure.attachment_type.TEXT)
        driver.get()

    @allure.story("测试tag的新增")
    def test_add_tag(self):
        group_name = 'uku group'
        tag1 = 'test add tag' + str(
            datetime.datetime.now().strftime("%Y%m%d%H%M"))
        tag2 = 'test add tag 2' + str(
            datetime.datetime.now().strftime("%Y%m%d%H%M"))
        tag3 = 'test add tag 3' + str(
            datetime.datetime.now().strftime("%Y%m%d%H%M"))
        tag = [
            {
                "name": tag1
            },
            {
                "name": tag2
            },
            {
                "name": tag3
            },
        ]
        self.tag.add(groupname=group_name, tag=tag)

    @allure.story("列出所有tags")
    def test_list(self):
        self.tag.list()

    @allure.story("删除tag")
    def test_delete_tag(self):
        r = self.tag.list(self.group_id)
        tags = [
            tag for group in r.json()['tag_group'] for tag in group['tag']
            if tag['deleted'] is False
        ]
        print(tags)
        self.tagid = tags[0]['id']
        # print(r.json()['tag_group'][0]['tag'][0])
        self.tag.delete(self.tagid)

    @allure.story('删除group')
    def test_delete_group(self):
        self.tag.delete_group(["etWtwhEQAAsSp0ujrSGTqYKqyfvkoxXA"])

    @allure.story('删除tag')
    def test_delete_tag(self):
        self.tag.delete_tag(["etWtwhEQAAvZrYlpgRWxYz2EClCL2jDg"])
Example #6
0
 def setup_class(self):
     ##资源初始化
     self.tag = Tag()
     self.tagid = ''
     self.group_id = 'etWtwhEQAAX_WVyJDmfF_Nx3nX2al-Og'
class TestClassic:
    def setup_class(self):
        self.tag = Tag()
        # r = self.tag.add()
        # self.tag_id = r.json()['tag_group']['tag']['id']

    @pytest.mark.parametrize('tag_id,name',
                             [['ettrhEDwAAJ68kxUxAVsQ8xwDCK5KOTg', 'tag_new'],
                              ['ettrhEDwAAGxx8807ekDQoSb1xd5-1Kw', '中文'],
                              ['ettrhEDwAA8zLl_-JiC5KSB0hADr1SgA', '你是']])
    def test_tag_list(self, tag_id, name):
        tag_name = name + str(datetime.datetime.now().strftime("%Y%m%d-%H%M"))
        group_name = '测试'
        self.tag.update(tag_id, tag_name)
        r = self.tag.list()
        print(json.dumps(r.json(), indent=2))
        tag = [
            tag for group in r.json()['tag_group']
            if group['group_name'] == group_name for tag in group['tag']
            if tag['name'] == tag_name
        ]
        print(tag)
        assert tag != []

    def test_clean(self):
        pass

    def test_get_list(self):
        self.tag.list()

    def test_add(self):
        r = self.tag.add()
        assert r.status_code == 200
        assert r.json()["errcode"] == 0

    def test_before_add(self):
        group_name = "test1111"
        tag = [{"name": "test1"}, {"name": "test2"}, {"name": "test3"}]
        r = self.tag.before_add(group_name, tag)
        assert r

    # 40068 invalid tagid
    # 删除的元素不存在
    def test_delete_group(self):
        group_id = "ettrhEDwAAVEzFZl-qf_FJtlwxN4ERLQ"
        self.tag.delete_group(group_id=group_id)

    def test_delete_id(self):
        tag_id = "ettrhEDwAAVEzFZl-qf_FJtlwxN4ERLQ"
        self.tag.delete_tag(tag_id=tag_id)

    def test_delete_and_detect_group(self):
        group_id = ["ettrhEDwAAloLp0iUKFO6kShc9C23-7w"]
        self.tag.delete_and_detect_group(group_id)
 def setup_class(self):
     self.tag = Tag()
Example #9
0
class TestTag:
    def setup_class(self):
        self.tag = Tag()
        self.id = {  # 收集测试中添加的标签id
            "tag_id": [],
            "group_id": []
        }

    def teardown_class(self):
        print(self.id)
        self.tag.del_corp_tag(**self.id)  # 脏数据清理

    # 测试获取企业标签库  获取所有标签组, 获取指定的单个/多个标签组, 获取不存在的标签组
    @pytest.mark.parametrize(
        "tag_id",
        [
            [],  # 获取所有标签列表
            ['et8PVGCwAAzOVONzSMrHPiAMuZEKn6RQ'],  # 获取单个指定标签列表
            [
                'et8PVGCwAApPvMzyD05Qxt1Xv3Uvj-lQ',
                'et8PVGCwAAN90CZElDC4_W9-be-Z4mQg'
            ],  # 获取多个指定标签列表
            ['xxxxxxxx']  # 获取不存在的标签列表
        ])
    def test_get_crop_tag_list(self, tag_id):
        r = self.tag.get_corp_tag_list(tag_id)
        try:
            assert r.json()['errcode'] == 0
        except Exception as e:
            print(f"{tag_id}不存在")

    # 测试添加企业客户标签  et8PVGCwAAXjEr618N44pHUPTodQ0Mhw
    @pytest.mark.parametrize(
        "group_name, tag_names, group_id, order",
        [
            ['test02', [{
                'name': 'tag01'
            }, {
                'name': 'tag02'
            }], None, None],  # 添加多个标签
            ['测试三组', [{
                'name': '#^*&%$(#'
            }], None, None],  # 特殊符号命名
            ['测试四组', [{
                'name': '不重要'
            }], 'et8PVGCwAAXjEr618N44pHUPTodQ0Mhw', 3],  # 指定标签组添加标签
            ['测试四组', [{
                'name': '不重要'
            }], 'et8PVGCwAAXjEr618N44pHUPTodQ0Mhw', 3],  # 重复添加
            [
                '超长名字超长名字超长名字超长名字超长名字超长名字超长名字超长', [{
                    'name': '#^*&%$(#'
                }], None, None
            ],
            ['测试三组', [{
                'name': '超长名字超长名字超长名字超长名字超长名字超长名字超长名字超长'
            }], None, None],
            [
                '超出限制超出限制超出限制超出限制超出限制超出限制超出限制超出限制', [{
                    'name': '#^*&%$(#'
                }], None, None
            ],
            [
                '测试三组', [{
                    'name': '超出限制超出限制超出限制超出限制超出限制超出限制超出限制超出限制'
                }], None, None
            ],
        ])
    def test_add_crop_tag(self, group_name, tag_names, group_id, order):
        r = self.tag.add_crop_tag(group_name, tag_names, group_id, order)
        # 添加请求返回的标签组名和标签名列表
        add_crop_tag_group_name = r.json()['tag_group']['group_name']
        add_crop_tag_tag_names = [
            name['name'] for name in r.json()['tag_group']['tag']
        ]
        # 添加请求返回的标签组id和标签id
        add_crop_tag_group_id = r.json()['tag_group']['group_id']
        add_crop_tag_tag_ids = [
            name['id'] for name in r.json()['tag_group']['tag']
        ]
        # 将id加入收集信息中
        self.id['group_id'].append(add_crop_tag_group_id)
        for name in add_crop_tag_tag_ids:
            self.id['tag_id'].append(name)
        # 重新请求获取标签列表
        r = self.tag.get_corp_tag_list()
        get_corp_tag_list_group_names = [
            group['group_name'] for group in r.json()['tag_group']
        ]
        get_corp_tag_list_tag_names = [
            tag['name'] for group in r.json()['tag_group']
            for tag in group['tag']
        ]
        assert add_crop_tag_group_name in get_corp_tag_list_group_names
        for name in add_crop_tag_tag_names:
            assert name in get_corp_tag_list_tag_names

    # 测试编辑企业客户标签
    @pytest.mark.parametrize(
        "tag_id, name, order",
        [
            ['et8PVGCwAAXjEr618N44pHUPTodQ0Mhw', None, None],  # 标签组id
            ['et8PVGCwAAzOVONzSMrHPiAMuZEKn6RQ', None, None],  # 标签id
            ['et8PVGCwAAXjEr618N44pHUPTodQ0Mhw', '标签组改名测试', None],
            ['et8PVGCwAAzOVONzSMrHPiAMuZEKn6RQ', '标签改名测试', None],
            ['et8PVGCwAAXjEr618N44pHUPTodQ0Mhw', '标签组改名测试', -99],  # 排序
            [
                'et8PVGCwAAzOVONzSMrHPiAMuZEKn6RQ',
                '超长名字超长名字超长名字超长名字超长名字超长名字超长名字超长', None
            ],
            ['et8PVGCwAAzOVONzSMrHPiAMuZEKn6RQ', '@#$%^&&*(()(*&*^%$', None],
            [
                'et8PVGCwAAzOVONzSMrHPiAMuZEKn6RQ',
                '超出限制超出限制超出限制超出限制超出限制超出限制超出限制超出限制', None
            ],
        ])
    def test_edit_corp_tag(self, tag_id, name, order):
        self.tag.edit_corp_tag(tag_id, name, order)
        r = self.tag.get_corp_tag_list()
        get_corp_tag_list_group_names = [
            group['group_name'] for group in r.json()['tag_group']
        ]
        get_corp_tag_list_tag_names = [
            tag['name'] for group in r.json()['tag_group']
            for tag in group['tag']
        ]
        assert name in get_corp_tag_list_group_names or name in get_corp_tag_list_tag_names

    # 测试删除企业客户标签
    @pytest.mark.parametrize(
        "id",
        [
            {},
            {
                'tag_id': ['et8PVGCwAAzOVONzSMrHPiAMuZEKn6RQ']
            },  # 删除单个标签
            {
                'tag_id': [
                    'et8PVGCwAAzOVONzSMrHPiAMuZEKn6RQ',
                    'et8PVGCwAA3Bj2gH1uNj51WMKCaL9q_w'
                ]
            },  # 删除多个标签
            {
                'group_id': ['et8PVGCwAAXjEr618N44pHUPTodQ0Mhw']
            },  # 删除单个标签组
            {
                'group_id': [
                    'et8PVGCwAAXjEr618N44pHUPTodQ0Mhw',
                    'et8PVGCwAA7hSN2dC_Jtdd2qY5mRVkaQ'
                ]
            },  # 删除多个标签组
            {
                'tag_id': ['et8PVGCwAA3Bj2gH1uNj51WMKCaL9q_w']
            },
            {
                'group_id': ['et8PVGCwAA7hSN2dC_Jtdd2qY5mRVkaQ']
            },
            {
                'tag_id': ['et8PVGCwAAzOVONzSMrHPiAMuZEKn6RQ']
            },  # 删除不存在的
        ])
    def test_del_corp_tag(self, id):
        print(id)
        if len(id.items()) == 0:
            print("tag_id 和 group_id 不可同时为空")
        else:
            r = self.tag.del_corp_tag(**id)
            assert r.json()['errcode'] == 0
Example #10
0
 def setup_class(self):
     self.tag = Tag()
     self.id = {  # 收集测试中添加的标签id
         "tag_id": [],
         "group_id": []
     }
Example #11
0
class TestTag:
    update_index_class=0

    def setup_class(self):
        # todo:数据清理的过程,把测试数据清空或者还原

        # 还原数据库,如果可以还原数据库,那么测试用例中是可以使用一些变化的tagid。否则不要硬编码这些tagid,一旦数据被清空,tagid就会失效。
        # 使用接口去清理数据
        # 使用接口去构建测试数据

        self.tag = Tag()
        self.tag.get_token()
        self.tag.clear_all()
        self.update_index = 0
        print("update_index")
        print(self.update_index)

    def test_tag_list(self):
        # todo: 完善功能测试
        r = self.tag.list()
        assert r.status_code == 200
        assert r.json()['errcode'] == 0

    @pytest.mark.parametrize("group_name, tag_names", [
        ["group_demo_1201", [{'name': 'tag_demo_1201'}]],
        ["group_demo_1202", [{'name': 'tag_demo_1202'}, {'name': 'tag_demo_1203'}]],
    ])
    def test_tag_add(self, group_name, tag_names):
        r = self.tag.add(group_name, tag_names)
        assert r.status_code == 200
        # assert r.json()['errcode'] == 0

        r = self.tag.list()
        assert r.status_code == 200
        assert r.json()['errcode'] == 0

        group = [group for group in r.json()['tag_group'] if group['group_name'] == group_name][0]
        tags = [{'name': tag['name']} for tag in group['tag']]
        print(group)
        print(tags)
        assert group['group_name'] == group_name
        assert tags == tag_names

    def test_tag_add_fail(self):
        pass

    @pytest.mark.parametrize("group_name, tag_names, need_group_id", [
        # 删除有效的单个标签
        ['group_delete_demo', [{'name': "tag_delete_demo_1"}], False],
        # 删除多个标签
        ['group_delete_demo', [{'name': "tag_delete_demo_2", 'name': "tag_delete_demo_3"}], False],
        # 删除整个组
        ['group_delete_demo', [{'name': 'tag_delete_demo_4'}], True],
        # 删除标签组,名字或者id
    ])
    def test_tag_delete(self, group_name, tag_names, need_group_id):
        self.tag.add(group_name, tag_names)
        r = self.tag.list()
        group = [group for group in r.json()['tag_group'] if group['group_name'] == group_name][0]
        tag_ids = [tag['id'] for tag in group['tag']]
        if need_group_id:
            group_id = group['group_id']
            tag_ids = None
        else:
            group_id = None

        self.tag.delete(group_id, tag_ids)
        r = self.tag.list()
        groups = [group for group in r.json()['tag_group'] if group['group_name'] == group_name]
        assert groups == []

    @pytest.mark.parametrize("name", [
        # 普通改名 加长
        'tag_test_update_name_1',
        # 缩短
        'tag_1',
        # 不变
        'tag_test_update_name',
        # 重名
        # 组名重名
        # 特殊字符

    ])
    def test_update_name(self, name):
        self.update_index += 1
        # doine: id一样 不要用实例变量就可以
        print(f"update_index={self.update_index}")
        tag_name = 'tag_test_update_name_' + str(datetime.now())[-5:]
        tag = [{'name': tag_name}]
        self.tag.add("group_test_update_name", tag)
        r = self.tag.list()
        tag_id = jsonpath(r.json(), f'$..[?(@.name=="{tag_name}")].id')[0]
        r = self.tag.update(tag_id, name)
        assert r.json()['errcode'] == 0
        r = self.tag.list()
        assert len(jsonpath(r.json(), f'$..[?(@.name=="{name}")].id')) == 1

    @pytest.mark.parametrize("order_id", [
        # [5,4,3,2,1]  标签/标签组的次序值。order值大的排序靠前。有效的值范围是[0, 2^32)

    ])
    def test_update_order(self, order_id):
        pass

    def test_clear_all(self):
        r = self.tag.clear_all()
        assert len(r.json()['tag_group']) == 0

    def setup(self):
        self.update_index += 1

    @pytest.mark.parametrize('a', [1, 2, 3, 4, 5])
    def test_demo(self, a):
        self.update_index += 1
        TestTag.update_index_class+=1
        print(f"update_index={self.update_index}")
        print(f"update_index_class={self.update_index_class}")
Example #12
0
class TestTag:
    def setup_class(self):
        # todo:数据清理的过程,把测试数据清空或者还原
        self.tag = Tag()
        self.tag.get_token()

    # 获取企业标签库
    def test_tag_list(self):
        # 获取企业标签库
        # todo:完善功能测试
        r = self.tag.list()
        assert r.status_code == 200
        assert r.json()["errcode"] == 0

    @pytest.mark.parametrize("group_name, tag_names", [
        ["group_name_1201", [{
            'name': 'tag_name_1201'
        }]],
        [
            "group_name_1202",
            [{
                'name': 'tag_name_1202'
            }, {
                'name': 'tag_name_1203'
            }]
        ],
    ])
    def test_tag_add(self, group_name, tag_names):
        # todo:本身数据支持参数化:利用@pytest.mark.parametrize
        # 这个类中都会使用到的初始化信息,放到setup_class(self):中
        # tag = Tag()
        # # 利用Tag类中封装的获取token的方法来获取access_token
        # tag.get_token()

        # # step1:代码中多处使用了同一变量,抽出来定义变量
        # 进一步修改:利用参数化,不直接在用例中定义变量
        # group_name = "group_name_1201"
        # tag_names = [{'name': 'tag_name_1201'}]

        # 添加企业客户标签,需要传值
        r = self.tag.add(group_name, tag_names)
        assert r.status_code == 200
        # assert r.json()["errcode"] == 0

        # 获取企业标签库,校验添加的标签是否存在
        r = self.tag.list()
        assert r.status_code == 200
        assert r.json()["errcode"] == 0

        # 校验创建的标签组和标签存在。
        """
        tag_group对应的value值是一个列表,采用for循环
        """
        group = [
            group for group in r.json()['tag_group']
            if group['group_name'] == group_name
        ][0]
        tags = [{'name': tag['name']} for tag in group['tag']]
        print(group)
        print(tags)
        assert group['group_name'] == group_name
        assert tags == tag_names

    # 标签名超过30个的失败
    def test_tag_add_fail(self):
        pass
Example #13
0
 def setup_class(self):
     # todo:数据清理的过程,把测试数据清空或者还原
     self.tag = Tag()
     self.tag.get_token()
Example #14
0
 def setup_class(self):
     # 初始化Tag
     self.tag = Tag()
     # 拿到token
     self.tag.get_token()
Example #15
0
class TestTag:
    def setup_class(self):
        self.tag = Tag()

    @pytest.mark.parametrize("tag_id, tag_name", [
        ['et_6ElDwAAK8oJuAJ82drAyVi7DBhJyA', 'tag1_new_'],
        ['et_6ElDwAAxqiLMGOboky3_SyekzNUuA', 'tag1——中文'],
        ['et_6ElDwAA3p5Mmu7lR_C2S4s2Pw571w', 'tag1[中文]'],
    ])
    def test_tag_list(self, tag_id, tag_name):
        tag_name = tag_name + str(datetime.datetime.now().strftime("%Y%m%d-%H%M%S"))
        r = self.tag.list()
        r = self.tag.update(
            id=tag_id,
            tag_name=tag_name
        )
        r = self.tag.list()
        # tags = [
        #     tag2

        #     for group in r.json()['tag_group'] if group['group_name'] == group_name
        #     for tag in group['tag'] if tag['name'] == tag_name
        # ]

        assert jsonpath(r.json(), f"$..[?(@.name=='{tag_name}')]")[0]['name'] == tag_name
        # assert tags != []

    def test_list(self):
        self.tag.list()

    # 如果 40071 ,UserTag Name Already Exist
    # 1. 删除对应 tag (推荐)
    # 2. 已有 tag_name 的基础上,追加名字(时间戳,计数器)
    def test_add_tag(self):
        # todo: 测试数据要放到数据文件中
        group_name = "TMP00123"
        tag = [
            {"name": "TAG3"},
            {"name": "TAG2"},
            {"name": "TAG3"},
        ]

        r = self.tag.add(group_name=group_name, tag=tag)
        assert r.status_code == 200
        assert r.json()["errcode"] == 0

    def test_add_and_detect(self):
        group_name = "TMP00123"
        tag = [
            {"name": "TAG1"},
            {"name": "TAG2"},
            {"name": "TAG3"},
        ]
        r = self.tag.add_and_detect(group_name, tag)
        assert r

    # 如果 40068 ,invalid tagid
    # 0. 添加 tag
    # 1. 删除 tag 有问题
    # 2. 再进行重试(重试次数: n):手动实现,借助 pytest 钩子(rerun插件)
    #   a. 添加一个接口
    #   b. 对新添加的接口再删除
    #   c. 查询删除是否成功
    def test_delete_group(self):
        self.tag.delete_group(["et_6ElDwAAzdH3nsV5g24aSO4ZUQyBOg"])

    def test_delete_tag(self):
        self.tag.delete_tag(["et_6ElDwAAgItYmM3RQYkH3dhdAI8_QA"])

    def test_delete_and_detect_group(self):
        r = self.tag.delete_and_detect_group(["et_6ElDwAAyvuY_HFzh0vHvy-yqYhVHA"])
        assert r.json()["errcode"] == 0
Example #16
0
class TestTag:
    def setup(self):
        self.tag = Tag()

    #删除标签组
    def test_delete_and_detect_group(self):
        r = self.tag.delete_and_detect_group(
            ['etMoQQDQAACquqZ5jT9KwvfE10T46GYQ'])
        print(r.json(), type(r.json()))
        assert r.json()['errcode'] == 0

    #更新标签
    # @pytest.mark.skip(reason='skip')
    @pytest.mark.parametrize(
        "tag_id,tag_name", [('etMoQQDQAAu47atKWLSSXFVYmy8doqiA', 'tag1_new_'),
                            ('etMoQQDQAAu47atKWLSSXFVYmy8doqiA', 'tag1_中文'),
                            ('etMoQQDQAAu47atKWLSSXFVYmy8doqiA', 'tag1_[中文]')])
    def test_update(self, tag_id, tag_name):
        # group_name='python15'
        # tag_id='etMoQQDQAACzSou6IVZVyDf33-zSC3ZQ'
        tag_name = tag_name + str(
            datetime.datetime.now().strftime('%Y%m%d%H%M%S'))

        # r=self.tag.list()
        r = self.tag.update(id=tag_id, tag_name=tag_name)
        r = self.tag.list()
        print(r.json(), type(r.json()))
        # print(type(jsonpath(r.json(),f"$..[?(@.name=='{tag_name}')]")))
        assert jsonpath(r.json(),
                        f"$..[?(@.name=='{tag_name}')]")[0]['name'] == tag_name
        # tags=[tag
        #       for group in r.json()['tag_group'] if group['group_name'] == group_name
        #       for tag in group['tag'] if tag['name'] == tag_name
        #       ]
        # assert tags !=[]

    #增加标签
    # @pytest.mark.parametrize("tag_name,group_id",[
    #     ('tag_name中文', 'etMoQQDQAA_Lca86F1dGKme-4qde0VJQ'),
    #     ('tag_name_new1', 'etMoQQDQAA_Lca86F1dGKme-4qde0VJQ'),
    #     ('tag_name?', 'etMoQQDQAA_Lca86F1dGKme-4qde0VJQ'),
    # ])
    @pytest.mark.skip(reason='skip')
    def test_add_tag(self):
        # tag_name =tag_name+ str(datetime.datetime.now().strftime('%Y%m%d%H%M%S'))
        group_name = "tmp123"
        tag = [{
            "name": uuid.uuid1()
        }, {
            "name": uuid.uuid1()
        }, {
            "name": uuid.uuid1()
        }]
        r = self.tag.add(group_name=group_name, tag=tag)
        assert r.status_code == 200 and r['errcode'] == 0

    #添加全新标签
    def test_add_and_detect(self):
        # tag_name =tag_name+ str(datetime.datetime.now().strftime('%Y%m%d%H%M%S'))
        group_name = "tmp123"
        tag = [{"name": '11'}, {"name": "tag2"}, {"name": "tag31"}]
        r = self.tag.add_and_detect(group_name=group_name, tag=tag)
        assert r

    #像指定组下添加标签
    def test_add_group_assign_tag(self):
        group_name = "tmp123"
        tag_first = [{"name": '11'}, {"name": "tag"}, {"name": "tag31"}]
        tag_second = [{
            "name": self.tag.generate_unique_tag_name('tag')
        }, {
            "name": self.tag.generate_unique_tag_name('tag1')
        }]
        self.tag.add_and_detect(group_name=group_name, tag=tag_first)
        r = self.tag.add(group_name, tag_second)

    #删除标签
    # @pytest.mark.parametrize("tag_id",[
    #     'etMoQQDQAABbwEJAbIhNRu87l489sYEw',
    #     'etMoQQDQAAlFY29_c-nlNHLZzsFPzKBQ',
    #     # 'etMoQQDQAAIbsqLILajxZnuqQTI3XpEg'
    # ])

    # @pytest.mark.skip(reason='skip')
    def test_group_delete(self):
        r = self.tag.delete_group(group_id=['etMoQQDQAAvErLVWDNoKOff6o-44wkE'])
        # r=self.tag.list()
        # print(jsonpath(r.json(),f"$..[?(@.id=='etMoQQDQAAq6lttsvB49lm2bnXI-5TTQ')]"))
        # assert not (jsonpath(r.json(),f"$..[?(@.id=={tag_id})]"))

    # @pytest.mark.skip(reason='skip')
    def test_tag_delete(self):
        r = self.tag.delete_tag(tag_id=['etMoQQDQAACquqZ5jT9KwvfE10T46GY'])

    #删除标签
    def test_delete_and_detect_tag(self):
        r = self.tag.delete_and_detect_tag(
            ['etMoQQDQAAMQNKuk9x7YwJszGijAXlZw'])
        assert r.json()['errcode'] == 0
Example #17
0
 def setup(self):
     self.tag = Tag()