企业微信-接口测试实战1

restful架构:

  • 每一个URI代表一种资源
  • 客户端和服务器之间,传递这种资源的某种表现层
  • 客户端通过四个HTTP动词,对服务器端资源进行操作,实现表现层状态转化

requests: https://requests.readthedocs.io/zh_CN/latest/user/quickstart.html

URL 解析

https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=ID&corpsecret=SECRET

  • https: 协议,http,websockets
  • qyapi.weixin.qq.com: 主机地址,DNS
  • /cgi-bin/gettoken:资源地址
  • ?corpid=ID&corpsecret=SECRET:参数

ppt

作业

  1. 实现通讯录的增删改查
  2. 使用 session 减少字段的重复项

实现通讯录的增删改查

并使用 session 减少字段的重复项:token,userid

import requests
from hamcrest import *
class TestWechatAccess:
    # 实例化会话对象
    s = requests.Session()
    def setup(self):
        params={
            "corpid":"ww44051ca7a74ae8e3",
            "corpsecret":"uhSqBpzjxIvpbfPaXuPH574dfKwPUcLzlnqOGEklghc"
        }
        res = self.s.get(url="https://qyapi.weixin.qq.com/cgi-bin/gettoken",params=params)
        # 将token放入会话对象中
        self. s.params.update({"access_token": res.json()['access_token']})

    # 添加成员
    def test_addMember(self):
        data = {
                "userid": "zhangsan",
                "name": "张三",
                "mobile": "13800000009",
                "department": [1]
        }

        res = self.s.post(url=f'https://qyapi.weixin.qq.com/cgi-bin/user/create',json=data)
        # 将userid放入会话对象中
        self.s.params.update({"userid":"zhangsan"})
        assert(self.test_getMember()['name']=="张三")
        print(res.json())

    #  读取成员
    def test_getMember(self):
        # params={
        #     "userid":"zhangsan"
        # }
        # res = self.s.get("https://qyapi.weixin.qq.com/cgi-bin/user/get",params=params)
        res = self.s.get("https://qyapi.weixin.qq.com/cgi-bin/user/get")
        return res.json()
        print(res.json())

    # 修改成员
    def test_updateMember(self):
        data={
            "userid":"zhangsan",
            "name":"王五"
        }
        res=self.s.post(url=f"https://qyapi.weixin.qq.com/cgi-bin/user/update",json=data)
        assert (self.test_getMember()['name'] == "王五")
        print(res.json())

    # 删除成员
    def test_deleteMember(self):
        # params={
        #     "userid":"zhangsan"
        # }
        res = self.s.get(url="https://qyapi.weixin.qq.com/cgi-bin/user/delete")
        assert_that(self.test_getMember()['errmsg'], starts_with('userid not found'))
        print(res.json())

https://github.com/tzhang-web/pyzt1/tree/07ffd9c3acd1d8c8aa05a3889446053993551277/test_rest
张涛接口作业:文件名:test_rest---------------- >test_work_rest.py

https://github.com/jb5881/TestDevlopProject/tree/master/devlop0726/test_requests

郑向红作业:
https://github.com/anny2020/hogwarts.git

陈智斌 【企业微信-接口测试实战1】作业提交

https://github.com/archerckk/hogwarts/tree/master/api_hw1

https://github.com/tanya931117/TestDev

卢海清作业:
https://github.com/haiqing999/Lagou2qiProject/tree/master/test_api

王小刚作业:
https://github.com/yuguo100tianqing/lagou2qiprj/tree/master/Interfacetest

刘羽–作业1-企业微信接口通讯录增删改查
https://github.com/elsa-liu/lagou2QProject/blob/master/pythoncode/requests_homework/test_request1/test_requests_contact.py

刘伟作业:
https://github.com/huanxingshi01/interfacelearning.git

贾潇冰-企业微信接口测试实战1
https://github.com/cathyyyyyJ/Lagou2QI_ZY/tree/master/pythoncode9

https://github.com/echoqyg/lagouproject/blob/master/test_requests/test_wework_access.py

程晨:接口一期
https://github.com/Staupo/testpro.git

王熙曈作业
https://github.com/wxt-hhh/lagou-hogwarts/tree/master/requestscode

林遵明作业
https://github.com/jimmylinz/LagouProject/tree/master/api