Ejemplo n.º 1
0
class TestEmployee(unittest.TestCase):
    # 初始化
    @classmethod
    def setUpClass(cls):
        cls.api = ApiEmployee()

    # 新增员工
    @parameterized.expand(read_json("a.json"))
    def test01_post(self, username, mobile, workNumber):
        # 调用新增员工接口
        r = self.api.post_empolyee(username, mobile, workNumber)
        print(r.json())
        api.user_id = r.json().get("data").get("id")
        assert_common(self, r)

    # 更新
    @parameterized.expand(read_json("b.json"))
    def test02_post(self, username):
        # 调用新增员工接口
        r = self.api.put_employee(username)
        print(r.json())
        assert_common(self, r)

    # 查询
    def test03_get(self):
        r = self.api.get_employee()
        print(r.json())
        assert_common(self, r)

    # 删除员工
    def test04_delete(self):
        r = self.api.delete_employee(api.user_id)
        print(r.json())
        assert_common(self, r)
Ejemplo n.º 2
0
class Testadk(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.api = ApiEmployee()

    @parameterized.expand(read_json("login.json"))
    def test01_post(self, username, mobile, workNumber):
        r = self.api.api_post(username, mobile, workNumber)
        print("新增员工后结果:", r.json())
        api.user_id = r.json().get("data").get("id")
        print("新增员工id", api.user_id)
        assert_common(self, r)

    def test02_put(self, username="******"):
        r = self.api.api_put(username)
        print("更新员工的姓名为:", r.json())
        assert_common(self, r)

    def test03_get(self):
        r = self.api.api_get()
        print("查询结果为", r.json())
        assert_common(self, r)

    def test04_delete(self):
        r = self.api.api_delete(api.user_id)
        print("删除员工成功", r.json())
        assert_common(self, r)
Ejemplo n.º 3
0
class Test_Employee:
    def setup(self):
        self.emp = Employee()
        self.log = GetLog.get_logger()

    @pytest.mark.parametrize('username,mobile,workNumber',
                             read_json('add_emp.json'))
    def test_01_add(self, username, mobile, workNumber):
        r = self.emp.add_emp(username, mobile, workNumber)
        self.log.info("添加员工接口返回信息:{}".format(r.json()))
        # 获取 ID 值
        id = r.json().get('data').get('id')
        api.user_id = id
        self.log.info("ID值:{}".format(id))
        assert_tool(r)

    def test_02_update(self):
        r = self.emp.update_emp("xxxiii-new")
        self.log.info("修改员工接口返回信息:{}".format(r.json()))
        assert_tool(r)

    def test_03_search(self):
        r = self.emp.search_emp()
        self.log.info("查询员工接口返回信息:{}".format(r.json()))
        assert_tool(r)

    def test_04_delete(self):
        r = self.emp.delete_emp()
        self.log.info("删除员工接口返回信息:{}".format(r.json()))
        assert_tool(r)
Ejemplo n.º 4
0
class TestArticle(unittest.TestCase):
    # 新建收藏文章方法
    @parameterized.expand(read_json('article_collect.json'))
    def test_collect(self, url, headers, data, status_code, expect_result):
        # 临时数据
        # url = 'http://ttapi.research.itcast.cn/app/v1_0/article/collections'
        # headers = {
        #     "Content-Type": "application/json",
        #     "Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1OTg5NjkyMzYsInVzZXJfaWQiOjEzMDA3MTI4MDY4MDIyNTk5NjgsInJlZnJlc2giOmZhbHNlfQ.j7WyrRVTowbt97HWN3KzoCKOsVVrNvU4JH-cExhj4z0"
        # }
        # data = {"target": 2}

        # 调用收藏文章方法
        res = ApiArticle().api_post_collect(url, headers, data)

        # 调试 查看响应数据测试结果
        print('响应结果为:', res.json())

        # 断言 状态码
        self.assertEqual(status_code, res.status_code)

        # 断言 响应信息
        self.assertEqual(expect_result, res.json()['message'])

    # 新建取消收藏文章方法
    @parameterized.expand(read_json('cancel_collect.json'))
    def test_cancel_collect(self, url, headers, status_code):
        # url = 'http://ttapi.research.itcast.cn/app/v1_0/article/collections/2'
        # headers = {
        #     "Content-Type": "application/x-www-form-urlencoded",
        #     "Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1OTg5NjkyMzYsInVzZXJfaWQiOjEzMDA3MTI4MDY4MDIyNTk5NjgsInJlZnJlc2giOmZhbHNlfQ.j7WyrRVTowbt97HWN3KzoCKOsVVrNvU4JH-cExhj4z0"
        # }

        # 调用取消收藏方法
        res = ApiArticle().api_delete_cancel_collect(url, headers)

        # 调试, 查看响应数据
        print('响应数据为:', res.text)

        # 断言 状态码
        self.assertEqual(status_code, res.status_code)
Ejemplo n.º 5
0
class TestChannel(unittest.TestCase):
    # 新建测试方法
    @parameterized.expand(read_json('channel.json'))
    def test_channel(self, url, headers, expect_result, status_code):
        # 临时数据
        # url = 'http://ttapi.research.itcast.cn/app/v1_0/user/channels'
        # headers = {
        #     "Content-Type": "application/json",
        #     "Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1OTg5NjAxMTgsInVzZXJfaWQiOjEzMDA3MTI4MDY4MDIyNTk5NjgsInJlZnJlc2giOmZhbHNlfQ.3ijNJfgOvaVt1jxpQiQInNRykothYX7mjKjnGUU3eI0"
        # }

        # 调用获取用户频道列表方法
        res = ApiChannel().api_get_channel(url, headers)

        # 调试信息 打印响应结果
        print('查看响应结果信息为:', res.json())

        # 断言  状态码
        self.assertEqual(status_code, res.status_code)

        # 断言 响应信息
        self.assertEqual(expect_result, res.json()['message'])
Ejemplo n.º 6
0
class TestLogin(unittest.TestCase):
    # 初始化
    @classmethod
    def setUpClass(cls):
        cls.session = requests.session()
        cls.login = ApiLogin(cls.session)

    # 结束
    @classmethod
    def tearDownClass(cls):
        # 关闭sesstion对象
        cls.session.close()

    # 测试方法
    @parameterized.expand(read_json("login.json"))
    def test_login(self, username, password, verify_code, expect):
        # 调用获取验证吗
        self.login.api_verify_code()
        # 调用登录
        r = self.login.api_login(username, password, verify_code)
        # 断言
        self.assertEqual(expect, r.json().get("status"))