Giter Site home page Giter Site logo

mockpy's Introduction

Mockpy

Build Status PyPI version

Mockpy is a python command line utility to create development mock servers under Mac OS X easily.

Demo

Mockpy is inspired by wiremock and uses libmproxy for the proxy functionality. Mockpy works by reading a list of configuration files in the YAML format, it uses these configurations to match the HTTP request received and return an http response based on the matched YAML file configuration.

Why mockpy

  • You want a very lightweight utility to quickly create a mock API
  • No need to edit your app code as it uses proxy mocking
  • Works on top of proven technology (mitmproxy and cherrypi)
  • Update to the mock API are picked up from files without the need to start/restart the server again.
  • It works correctly with other network proxy debuggers like Charles.
  • It creates HTTP and HTTPS proxies, for HTTPS read here.

Installation

Mockpy can be installed as a python wheel using pip, as a standalone binary using homebrew, or by downloading the archived binary from release.

Installing using brew (recommended)

Install using brew tap

brew tap oarrabi/tap
brew install mockpy

Installing with pip

Make sure you have pip installed.

Run the following to install mockpy

pip install mockpy

Usage

It takes less than a minute to create a mock server with mockpy, check this demo.

Bellow is a description of the basic operations that mockpy provides, for a more comprehensive list, please refer to the wikis.

Initialize a directory

Initialize a the current folder by running:

mockpy init

This will create two folders:

inout: this folder will contains a list of mapping YAML files, each YAML file represents an request and response operation.

res: resource folder contains the static HTML, JSON, Images and static files returned as part of the mocking process.

To understand the YAML file format, please refer to the documentation.

Sample

request:
    method: GET
    url: .*sample/matching.*
response:
    status: 200
    body: hello world

The above catches all the GET request that has sample/matching in its URL, and returns the status 200. Requesting http://localhost:9090/sample/matching returns a response with "hello world" in its body.

More information about the YAML request/response check out the wikis.

Start the mock server

The mock server can be started as a standalone web server, or as a proxy server.

Standalone web server

Use mockpy start to start the standalone web server, this will setup a server on the default port. Visit 127.0.0.1:9090 to check the mock server.

Proxy web server

To start mockpy in proxy server mode use mockpy start -x. This command does the following:

  • Starts a proxy server on '127.0.0.1:9090'
  • Sets the macs HTTP/HTTPS settings to the created proxy server.

Documentation

Mockpy contains a documentation that can be accessed following this link.

Clean up

Running mockpy with in web-proxy mode with mockpy start -x changes mac web proxy to the newly created proxy. Mac proxy settings are then reset when mockpy exits.
If you end mockpy unexpectedly, such as closing the terminal window, mockpy has no way of resetting the mac proxy. In order to reset them again to their defaults run:

mockpy cleanup

Future milestones and improvements

Mockpy is still under development, the following is a list of tasks and improvement it still lacks:

  • Create a better documentation
  • Devise a proper mechanism to format the printed HTTP request and response.
  • Provide more command line flags options

mockpy's People

Watchers

Jianjun avatar James Cloos avatar

Forkers

ezhvsalate

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.