Esempio n. 1
0
class TestTag:
    data = BaseApi.yaml_load("../data/test_tag.data.yaml")
    steps = BaseApi.yaml_load("../data/test_tag.step.yaml")

    @classmethod
    def setup_class(cls):
        cls.tag = Tag()
        cls.reset()

    def test_get(self):
        r = self.tag.get()

        assert r["errcode"] == 0
        print(self.tag.jsonpath(f"$..tag[?(@name !='')]"))

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

    @pytest.mark.parametrize("name", data["test_delete"])
    def test_delete(self, name):
        # 如果有就删除
        r = self.tag.get()
        x = self.tag.jsonpath(f"$..tag[?(@.name=='{name}')]")
        if isinstance(x, list) and len(x) > 0:
            self.tag.delete(tag_id=[x[0]['id']])

        # 环境干净后开始测试
        r = self.tag.get()
        path = "$..tag[?(@.name!='')]"
        size = len(self.tag.jsonpath(path))

        # 添加新标签
        self.tag.add(name)
        r = self.tag.get()
        assert len(self.tag.jsonpath(path)) == size + 1
        tag_id = self.tag.jsonpath(f"$..tag[?(@.name=='{name}')]")[0]['id']
        print(tag_id)
        # 删除新标签
        self.tag.delete(tag_id=[tag_id])

        # 断言
        r = self.tag.get()
        assert len(self.tag.jsonpath(path)) == size

    @pytest.mark.parametrize("name", data["test_delete"][0:1])
    def test_delete_steps(self, name):
        self.tag.params = {"name": name}
        self.tag.step_run(self.steps['test_delete'])

    def teardown(self):
        self.reset()

    @classmethod
    def reset(cls):
        cls.tag.get()
        for name in ["demo1", "demo2"]:
            x = cls.tag.jsonpath(f"$..tag[?(@.name=='{name}')]")
            if isinstance(x, list) and len(x) > 0:
                cls.tag.delete(tag_id=[x[0]['id']])
Esempio n. 2
0
def test_template():
    print(
        BaseApi.template("D:/PythonWork/python/test_requests/api/tag.add.yaml",
                         {
                             "token": "123",
                             "tag_name": "demo"
                         }))
Esempio n. 3
0
class TestWork:
    test_data = BaseApi.test_load("test_tag_data.yaml")

    @classmethod
    def setup_class(cls):
        cls.tag = Tag()

    @pytest.mark.parametrize("old_name,new_name", test_data)
    def test_all(self, old_name, new_name):
        data = self.tag.get_tag()
        for name in [old_name, new_name]:
            print(name)
            tag_id = self.tag.jsonpath(data, f'$..tag[?(@.name=="{name}")].id')
            if tag_id:
                self.tag.delete_tag(tag_id[0])
        assert self.tag.add_tag(old_name)["errcode"] == 0
        tag_id = self.tag.jsonpath(self.tag.get_tag(),
                                   f'$..tag[?(@.name=="{old_name}")].id')[0]
        assert self.tag.update_tag(tag_id, new_name)["errcode"] == 0

    def test_get_token(self):
        corpsecret = "neiCBsIZkMi5GlphBz_YNfeLZDgNEkyjm3SktMGfxA8"
        print(WeWork().get_token(corpsecret))

    def test_add_tag(self):
        print(self.tag.add_tag("朋友3"))

    def test_get_tag(self):
        assert self.tag.get_tag()["errcode"] == 0

    def test_delete_tag(self):
        print(Tag().delete_tag("et2Gx3DAAAg7mfAdQ0GTS_Wk-fi_ioPg"))

    def test_update_tag(self):
        print(Tag().update_tag("et2Gx3DAAAT3OXcTdfPIcnDGxfX7s17w", "亲戚"))
Esempio n. 4
0
class TestTag:
    test_data = BaseApi.load('test_tag_data.yaml')

    @classmethod
    def setup_class(cls):
        cls.tag = Tag()
        for name in ['add demo']:
            tag_id = cls.tag.jsonpath(cls.tag.get(),
                                      f'$..tag[?(@.name=="{name}")].id')
            if tag_id:
                cls.tag.delete(tag_id=tag_id[0])

    def setup(self):
        pass

    @pytest.mark.parametrize("name_old", "name_new", test_data)
    def test_all(self, name_old, name_new):
        assert self.tag.add(tag_name=name_old)['errcode'] == 0
        tag_id = self.tag.jsonpath(self.tag.get(),
                                   f'$..tag[?(@.name=="{name_old}")].id')[0]
        assert self.tag.update(tag_id, f'{name_new}')['errcode'] == 0

    def test_get(self):
        print(json.dumps(self.tag.get(), indent=2))

    def test_delete(self):
        self.tag.delete('dsfdfgfds')

    def test_add(self):
        assert self.tag.add(tag_name="add demo")['errcode'] == 0

    def test_update(self):
        self.tag.update('dasdsa', 'dsad')
Esempio n. 5
0
class Test_Tag:
    tag = Tag()
    test_data = BaseApi.load('./test_requests/test_case/test_tag_data.yaml')

    @classmethod
    def setup_class(cls):
        data = cls.tag.get()
        for name in ["add demo"]:
            # 找到包含zhangsan 属性的tag节点,再通过.id查找到所属id
            tag_id = cls.tag.jsonpath(data, f'$..tag[?(@.name=="{name}")].id')
            if tag_id:
                cls.tag.delete(tag_id[0])

    def setup(self):
        pass

    @pytest.mark.parametrize("name_old,name_new", test_data)
    def test_all(self, name_old, name_new):
        # data = self.tag.get()
        # for name in [name_old, name_new]:
        #     # 找到包含zhangsan 属性的tag节点,再通过.id查找到所属id
        #     tag_id = self.tag.jsonpath(data, f'$..tag[?(@.name=="{name}")].id')
        #     if tag_id:
        #         self.tag.delete(tag_id[0])
        assert self.tag.add(name_old)['errcode'] == 0
        tag_id = self.tag.jsonpath(self.tag.get(), f'$..tag[?(@.name=="{name_old}")].id')[0]
        assert self.tag.update(tag_id, name_new)['errcode'] == 0

    def test_add(self):
        assert self.tag.add("add demo")["errcode"] == 0

    def test_get(self):
        # 格式美化
        assert self.tag.get()['errcode'] == 0
        # print(json.dumps(self.tag.get(), indent=2))

    def test_delete(self):
        print(self.tag.delete("etQKd-CgAAI70aMYm4j37aJyTo0EMRmw"))

    def test_update(self):
        print(Tag().update('etQKd-CgAAE6Zdmx89xoc_LYuIyLWwNw', 'wangwu'))
Esempio n. 6
0
def test_template():
    print(BaseApi.template("tag_get.yaml", {"access_token": 123}))
Esempio n. 7
0
def test_template():
    print(
        BaseApi.template("../api/tag.add.yaml", {
            "token": "123",
            "tag_name": "demo"
        }))
 def setup(self):
     self.department = Department()  # 需要先实例化,才可调用Department类中的方法
     self.baseapi = BaseApi()