Socket Mock Framework
Project description
A socket mock framework
Installation
Using pip:
$ pip install mocket
Quick example
Let’s create a new virtualenv with all we need:
$ virtualenv example $ source example/bin/activate $ pip install pytest requests mocket
As second step, we create an example.py file as the following one:
from unittest import TestCase import json from mocket.mocket import mocketize from mocket.mockhttp import Entry import requests class Example(TestCase): @mocketize def test_json(self): url_to_mock = 'http://testme.org/intro' response_to_mock = { "integer": 1, "string": "asd", "boolean": False, } Entry.single_register( Entry.GET, url_to_mock, body=json.dumps(response_to_mock), headers={'content-type': 'application/json'} ) response = requests.get(url_to_mock).json() self.assertEqual(response, response_to_mock)
Let’s fire our example test:
$ py.test example.py::Example::test_json
Video presentation
EuroPython 2013, Florence
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mocket-1.2.5.tar.gz
(7.6 kB
view hashes)