Esempio n. 1
0
class TestMp:
    #  初始化
    def setup_class(self):
        self.mp = ApiMp()

    # 测试登录接口
    @pytest.mark.parametrize("mobile,code", read_yaml("mp_login.yaml"))
    def test01_mp_login(self, mobile, code):
        r = self.mp.api_mp_login(mobile, code)
        print("登录接口返回的信息为:", r.json())
        try:
            Tools.common_token(r)
            Tools.common_assert(response=r)
        except Exception as e:
            # 写日志
            log.error(e)
            # 抛异常
            raise

    # 发布文章接口测试
    def test02_article(self,
                       title=api.title,
                       content=api.content,
                       channel_id=api.channel_id):
        r = self.mp.api_mp_article(title, content, channel_id)
        print("获取的响应信息为:", r.json())
        # 获取文章id
        api.article_id = r.json().get("data").get("id")
        # 断言
        try:
            Tools.common_assert(response=r)
        except Exception as e:
            log.error(e)
            raise
class TestMp:
    # 1.初始化
    def setup_class(self):
        # 获取ApiMp对象
        self.mp = ApiMp()

    # 2.登录接口测试方法
    @pytest.mark.parametrize("mobile, code", read_json('data/mp_login.json'))
    def test01_mp_login(self, mobile, code):
        # 调用登录接口
        r = self.mp.api_mp_login(mobile, code)
        # 打印输出接口
        print("登录接口为:", json.dumps(r.json(), indent=2))
        # 提取token
        Tool.common_token(r)
        # 断言
        Tool.common_assert(r)

    # 3.发布文章接口测试方法
    def test_mp_article(self):
        # 1.调用发布文章接口
        r = self.mp.api_mp_article(title=api.title,
                                   content=api.content,
                                   channel_id=api.channel_id)
        # 2.提取文章id
        api.article_id = r.json().get("data").get("id")
        print("发布文章成功后的id:{}".format(api.article_id))
        # 3.断言
        Tool.common_assert(r)
Esempio n. 3
0
class TestMp:
    # 1. 初始化
    def setup_class(self):
        # 获取ApiMp对象
        self.mp = ApiMp()

    # 2. 登录接口测试方法
    @pytest.mark.parametrize("mobile,code", read_yaml("mp_login.yaml"))
    def test01_mp_login(self, mobile, code):
        # 调用登录接口
        r = self.mp.api_mp_login(mobile, code)
        # 打印输出结果
        print("登录的结果为:", r.json())
        try:
            # 提取token
            Tool.common_token(r)
            # 断言
            Tool.common_assert(r)
        except Exception as e:
            # 写日志
            log.error(e)
            # 抛异常
            raise
        # # 提取token
        # token = r.json().get("data").get("token")
        # # 追加请求信息头
        # api.headers['Authorization'] = "Bearer " + token
        # print("添加token后的headers为:", api.headers)
        # # 断言状态码
        # assert 201 == r.status_code
        # # 断言响应信息
        # assert "OK" == r.json().get("message")

    # 3. 发布文章测试接口方法
    def test02_mp_article(self,
                          title=api.title,
                          content=api.content,
                          channel_id=api.channel_id):
        # 1. 调用发布文章接口
        r = self.mp.api_mp_article(title, content, channel_id)
        # 2. 提取id
        api.article_id = r.json().get("data").get("id")
        print("发布文章成功后的id值为:", api.article_id)
        try:
            # 3. 断言
            Tool.common_assert(r)
        except Exception as e:
            # 1. 日志
            log.error(e)
            # 2. 抛异常
            raise
Esempio n. 4
0
class TestMp:
    # 1. 初始化
    def setup_class(self):
        # 获取ApiMp对象
        self.mp = ApiMp()

    # 2. 登录接口测试方法
    @pytest.mark.parametrize("mobile,code", read_yaml("mp_login.yaml"))
    def test01_mp_login(self, mobile, code):
        # 调用登录接口
        r = self.mp.api_mp_login(mobile, code)
        # 打印输出结果
        print("登录的结果为: ", r.json())
        try:
            # 提取token
            Tool.common_token(r)
            # 断言
            Tool.common_assert(r)
        except Exception as e:
            # 日志
            log.error(e)
            # 抛异常
            raise

    # 3. 发布文章接口测试方法
    def test02_mp_article(self,
                          title=api.title,
                          content=api.content,
                          channel_id=api.channel_id):
        # 1. 调用发布文章接口
        r = self.mp.api_mp_article(title, content, channel_id)
        print("登录的结果为:", r.json())
        # 2. 提取id
        api.article_id = r.json().get("data").get("id")
        print("发布文章成功后的id为:{}".format(api.article_id))
        try:
            # 3. 断言
            Tool.common_assert(r)
        except Exception as e:
            # 1. 日志
            log.error(e)
            # 2. 抛异常
            raise
Esempio n. 5
0
class TestMp:
    # 初始化
    def setup_class(self):
        # 获取ApiMp对象
        self.mp = ApiMp()

    @pytest.mark.parametrize("mobile,code", read_txt("mp_login.txt"))
    def test01_mp_login(self, mobile, code):
        """
        登录测试方法
        :param mobile: 手机号
        :param code: 验证码
        :return:
        """
        # 调用登录接口方法
        r = self.mp.api_mp_login(mobile, code)
        # 提取token
        ToolsInter.get_token(r)
        # 断言
        print(r.json())
        ToolsInter.assert_common(r)

    #
    @pytest.mark.parametrize("title, content, channel_id,channel_name",
                             read_txt("mp_article.txt"))
    def test02_mp_article(self, title, content, channel_id, channel_name):
        """
        发布文章测试用例
        :param title: 文章标题
        :param content: 文章内容
        :param channel_id:
        :param channel_name:
        :return:
        """
        # 调用发布文章接口方法
        r = self.mp.api_mp_article(title, content, channel_id)
        # 发布文章成功id,生成文章id---审核文章使用
        api.article_id = r.json().get("data").get("id")
        # 断言
        ToolsInter.assert_common(r)
Esempio n. 6
0
class TestMp:
    # 初始化
    def setup_class(self):
        # 获取ApiMp对象
        self.mp = ApiMp()
        log.info("正在获取ApiMp对象:{}".format(self.mp))

    # 登录接口 测试方法
    @pytest.mark.parametrize("mobile,code", read_yaml("mp_login.yaml"))
    def test01_mp_login(self, mobile, code):
        # 调用登录接口
        r = self.mp.api_mp_login(mobile, code)
        print("状态码为:", r.status_code)
        print(r.json())
        try:
            # 提取token
            Tool.common_token(r)
            # 断言
            Tool.common_assert(r)
        except Exception as e:
            # 1. 日志
            log.error(e)
            # 2. 抛异常
            raise
            # 发布文章 接口测试方法

    def test02_mp_article(self, title=api.title, content=api.content):
        # 调用发布文章接口
        r = self.mp.api_mp_article(title, content)
        try:
            # 提取文章id
            api.article_id = r.json().get("data").get("id")
            log.info("正在提取发布文章id:{}".format(api.article_id))
            # 断言
            Tool.common_assert(r)
        except Exception as e:
            # 1. 日志
            log.error(e)
            # 2. 抛异常
            raise
Esempio n. 7
0
 def setup_class(self):
     self.mp = ApiMp()
 def setup_class(self):
     # 获取ApiMp对象
     self.mp = ApiMp()
Esempio n. 9
0
 def setup_class(self):
     # 获取ApiMp对象
     self.mp = ApiMp()
     log.info("正在获取ApiMp对象:{}".format(self.mp))