Metadata-Version: 2.1
Name: pytest-mock-server
Version: 0.3.0
Summary: Mock server plugin for pytest
Home-page: https://github.com/AndreyErmilov/pytest-mock-server
Author: Andrey Ermilov
Author-email: andrerm@ya.ru
Maintainer: Andrey Ermilov
Maintainer-email: andrerm@ya.ru
License: MIT
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: Pytest
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Testing
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Operating System :: OS Independent
Classifier: License :: OSI Approved :: MIT License
Requires-Python: >=3.0
License-File: LICENSE
Requires-Dist: pytest (>=3.5.0)
Requires-Dist: flask (>=1.0)

==================
pytest-mock-server
==================

.. image:: https://img.shields.io/pypi/v/pytest-mock-server.svg
    :target: https://pypi.org/project/pytest-mock-server
    :alt: PyPI version

.. image:: https://img.shields.io/pypi/pyversions/pytest-mock-server.svg
    :target: https://pypi.org/project/pytest-mock-server
    :alt: Python versions

.. image:: https://travis-ci.org/AndreyErmilov/pytest-mock-server.svg?branch=master
    :target: https://travis-ci.org/AndreyErmilov/pytest-mock-server
    :alt: See Build Status on Travis CI


Mock server plugin for pytest

----

Installation
------------

You can install "pytest-mock-server" via `pip`_ from `PyPI`_::

    $ pip install pytest-mock-server


Usage
-----
One handler
~~~~~~~~~~~
.. code-block:: python

  import pytest
  import requests

  @pytest.mark.server(url='/v1/books/', response=[{'id': 1}], method='GET')
  def test_handler_responses():
      response = requests.get('http://localhost:5000/v1/books/')
      assert response.status_code == 200
      assert response.json() == [{'id': 1}]


More than one handlers
~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: python

  import pytest
  import requests

  @pytest.mark.server(url='/v1/books/', response=[{'id': 1}], method='GET')
  @pytest.mark.server(url='/v1/books/<book_id>/', response={'id': 1}, method='GET')
  def test_handler_responses():
      response = requests.get('http://localhost:5000/v1/books/')
      assert response.status_code == 200
      assert response.json() == [{'id': 1}]
      response = requests.get('http://localhost:5000/v1/books/1/')
      assert response.status_code == 200
      assert response.json() == {'id': 1}


Callback executes before response returns
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: python

  import pytest
  import requests
  import time

  def sleep_two(*args, **kwargs):
      time.sleep(2)

  @pytest.mark.server(url='/v1/books/', response={}, callback=sleep_two)
  def test_handler_responses():
      """Ensures Timeouts works"""
      with pytest.raises(requests.exceptions.Timeout):
          response = requests.get('http://localhost:5000/v1/books/', timeout=1)

Custom settings for server
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: python

  import pytest
  import requests

  @pytest.mark.server(url='/v1/books/', response={})
  @pytest.mark.server_settings(port=8000)
  def test_handler_responses():
      response = requests.get('http://localhost:8000/v1/books/')
      assert response.status_code == 200
      assert response.json() == {}


Contributing
------------
Contributions are very welcome. Tests can be run with `tox`_, please ensure
the coverage at least stays the same before you submit a pull request.

License
-------

Distributed under the terms of the `MIT`_ license, "pytest-mock-server" is free and open source software


Issues
------

If you encounter any problems, please `file an issue`_ along with a detailed description.

.. _`MIT`: http://opensource.org/licenses/MIT
.. _`file an issue`: https://github.com/AndreyErmilov/pytest-mock-server/issues
.. _`tox`: https://tox.readthedocs.io/en/latest/
.. _`pip`: https://pypi.org/project/pip/
.. _`PyPI`: https://pypi.org/project


