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
An interactive TLS-capable intercepting HTTP proxy for penetration testers and software developers.

mitmproxy mitmproxy is an interactive, SSL/TLS-capable intercepting proxy with a console interface for HTTP/1, HTTP/2, and WebSockets. mitmdump is the

mitmproxy 29.7k Jan 02, 2023
The best, free, all in one, multichecking, pentesting utility

The best, free, all in one, multichecking, pentesting utility

Mickey 58 Jan 03, 2023
Test for generating stylized circuit traces from images

I test of an image processing idea to take an image and make neat circuit board art automatically. Inspired by this twitter post by @JackRhysider

Miller Hooks 3 Dec 12, 2022
Browser reload with uvicorn

uvicorn-browser This project is inspired by autoreload. Installation pip install uvicorn-browser Usage Run uvicorn-browser --help to see all options.

Marcelo Trylesinski 64 Dec 17, 2022
Django-google-optimize is a Django application designed to make running server side Google Optimize A/B tests easy.

Django-google-optimize Django-google-optimize is a Django application designed to make running Google Optimize A/B tests easy. Here is a tutorial on t

Adin Hodovic 39 Oct 25, 2022
Divide full port scan results and use it for targeted Nmap runs

Divide Et Impera And Scan (and also merge the scan results) DivideAndScan is used to efficiently automate port scanning routine by splitting it into 3

snovvcrash 226 Dec 30, 2022
pytest plugin for manipulating test data directories and files

pytest-datadir pytest plugin for manipulating test data directories and files. Usage pytest-datadir will look up for a directory with the name of your

Gabriel Reis 191 Dec 21, 2022
Scalable user load testing tool written in Python

Locust Locust is an easy to use, scriptable and scalable performance testing tool. You define the behaviour of your users in regular Python code, inst

Locust.io 20.4k Jan 04, 2023
Spam the buzzer and upgrade automatically - Selenium

CookieClicker Usage: Let's check your chrome navigator version : Consequently, you have to : download the right chromedriver in the follow link : http

Iliam Amara 1 Nov 22, 2021
A cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.

PyAutoGUI PyAutoGUI is a cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard. pip inst

Al Sweigart 7.5k Dec 31, 2022
ApiPy was created for api testing with Python pytest framework which has also requests, assertpy and pytest-html-reporter libraries.

ApiPy was created for api testing with Python pytest framework which has also requests, assertpy and pytest-html-reporter libraries. With this f

Mustafa 1 Jul 11, 2022
Python Projects - Few Python projects with Testing using Pytest

Python_Projects Few Python projects : Fast_API_Docker_PyTest- Just a simple auto

Tal Mogendorff 1 Jan 22, 2022
Tattoo - System for automating the Gentoo arch testing process

Naming origin Well, naming things is very hard. Thankfully we have an excellent

Arthur Zamarin 4 Nov 07, 2022
Automated Security Testing For REST API's

Astra REST API penetration testing is complex due to continuous changes in existing APIs and newly added APIs. Astra can be used by security engineers

Flipkart Incubator 2.1k Dec 31, 2022
A set of pytest fixtures to test Flask applications

pytest-flask An extension of pytest test runner which provides a set of useful tools to simplify testing and development of the Flask extensions and a

pytest-dev 433 Dec 23, 2022
User-interest mock backend server implemnted using flask restful, and SQLAlchemy ORM confiugred with sqlite

Flask_Restful_SQLAlchemy_server User-interest mock backend server implemnted using flask restful, and SQLAlchemy ORM confiugred with sqlite. Backend b

Austin Weigel 1 Nov 17, 2022
show python coverage information directly in emacs

show python coverage information directly in emacs

wouter bolsterlee 30 Oct 26, 2022
Ab testing - basically a statistical test in which two or more variants

Ab testing - basically a statistical test in which two or more variants

Buse Yıldırım 5 Mar 13, 2022
Wraps any WSGI application and makes it easy to send test requests to that application, without starting up an HTTP server.

WebTest This wraps any WSGI application and makes it easy to send test requests to that application, without starting up an HTTP server. This provides

Pylons Project 325 Dec 30, 2022
Code for "SUGAR: Subgraph Neural Network with Reinforcement Pooling and Self-Supervised Mutual Information Mechanism"

SUGAR Code for "SUGAR: Subgraph Neural Network with Reinforcement Pooling and Self-Supervised Mutual Information Mechanism" Overview train.py: the cor

41 Nov 08, 2022