All Projects → yuyu1987 → Pithy Test

yuyu1987 / Pithy Test

Licence: apache-2.0
简化接口测试

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Pithy Test

Zerocode
A community-developed, free, open source, microservices API automation and load testing framework built using JUnit core runners for Http REST, SOAP, Security, Database, Kafka and much more. Zerocode Open Source enables you to create, change, orchestrate and maintain your automated test cases declaratively with absolute ease.
Stars: ✭ 482 (+246.76%)
Mutual labels:  api, automation
Gocertcenter
CertCenter API Go Implementation
Stars: ✭ 21 (-84.89%)
Mutual labels:  api, automation
Fuzzapi
Fuzzapi is a tool used for REST API pentesting and uses API_Fuzzer gem
Stars: ✭ 521 (+274.82%)
Mutual labels:  api, automation
Api
API that uncovers the technologies used on websites and generates thumbnail from screenshot of website
Stars: ✭ 189 (+35.97%)
Mutual labels:  api, automation
Patrowlhears
PatrowlHears - Vulnerability Intelligence Center / Exploits
Stars: ✭ 89 (-35.97%)
Mutual labels:  api, automation
Allure Docker Service
This docker container allows you to see up to date reports simply mounting your "allure-results" directory in the container (for a Single Project) or your "projects" directory (for Multiple Projects). Every time appears new results (generated for your tests), Allure Docker Service will detect those changes and it will generate a new report automatically (optional: send results / generate report through API), what you will see refreshing your browser.
Stars: ✭ 194 (+39.57%)
Mutual labels:  api, automation
Openapi3 Validator
Validator for OpenAPI v3 specs
Stars: ✭ 11 (-92.09%)
Mutual labels:  api, automation
Stelace
Open-source marketplace backend in Node.js, empowering Web platforms with Search API, Automation, Auth, Headless CMS… ⚡ 💻
Stars: ✭ 144 (+3.6%)
Mutual labels:  api, automation
Api Store
Contains all the public APIs listed in Phantombuster's API store. Pull requests welcome!
Stars: ✭ 69 (-50.36%)
Mutual labels:  api, automation
Nexrender
📹 Data-driven render automation for After Effects
Stars: ✭ 946 (+580.58%)
Mutual labels:  api, automation
Whatsapp Bot
BOT - WhatsApp Web in TypeScript
Stars: ✭ 170 (+22.3%)
Mutual labels:  api, automation
30 Days Of Python
Learn Python for the next 30 (or so) Days.
Stars: ✭ 1,748 (+1157.55%)
Mutual labels:  api, automation
Sherpa
Sherpa is a highly available, fast, and flexible horizontal job scaling for HashiCorp Nomad. It is capable of running in a number of different modes to suit different requirements, and can scale based on Nomad resource metrics or external sources.
Stars: ✭ 165 (+18.71%)
Mutual labels:  api, automation
Patrowlmanager
PatrOwl - Open Source, Smart and Scalable Security Operations Orchestration Platform
Stars: ✭ 363 (+161.15%)
Mutual labels:  api, automation
Patrowlengines
PatrOwl - Open Source, Free and Scalable Security Operations Orchestration Platform
Stars: ✭ 162 (+16.55%)
Mutual labels:  api, automation
Just Api
💥 Test REST, GraphQL APIs
Stars: ✭ 768 (+452.52%)
Mutual labels:  api, automation
Quip Export
Export all folders and documents from Quip
Stars: ✭ 28 (-79.86%)
Mutual labels:  api, automation
Patrowldocs
PatrOwl - Open Source, Free and Scalable Security Operations Orchestration Platform
Stars: ✭ 105 (-24.46%)
Mutual labels:  api, automation
Pfsense Api
The missing REST API package for pfSense
Stars: ✭ 126 (-9.35%)
Mutual labels:  api, automation
Gatling Sbt Plugin Demo
Showcase of the Gatling Plugin for SBT
Stars: ✭ 137 (-1.44%)
Mutual labels:  automation

该项目不再继续更新维护了,请转到新项目 https://github.com/sunhetao/walnuts ,感谢

安装&更新

# 安装
pip install pithy-test

# 更新
pip install -U pithy-test

# 删除
pip uninstall pithy-test

项目文档

http://pithy-test.readthedocs.io/

生成接口测试项目

