• Stars
    star
    138
  • Rank 264,508 (Top 6 %)
  • Language
    Python
  • Created over 9 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Mockpy is an open source tool to quickly create mock servers.

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

More Repositories

1

OAStackView

Porting UIStackView to iOS 7+
Objective-C
2,141
star
2

Swiftline

Swiftline is a set of tools to help you create command line applications.
Swift
1,197
star
3

Guaka

The smartest and most beautiful (POSIX compliant) Command line framework for Swift 🤖
Swift
1,146
star
4

Download-Manager

iOS download manager, Download a set of files in parallel and sequential order.
Objective-C
196
star
5

OALayoutAnchor

Porting NSLayoutAnchor to iOS7 (full port)
Objective-C
83
star
6

Collection-Each

Adding ruby style each iterator to Cocoa/Cocoa touch Swift Array and Range classes, And Int.times{} to Int class
Swift
65
star
7

facebook_messenger

ExFacebookMessenger is a library that helps you create facebook messenger bots easily.
Elixir
58
star
8

OAStatusItemKit

OAStatusItemKit allows you to easily create mac status bar apps with a swifty flavour.
Swift
34
star
9

github-project-landing-page

A Github project landing page theme for Hugo.
HTML
27
star
10

exrequester

Quickly create API clients using module attributes.
Elixir
19
star
11

phoenix_facebook_echo_bot

Elixir sample facebook messenger echo bot using Phoenix framework.
Elixir
19
star
12

RangeSliderView

RangeSliderView provide an easy to use range selection view.
Swift
18
star
13

zenixir

Elixir Zendesk API Client http://developer.zendesk.com/
Elixir
17
star
14

ipa_utilities

Simple ruby gem to execute common ipa utilities, such as verify integrity, convert certificate formats, re-signs an ipa using a new provision profile and more.
Ruby
17
star
15

xserverpy

Manage Xcode server bots from the command line, without the need to open or install Xcode.
Python
16
star
16

dtracer

DTracer is part ruby gem, part iOS pod, that helps the sending and receiving of DTrace commands.
Ruby
14
star
17

IAModelBase

Json (and NSDictionary) to Objective c Model Helper
Objective-C
14
star
18

CodeImager

Generate a beautiful image from a code snippet on Mac OS.
11
star
19

phoenix_facebook_messenger

PhoenixFacebookMessenger is a library that helps you create facebook messenger bots easily with phoenix.
Elixir
10
star
20

Suas-iOS

Unidirectional data flow architecture implementation for iOS, macOS, tvOS and watchOS
Swift
8
star
21

JavaErlang

Java Erlang Integration using JInterface (OtpErlang)
Java
8
star
22

IASequenceAnimations

Perform a sequence of animations one after the other using blocks
Objective-C
8
star
23

ex_stub

ExStub provides an easy way to stub a module and record the function calls on it.
Elixir
8
star
24

OADTracer

Objective c library that facilitates the sending of DTrace commands.
Objective-C
8
star
25

Sublime-Text-Midnight

Sublime Text Midnight Theme (ported from Xcode Midnight theme)
7
star
26

IADraggableViewController

Create an apple iOS5 camera like View Controllers container
Objective-C
7
star
27

specipy

Extract spec descriptions from Kiwi
Python
7
star
28

StringScanner

A string scanner (similar to NSScanner) implementation purely implemented in swift written in swift
Swift
6
star
29

Storyboard_Layout_Translator

Storyboard Layout Translator
Ruby
5
star
30

profiles

A gem that searches local provision profiles and an ipa for a UDID
Ruby
4
star
31

IAAnimationTable

Fun with UITableView
Objective-C
4
star
32

RandomUser

Objective c iOS library for to generate random users, using https://randomuser.me/
Objective-C
3
star
33

Guaka-Generator

Guaka command line application generator app.
Swift
3
star
34

EmojiOntology

Emoji ontology project for UCD
Web Ontology Language
3
star
35

Currying-refresh-token

A swift playground containing samples on how to use swift functional currying
Swift
2
star
36

ObjcAndSwift

Objective-C and Swift in the same Dynamic Framework Target
Objective-C
2
star
37

Suas-Monitor

Cross-platform desktop app for visualizing and debugging apps built with Suas
TypeScript
1
star
38

TestTrunk

Ruby
1
star
39

Environ

Environ is a library that wrap libc environ to get all the environment variables passed to an application
Swift
1
star
40

LeftPad

Swift implementation of the famous npm left-pad (http://left-pad.io/) module
Ruby
1
star
41

homebrew-tap

Homebrew tap for mockpy
Ruby
1
star
42

elixir-algos

Some algorithm solutions in Elixir
Elixir
1
star
43

Swift-type-erasure-playground

Swift Type erasure playground
Swift
1
star