Пример #1
0
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)
Пример #2
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"])
Пример #3
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
Пример #4
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