(pyenv)➜  pithy-cli init
请选择项目类型,输入api或者app: api
请输入项目名称,如pithy-api-test: pithy-api-test
开始创建pithy-api-test项目
开始渲染...
生成 api/.gitignore                   [√]
生成 api/apis/__init__.py             [√]
生成 api/apis/pithy_api.py            [√]
生成 api/cfg.yaml                     [√]
生成 api/db/__init__.py               [√]
生成 api/db/pithy_db.py               [√]
生成 api/README.MD                    [√]
生成 api/requirements.txt             [√]
生成 api/test_suites/__init__.py      [√]
生成 api/test_suites/test_login.py    [√]
生成 api/utils/__init__.py            [√]
生成成功,请使用编辑器打开该项目

接口测试

HTTP接口

这个地方,我扩展了python requests库的使用,在原api不变的基础上,把原先的语句调用,扩展成了函数定义,然后对输出进行了包装,下面对比一下两种写法的不同

import requests
from pithy import request

# 直接使用requets的api
data = {'key': 'value'}
requests.get('http://www.xxx.com', data=data)


# 使用封装后的request
@request(url='http://www.xxx.com')
def get(value):
    data = {'key': value}
    return {'data': data}

之所以这么做,是因为这样可以更突显出api,更容易参数化,对session以及响应结果更好的处理

使用POST方法,数据传输为form格式

from pithy import request

@request(url='http://httpbin.org/post', method='post')
def post(self, key1='value1'):
    """
    post method
    """
    data = {
        'key1': key1
    }
    return dict(data=data)

# 使用
response = post('test').to_json()     # 解析json字符,输出为字典
response = post('test').json          # 解析json字符,输出为字典
response = post('test').to_content()  # 输出为字符串
response = post('test').content       # 输出为字符串
response = post('test').get_cookie()  # 输出cookie对象
response = post('test').cookie        # 输出cookie对象

# 结果取值, 假设此处response = {'a': 1, 'b': { 'c': [1, 2, 3, 4]}}
response = post('13111111111', '123abc').json

print response.b.c   # 通过点号取值,结果为[1, 2, 3, 4]

print response('$.a') # 通过object path取值,结果为1

for i in response('$..c[@>3]'): # 通过object path取值,结果为选中c字典里大于3的元素
    print i

使用GET方法

from pithy import request

@request(url='http://httpbin.org//get')
def get(self, key1='value1', key2=None):
    """
    get method
    """
    if key2 is None:
        key2 = ['value2', 'value3']

    params = {
        'key1': key1,
        'key2': key2
    }
    return dict(params=params)

使用POST方法,数据传输方式为json方式

from pithy import request

@request(url='http://httpbin.org/post', method='post')
def post(self, key1='value1'):
    """
    post method
    """
    data = {
        'key1': key1
    }
    return dict(json=data)

使用类的方式组织用接口,使用同一session,指定base_url

from pithy import request

class PithyAPP(object):

    def __init__(self):
        self.base_url = 'http://httpbin.org

    @request(url='/get')
    def get(self, key1='value1', key2=None):
        """
        get method
        """
        if key2 is None:
            key2 = ['value2', 'value3']

        params = {
            'key1': key1,
            'key2': key2
        }
        return dict(params=params)

    @request(url='post', method='post')
    def post(self, key1='value1'):
        """
        post method
        """
        data = {
            'key1': key1
        }
        return dict(data=data)

    @request(url='post', method='post')
    def json(self, key1='value1'):
        """
        post method
        """
        data = {
            'key1': key1
        }
        return dict(json=data)
    
    @request(url='login', method='post')
    def _login(username, password):
        """
        登录api
        注: 该方法只是示例,并不能运行,请结合自己的项目使用
        """
        data = {
            'username': username,
            'password': password
           }
         return dict(data=data)
     
     def login(username, password):
        """
        登录方法
        注: 该方法只是示例,并不能运行,请结合自己的项目使用
        """
        req = self._login(username, password)
        cookies = res.cookies  # 响应cookies
        headers = res.headers  # 响应headers
        self.session.headers.update(xxx=headers.get('xxx')) # 设置session里的headers,设置之后,所有的请求均会带上
        self.session.cookies.set('xxx', cookies.get('xxx')) # 设置session里的cookies,设置之后,所有的请求均会带上

