Cornell record & replay mock server

Related tags

Testingcornell
Overview

Cornell: record & replay mock server

Build Status

Cornell makes it dead simple, via its record and replay features to perform end-to-end testing in a fast and isolated testing environment.

Cornell Logo

When your application integrates with multiple web based services, end-to-end testing is crucial before deploying to production. Mocking is often a tedious task, it becomes even more tiresome when working with multiple APIs from multiple vendors.

vcrpy is an awesome library that records and replays HTTP interactions for unit tests. Its output is saved to reusable "cassette" files.

By wrapping vcrpy with Flask, Cornell provides a lightweight record and replay server that can be easily used during distributed system testing and simulate all HTTP traffic needed for your tests.

Basic Use Case

When you're working with distributed systems, the test client entry point triggers a cascade of events that eventually send HTTP requests to an external server

System in test

With Cornell server started, it will act as a proxy (record mode) between the outgoing HTTP requests and the external server and will record all relevant interactions. Once interactions are recorded, Cornell can be work in replay mode and replace the external server entirely, short circuting the calls and instead, replying back instantly with the previously recorded response.

System in test

Installation

To install from PyPI, all you need to do is this:

  pip install cornell

Usage

Usage: cornell_server.py [OPTIONS]

  Usage Examples: Record mode: `cornell --forward_uri="https://remote_server/api" --record -cd custom_cassette_dir`
  Replay mode: `cornell -cd custom_cassette_dir

Options:
  -p, --port INTEGER
  -ff, --forward_uri TEXT         Must be provided in case of recording mode
  -, --record-once / --record-all
                                  Record each scenario only once, ignore the
                                  rest

  -r, --record                    Start server in record mode
  -fp, --fixed-path               Fixed cassettes path. If enabled, Cornell
                                  will support only one server for recording

  -cd, --cassettes-dir TEXT       Cassettes parent directory, If not
                                  specified, Cornell parent dir will be used

  --help                          Show this message and exit.

Demo - Full Example

Staring Cornell in record mode:

cornell -ff https://api.github.com/ --record -cd cassettes

This will start the server in record-proxy mode on port 9000, and will forward all requests to https://api.github.com/

asciicast

When cornell is in record mode, it will forward all request to the specified forwarding url, for example:

requests.get("http://127.0.0.1:9000/github/repos/kevin1024/vcrpy/license").json()

or

requests.get("http://127.0.0.1:9000/github/repos/kevin1024/vcrpy/license").json()

or you can browse to the url using your browser

Browser

Cornell will forward the request to the specified url and will record both the request and the response.

The yaml cassettes will be recorded in dedicated dictory (cassettes in the root dir, by default)

For example:

Cassette dir

Note

By default, `cassettes` directory will be created in cornell's root dir and will contain the cassette by destination hierarchy.
Use `-cd` to specify custom directory for your cassettes.
Mind that `-cd  should match for both record and replay modes

Once all the necessary interactions were recorded, stop cornell server using ctrl+c. Once stopped, all interactions will be mapped via an auto-generated index.yaml file.

Note

In case the `index.yaml` was already present, it will be updated with new interactions, otherwise new file will be created.

In this specific example, we can see that the 2 requests are mapped to the saved cassettes:

Index file

Features

Request Matchers

In addition to the vcrpy matchers, cornell provides the following custom request matchers:

  • OData request query matcher
  • SOAP request body matcher

Environment Variables

Since Cornell is a testing server it's executed by default with FLASK_ENV=local. You can modify this as described in flask configuration

Advanced Features

Can be found in the documentation

Contributing

Yes please! contributions are more than welcome!

Please follow PEP8 and the Python Naming Conventions

Add tests when you're adding new functionality and make sure all the existing tests are happy and green :)

To set up development environment:

  python -m venv venv
  source venv/bin/activate
  make configure

Running Tests

To run tests, run the following command

  python -m venv venv
  source venv/bin/activate
  make test
Owner
HiredScoreLabs
Open Source from HiredScore Engineering
HiredScoreLabs
Akulaku Create NewProduct Automation using Selenium Python

Akulaku-Create-NewProduct-Automation Akulaku Create NewProduct Automation using Selenium Python Usage: 1. Install Python 3.9 2. Open CMD on Bot Folde

Rahul Joshua Damanik 1 Nov 22, 2021
Green is a clean, colorful, fast python test runner.

Green -- A clean, colorful, fast python test runner. Features Clean - Low redundancy in output. Result statistics for each test is vertically aligned.

Nathan Stocks 756 Dec 22, 2022
✅ Python web automation and testing. 🚀 Fast, easy, reliable. 💠

