Skip to main content

A yaml data-drive HTTP API testing tools.

Project description

apiflows testing

  • A yaml data-drive HTTP API testing tools.

usage

pip3 install apiflows
python3 -m apiflows [-c config.py]  -t testcases/github.yaml

configuration(config.py)

#!/bin/env python3

import uuid
import logging

# common headers
HEADERS = {
    'content-type': 'application/json',
    'x-token': '1234',
}

# common extracts
EXTRACTS = {
    'USERNAME':'allen'
}

def pre_testing():
    """
    pre testing
    """
    logging.debug("pre_testing()...")
    HEADERS['x-apiflows-id'] = str(uuid.uuid4())

def pre_request(apicase):
    """
    pre request
    """
    # TODO here
    logging.debug("pre_request()...")
    apicase.set_header("mycookie", "PHPSESSIONID=apiflows")
    return apicase

def do_request(apicase):
    logging.debug("do_request()...")
    apicase.do_request()
    return apicase

def parse_response(apicase):
    """
    parse HTTP response
    """
    logging.debug("parse_response()...")
    code = apicase.parse_status_code()
    headers = apicase.parse_response_headers()
    body = apicase.parse_response_body()
    return {'code': code, 'headers': headers, 'body': body}

def post_request(apicase):
    """
    post request
    """
    # TODO
    logging.debug("post_request()...")
    response = apicase.get_response()
    if response is not None:
        logging.debug("    RESPONSE: " + response.text)
    
    return apicase

def post_testing():
    """
    post testing
    """
    # TODO
    logging.debug("post_testing()...")

testcase example(github.yaml)

---
apicases:
- name: 获取GitHub API列表(Get Github API list)
  url: https://api.github.com
  method: GET
  headers:
    x-token: 5678
  data: '{"username":"apiflows"}'
  extracts:
    RATE_LIMIT_URL: $.rate_limit_url
    PUBLIC_GISTS_URL: $.public_gists_url
    ENCODING:
      in: headers
      exp: "$.Content-Encoding"
  assertions:
  - exp1: "$.hub_url"
    comparator: neq
    exp2: ""
  - exp1: "{{ENCODING}}"
    comparator: eq
    exp2: gzip
  - exp1: "{{RATE_LIMIT_URL}}"
    comparator: contains
    exp2: https
  - exp1: "{{PUBLIC_GISTS_URL}}"
    comparator: match
    exp2: (https:\/\/)

comparators

  • eq
  • neq
  • contains
  • match

test result

0:testcases/github.yaml
[获取GitHub API列表(Get Github API list)]: https://api.github.com/?username=allen
	EXTRACTOR:
		EXTRACT [RATE_LIMIT_URL]=https://api.github.com/rate_limit
		EXTRACT [PUBLIC_GISTS_URL]=https://api.github.com/gists/public
		EXTRACT [ENCODING]=gzip
	ASSERTIONS:
		$.hub_url = https://api.github.com/hub [neq] 
		{{ENCODING}} = gzip [eq] gzip
		{{RATE_LIMIT_URL}} = https://api.github.com/rate_limit [contains] https
		{{PUBLIC_GISTS_URL}} = https://api.github.com/gists/public [match] (https:\/\/)

for development

python3 -m build
twine upload dist/* 

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

apiflows-1.0.9-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file apiflows-1.0.9-py3-none-any.whl.

File metadata

  • Download URL: apiflows-1.0.9-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for apiflows-1.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 fad4724701ef91a6eefe8c80dcde6754227b788042c8283e54ae32beb5371a20
MD5 1728b233361d3c2b7d339182e539f525
BLAKE2b-256 fa01d846499bdafbce75348ae32ab009f0fd1073b73737cbbe3ab5543558dd25

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page