# 使用,此处两个接口使用同一request session请求
app = PithyAPP()
app.get('value1').to_json()
app.post('value1).to_json()

工具类

操作日期函数

from pithy import HumanDateTime

# 解析时间戳
print(repr(HumanDateTime(1490842267)))
print(HumanDateTime(1490842267000))
print(HumanDateTime(1490842267.11111))
print(HumanDateTime(1490842267111.01))

# 解析字符串格式日期
print(HumanDateTime('2017-02-02'))
print(HumanDateTime('Thu Mar 30 14:21:20 2017'))
print(HumanDateTime(time.ctime()))
print(HumanDateTime('2017-3-3'))
print(HumanDateTime('3/3/2016'))
print(HumanDateTime('2017-02-02 00:00:00'))

# 解析datetime或date类型时间
print(HumanDateTime(datetime(year=2018, month=11, day=30, hour=11)))
print(HumanDateTime(date(year=2018, month=11, day=30)))

# 增加减少时间
print(HumanDateTime('2017-02-02').add_day(1))
print(HumanDateTime('2017-02-02').sub_day(1))
print(HumanDateTime('2017-02-02').add_hour(1))
print(HumanDateTime('2017-02-02').sub_hour(1))
print(HumanDateTime('2017-02-02').add(days=1, hours=1, weeks=1, minutes=1, seconds=6))
print(HumanDateTime('2017-02-02').sub(days=1, hours=1, weeks=1, minutes=1, seconds=6))

# 转换为时间戳
print(HumanDateTime(1490842267.11111).timestamp_second)
print(HumanDateTime(1490842267.11111).timestamp_microsecond)
print(HumanDateTime('2017-02-02 12:12:12.1111').add_day(1).timestamp_microsecond)
print(HumanDateTime('2017-02-02 12:12:12 1111').add_day(1).timestamp_microsecond)

# 比较大小
print(HumanDateTime('2017-02-02 12:12:12 1111') < HumanDateTime('2017-02-02 12:12:11 1111'))
print(HumanDateTime('2017-02-02 12:12:12 1111') < HumanDateTime('2017-02-02 12:13:11 1111'))
print(HumanDateTime('2017-02-02 12:12:12 1111') < '2017-02-02 12:11:11')
print(HumanDateTime('2017-02-02 12:12:12 1111') < '2017-02-02 12:13:11 1111')
print(HumanDateTime('2017-02-02 12:12:12 1111') == '2017-02-02 12:13:11 1111')
print(HumanDateTime('2017-02-02 12:12:12 1111') == '2017-02-02 12:13:12 1111')
print(HumanDateTime('2017-02-02 12:12:12 1111') <= '2017-02-02 12:13:11 1111')
print(HumanDateTime('2017-02-02 12:12:12 1111') >= '2017-02-02 12:13:11 1111')
print(HumanDateTime('2017-02-02 12:12:12 1111') != time.time())
print(HumanDateTime('2017-02-02 12:12:12 1111') <= time.time())
print(HumanDateTime('2017-02-02 12:12:12 1111') >= time.time())

# 约等于或者接近
print(HumanDateTime('2017-02-02 12:12:12 1111').approach('2017-02-02 12:12:11 1111'))
print(HumanDateTime('2017-02-02 12:12:12 1111').approach('2017-02-02 12:12:10 1111'))
print(HumanDateTime('2017-02-02 12:12:12 1111').approach('2017-02-02 12:12:10 1111', offset=2))
print(HumanDateTime('2017-02-02 12:12:12 1111').approach('2017-02-02 12:12:14 1111', offset=2))

# 调用datetime的方法和属性
print(HumanDateTime('2017-02-02 12:12:12 1111').day)
print(HumanDateTime('2017-02-02 12:12:12 1111').year)
print(HumanDateTime('2017-02-02 12:12:12 1111').second)
print(HumanDateTime('2017-02-02 12:12:12 1111').date())

操作复杂JSON或字典

优化JSON字符串和字典的取值方式

# 1、操作JSON的KEY
from pithy import JSONProcessor
dict_data = {'a': 1, 'b': {'a': [1, 2, 3, 4]}}
json_data = json.dumps(dict_data)
result = JSONProcessor(json_data)
print result.a     # 结果:1
print result.b.a   # 结果:[1, 2, 3, 4]

# 这里使用的object path的取值方式,详细语法见:http://objectpath.org/reference.html
for i in result('$..a[@>3]'):  # 结果: 4
    print i

# 2、操作字典的KEY
dict_data = {'a': 1, 'b': {'a': [1, 2, 3, 4]}}
result = JSONProcessor(dict_data)
print result.a     # 1
print result.b.a   # [1, 2, 3, 4]

交流反馈qq群

563337437

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].