Build fast, reliable, end-to-end tests. SeleniumBase is a Python framework for web automation, end-to-end testing, and more. Tests are run with "pytes

SeleniumBase 3k Jan 04, 2023
Public repo for automation scripts

Script_Quickies Public repo for automation scripts Dependencies Chrome webdriver .exe (make sure it matches the version of chrome you are using) Selen

CHR-onicles 1 Nov 04, 2021
Active Directory Penetration Testing methods with simulations

AD penetration Testing Project By Ruben Enkaoua - GL4Di4T0R Based on the TCM PEH course (Heath Adams) Index 1 - Setting Up the Lab Intallation of a Wi

GL4DI4T0R 3 Aug 12, 2021
Fully functioning price detector built with selenium and python

Fully functioning price detector built with selenium and python

mark sikaundi 4 Mar 30, 2022
자동 건강상태 자가진단 메크로 서버전용

Auto-Self-Diagnosis-for-server 자동 자가진단 메크로 서버전용 이 프로그램은 SaidBySolo님의 auto-self-diagnosis를 참고하여 제작하였습니다. 개인 사용 목적으로 제작하였기 때문에 추후 업데이트는 진행하지 않습니다. 의존성 G

JJooni 3 Dec 04, 2021
Asyncio http mocking. Similar to the responses library used for 'requests'

aresponses an asyncio testing server for mocking external services Features Fast mocks using actual network connections allows mocking some types of n

93 Nov 16, 2022
Sixpack is a language-agnostic a/b-testing framework

Sixpack Sixpack is a framework to enable A/B testing across multiple programming languages. It does this by exposing a simple API for client libraries

1.7k Dec 24, 2022
It helps to use fixtures in pytest.mark.parametrize

pytest-lazy-fixture Use your fixtures in @pytest.mark.parametrize. Installation pip install pytest-lazy-fixture Usage import pytest @pytest.fixture(p

Marsel Zaripov 299 Dec 24, 2022
1st Solution to QQ Browser 2021 AIAC Track 2

1st Solution to QQ Browser 2021 AIAC Track 2 This repository is the winning solution to QQ Browser 2021 AI Algorithm Competition Track 2 Automated Hyp

DAIR Lab 24 Sep 10, 2022
tidevice can be used to communicate with iPhone device

tidevice can be used to communicate with iPhone device

Alibaba 1.8k Jan 08, 2023
A simple tool to test internet stability.

pingtest Description A personal project for testing internet stability, intended for use in Linux and Windows.

chris 0 Oct 17, 2021
A collection of benchmarking tools.

Benchmark Utilities About A collection of benchmarking tools. PYPI Package Table of Contents Using the library Installing and using the library Manual

Kostas Georgiou 2 Jan 28, 2022
Photostudio是一款能进行自动化检测网页存活并实时给网页拍照的工具,通过调用Fofa/Zoomeye/360qua/shodan等 Api快速准确查询资产并进行网页截图,从而实施进一步的信息筛查。

Photostudio-红队快速爬取网页快照工具 一、简介: 正如其名:这是一款能进行自动化检测,实时给网页拍照的工具 信息收集要求所收集到的信息要真实可靠。 当然,这个原则是信息收集工作的最基本的要求。为达到这样的要求,信息收集者就必须对收集到的信息反复核实,不断检验,力求把误差减少到最低限度。我

s7ck Team 41 Dec 11, 2022
A rewrite of Python's builtin doctest module (with pytest plugin integration) but without all the weirdness

The xdoctest package is a re-write of Python's builtin doctest module. It replaces the old regex-based parser with a new abstract-syntax-tree based pa

Jon Crall 174 Dec 16, 2022
Just a small test with lists in cython

Test for lists in cython Algorithm create a list of 10^4 lists each with 10^4 floats values (namely: 0.1) - 2 nested for iterate each list and compute

Federico Simonetta 32 Jul 23, 2022
MongoDB panel for the Flask Debug Toolbar

Flask Debug Toolbar MongoDB Panel Info: An extension panel for Rob Hudson's Django Debug Toolbar that adds MongoDB debugging information Author: Harry

Cenk Altı 4 Dec 11, 2019
Lightweight, scriptable browser as a service with an HTTP API

Splash - A javascript rendering service Splash is a javascript rendering service with an HTTP API. It's a lightweight browser with an HTTP API, implem

Scrapinghub 3.8k Jan 03, 2023
Command line driven CI frontend and development task automation tool.

tox automation project Command line driven CI frontend and development task automation tool At its core tox provides a convenient way to run arbitrary

tox development team 3.1k Jan 04, 2023