Giter Club home page Giter Club logo

redemption's Introduction

Redemption

接口自动化测试框架实现,基于Pytest+Requests

Features

  • 链式调用
  • 高级assert方法
  • response变量提取与使用
  • 协议扩展
  • 用例自动生成

Installation

export PYTHONPATH=$PYTHONPATH:/workspaces/Redemption
pip install poetry # Python >= 3.10
poetry install
poetry run pytest

Demo

TestCases/test_demo.py

import json

import pytest
import responses

from core import ClientType, TestCase


class TestDemo(TestCase):
    """
    testcase demo
    """

    @responses.activate
    def test_get(self, client: ClientType):
        # mock response
        responses.add(
            responses.Response(
                method="GET",
                url="http://example.com",
                headers={"Content-Type": "application/json"},
                json={"Hello": "World"},
            ),
        )
        (
            client.get("http://example.com")
            .headers({"Content-Type": "application/json"})
            .send(timeout=8)
            .assert_status_code(200)
            .assert_timing(0.5)
            .assert_header("Content-Type", "application/json")
            .assert_equal("$.Hello", "World")
            .export("body", "$.Hello", "Hello")
        )

    @responses.activate
    @pytest.mark.parametrize(
        "req",
        [
            {"xx": "post {Hello}"},
            {"xx": "post test", "yy": "post test"},
        ],
    )
    def test_by_parametrize(self, req, client: ClientType):
        # mock response
        responses.add(
            responses.Response(
                method="POST",
                url="http://example.com",
                headers={"Content-Type": "application/json"},
                json={"Hello": "World"},
            ),
        )
        (
            client.post("http://example.com")
            .headers({"Content-Type": "application/json"})
            .body(json.dumps(req))
            .send(timeout=8)
            .assert_status_code(200)
            .assert_timing(0.5)
            .assert_header("Content-Type", "application/json")
            .assert_equal("$.Hello", "World")
        )

redemption's People

Contributors

nowod avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.