/rmock

Primary LanguagePythonGNU Lesser General Public License v3.0LGPL-3.0

Rmock

The rmock is a python library for writing server mocks, with API inspired by mock package. It`s designed to be used mainly in unit and functional testing. Http, memcache, smtp and pop3 protocols are supported for now, more will come out later.

Installation

Just clone the project repo and run python setup.py install in main directory.

Dependencies

Library was tested on python 2.7 under various Linux distributions.

Examples

Here`s a basic usage example. More will be added later, you can also look into tests directory.

>>> import rmock
>>> import urllib2
>>> http_mock = rmock.run("http", port=37666)
>>> http_mock
rmock(name= runner=http(port=37666 slug=))
>>> http_mock.function.return_value = "function result"
>>> url = 'http://localhost:37666/function?param=value'
>>> result = urllib2.urlopen(url).read()
>>> assert result == "function result"
>>> http_mock.function.calls
[call(funcname=function args=() kwargs={'param': 'value'})]
>>> http_mock.function.assert_called_with(param='value')

Testing

Tests use nose and are located in tests directory. Before running them dependencies should be installed. They are stored in tests/requirements.txt, in format suitable for pip install -r command.

Documentation

More detailed documentation will come out in near future. For now, tests are self-documenting and could be good source of usage examples.