mocket


Namemocket JSON
Version 3.12.5 PyPI version JSON
download
home_pageNone
SummarySocket Mock Framework - for all kinds of socket animals, web-clients included - with gevent/asyncio/SSL support
upload_time2024-04-14 18:12:21
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseCopyright (c) 2017-2023 Giorgio Salluzzo and individual contributors. All rights reserved. Copyright (c) 2013-2017 Andrea de Marco, Giorgio Salluzzo and individual contributors. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the Mocket nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            ===============
mocket /mɔˈkɛt/
===============

.. image:: https://github.com/mindflayer/python-mocket/workflows/Mocket's%20CI/badge.svg
    :target: https://github.com/mindflayer/python-mocket/actions?query=workflow%3A%22Mocket%27s+CI%22

.. image:: https://coveralls.io/repos/github/mindflayer/python-mocket/badge.svg?branch=master
    :target: https://coveralls.io/github/mindflayer/python-mocket?branch=master

.. image:: https://app.codacy.com/project/badge/Grade/6327640518ce42adaf59368217028f14
    :target: https://www.codacy.com/gh/mindflayer/python-mocket/dashboard

.. image:: https://img.shields.io/pypi/dm/mocket
    :target: https://pypistats.org/packages/mocket


A socket mock framework
-------------------------
    for all kinds of socket *animals*, web-clients included - with gevent/asyncio/SSL support

...and then MicroPython's *urequests* (*mocket >= 3.9.1*)

Outside GitHub
==============

Mocket packages are available for `Arch Linux`_, `openSUSE`_, `NixOS`_, `ALT Linux`_ and `NetBSD`_.

.. _`Arch Linux`: https://archlinux.org/packages/extra/any/python-mocket/
.. _`openSUSE`: https://software.opensuse.org/search?baseproject=ALL&q=mocket
.. _`NixOS`: https://search.nixos.org/packages?query=mocket
.. _`ALT Linux`: https://packages.altlinux.org/en/sisyphus/srpms/python3-module-mocket/
.. _`NetBSD`: https://cdn.netbsd.org/pub/pkgsrc/current/pkgsrc/devel/py-mocket/index.html


Versioning
==========
Starting from *3.7.0*, Mocket major version will follow the same numbering pattern as Python's and therefore indicate the most recent Python version that is supported.

FYI: the last version compatible with Python 2.7 is *3.9.4*, bugfixing or backporting of features introduced after that release will only be available as commercial support.

Support it
==========
*Star* the project on GitHub, *Buy Me a Coffee* clicking the button below or, even better, contribute with patches or documentation.

.. image:: https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png
     :target: https://www.buymeacoffee.com/mocket
     :alt: Buy Me A Coffee

How to use it
=============
Read the following blog posts if you want to have a big picture of what *Mocket* is capable of:

- https://medium.com/p/mocket-is-alive-and-is-fighting-with-us-b2810d52597a
- https://hackernoon.com/make-development-great-again-faab769d264e
- https://hackernoon.com/httpretty-now-supports-asyncio-e310814704c6
- https://medium.com/@mindflayer/how-to-make-your-tests-fail-when-they-try-to-access-the-network-python-eb80090a6d24
- https://medium.com/@mindflayer/testing-in-an-asyncio-world-a9a0ad41b0c5

The starting point to understand how to use *Mocket* to write a custom mock is the following example:

- https://github.com/mindflayer/mocketoy

As next step, you are invited to have a look at the implementation of both the mocks it provides:

- HTTP mock (similar to HTTPretty) - https://github.com/mindflayer/python-mocket/blob/master/mocket/mockhttp.py
- Redis mock (basic implementation) - https://github.com/mindflayer/python-mocket/blob/master/mocket/mockredis.py

Please also have a look at the huge test suite:

- Tests module at https://github.com/mindflayer/python-mocket/tree/master/tests

Installation
============
Using pip::

    $ pip install mocket

Speedups
========
Mocket uses **xxhash** when available instead of *hashlib.md5* for creating hashes, you can install it as follows::

    $ pip install mocket[speedups]

Issues
============
When opening an **Issue**, please add few lines of code as failing test, or -better- open its relative **Pull request** adding this test to our test suite.

Example of how to mock an HTTP[S] call
======================================
Let's create a new virtualenv with all we need::

    $ python3 -m venv example
    $ source example/bin/activate
    $ pip install pytest requests mocket

As second step, we create an `example.py` file as the following one:

.. code-block:: python

    import json

    from mocket import mocketize
    from mocket.mockhttp import Entry
    import requests
    import pytest


    @pytest.fixture
    def response():
        return {
            "integer": 1,
            "string": "asd",
            "boolean": False,
        }


    @mocketize  # use its decorator
    def test_json(response):
        url_to_mock = 'https://testme.org/json'

        Entry.single_register(
            Entry.GET,
            url_to_mock,
            body=json.dumps(response),
            headers={'content-type': 'application/json'}
        )

        mocked_response = requests.get(url_to_mock).json()

        assert response == mocked_response

    # OR use its context manager
    from mocket import Mocketizer

    def test_json_with_context_manager(response):
        url_to_mock = 'https://testme.org/json'

        Entry.single_register(
            Entry.GET,
            url_to_mock,
            body=json.dumps(response),
            headers={'content-type': 'application/json'}
        )

        with Mocketizer():
            mocked_response = requests.get(url_to_mock).json()

        assert response == mocked_response

Let's fire our example test::

    $ py.test example.py

How to make Mocket fail when it tries to write to a real `socket`?
==================================================================
NEW!!! Sometimes you just want your tests to fail when they attempt to use the network.

.. code-block:: python

    with Mocketizer(strict_mode=True):
        with pytest.raises(StrictMocketException):
            requests.get("https://duckduckgo.com/")

    # OR

    @mocketize(strict_mode=True)
    def test_get():
        with pytest.raises(StrictMocketException):
            requests.get("https://duckduckgo.com/")

You can specify exceptions as a list of hosts or host-port pairs.

.. code-block:: python

    with Mocketizer(strict_mode=True, strict_mode_allowed=["localhost", ("intake.ourmetrics.net", 443)]):
        ...

    # OR

    @mocketize(strict_mode=True, strict_mode_allowed=["localhost", ("intake.ourmetrics.net", 443)])
    def test_get():
        ...


How to be sure that all the Entry instances have been served?
=============================================================
Add this instruction at the end of the test execution:

.. code-block:: python

    Mocket.assert_fail_if_entries_not_served()

Example of how to fake socket errors
====================================

It's very important that we test non-happy paths.

.. code-block:: python

    @mocketize
    def test_raise_exception(self):
        url = "http://github.com/fluidicon.png"
        Entry.single_register(Entry.GET, url, exception=socket.error())
        with self.assertRaises(requests.exceptions.ConnectionError):
            requests.get(url)

Example of how to record real socket traffic
============================================

You probably know what *VCRpy* is capable of, that's the *mocket*'s way of achieving it:

.. code-block:: python

    @mocketize(truesocket_recording_dir=tempfile.mkdtemp())
    def test_truesendall_with_recording_https():
        url = 'https://httpbin.org/ip'

        requests.get(url, headers={"Accept": "application/json"})
        resp = requests.get(url, headers={"Accept": "application/json"})
        assert resp.status_code == 200

        dump_filename = os.path.join(
            Mocket.get_truesocket_recording_dir(),
            Mocket.get_namespace() + '.json',
        )
        with io.open(dump_filename) as f:
            response = json.load(f)

        assert len(response['httpbin.org']['443'].keys()) == 1

HTTPretty compatibility layer
=============================
Mocket HTTP mock can work as *HTTPretty* replacement for many different use cases. Two main features are missing:

- URL entries containing regular expressions;
- response body from functions (used mostly to fake errors, *mocket* doesn't need to do it this way).

Two features which are against the Zen of Python, at least imho (*mindflayer*), but of course I am open to call it into question.

Example:

.. code-block:: python

    import json

    import aiohttp
    import asyncio
    from unittest import TestCase

    from mocket.plugins.httpretty import httpretty, httprettified


    class AioHttpEntryTestCase(TestCase):
        @httprettified
        def test_https_session(self):
            url = 'https://httpbin.org/ip'
            httpretty.register_uri(
                httpretty.GET,
                url,
                body=json.dumps(dict(origin='127.0.0.1')),
            )

            async def main(l):
                async with aiohttp.ClientSession(
                    loop=l, timeout=aiohttp.ClientTimeout(total=3)
                ) as session:
                    async with session.get(url) as get_response:
                        assert get_response.status == 200
                        assert await get_response.text() == '{"origin": "127.0.0.1"}'

            loop = asyncio.new_event_loop()
            loop.set_debug(True)
            loop.run_until_complete(main(loop))

What about the other socket animals?
====================================
Using *Mocket* with asyncio based clients::

    $ pip install aiohttp

Example:

.. code-block:: python

    class AioHttpEntryTestCase(TestCase):
        @mocketize
        def test_http_session(self):
            url = 'http://httpbin.org/ip'
            body = "asd" * 100
            Entry.single_register(Entry.GET, url, body=body, status=404)
            Entry.single_register(Entry.POST, url, body=body*2, status=201)

            async def main(l):
                async with aiohttp.ClientSession(
                    loop=l, timeout=aiohttp.ClientTimeout(total=3)
                ) as session:
                    async with session.get(url) as get_response:
                        assert get_response.status == 404
                        assert await get_response.text() == body

                    async with session.post(url, data=body * 6) as post_response:
                        assert post_response.status == 201
                        assert await post_response.text() == body * 2

            loop = asyncio.new_event_loop()
            loop.run_until_complete(main(loop))

    # or again with a unittest.IsolatedAsyncioTestCase
    from mocket.async_mocket import async_mocketize

    class AioHttpEntryTestCase(IsolatedAsyncioTestCase):
        @async_mocketize
        async def test_http_session(self):
            url = 'http://httpbin.org/ip'
            body = "asd" * 100
            Entry.single_register(Entry.GET, url, body=body, status=404)
            Entry.single_register(Entry.POST, url, body=body * 2, status=201)

            async with aiohttp.ClientSession(
                timeout=aiohttp.ClientTimeout(total=3)
            ) as session:
                async with session.get(url) as get_response:
                    assert get_response.status == 404
                    assert await get_response.text() == body

                async with session.post(url, data=body * 6) as post_response:
                    assert post_response.status == 201
                    assert await post_response.text() == body * 2
                    assert Mocket.last_request().method == 'POST'
                    assert Mocket.last_request().body == body * 6


Works well with others
=======================
Using *Mocket* as pook_ engine::

    $ pip install mocket[pook]

.. _pook: https://pypi.python.org/pypi/pook

Example:

.. code-block:: python

    import pook
    from mocket.plugins.pook_mock_engine import MocketEngine

    pook.set_mock_engine(MocketEngine)

    pook.on()

    url = 'http://twitter.com/api/1/foobar'
    status = 404
    response_json = {'error': 'foo'}

    mock = pook.get(
        url,
        headers={'content-type': 'application/json'},
        reply=status,
        response_json=response_json,
    )
    mock.persist()

    requests.get(url)
    assert mock.calls == 1

    resp = requests.get(url)
    assert resp.status_code == status
    assert resp.json() == response_json
    assert mock.calls == 2

First appearance
================
EuroPython 2013, Florence

- Video: https://www.youtube.com/watch?v=-LvXbl5d02U
- Slides: https://prezi.com/tmuiaugamsti/mocket/
- Slides as PDF: https://ep2013.europython.eu/media/conference/slides/mocket-a-socket-mock-framework.pdf

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "mocket",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "Giorgio Salluzzo <giorgio.salluzzo@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/3d/37/c2ed7fcd586d0c51c172d5502f6418960a3a19c8c929d88b9122b08731ce/mocket-3.12.5.tar.gz",
    "platform": null,
    "description": "===============\nmocket /m\u0254\u02c8k\u025bt/\n===============\n\n.. image:: https://github.com/mindflayer/python-mocket/workflows/Mocket's%20CI/badge.svg\n    :target: https://github.com/mindflayer/python-mocket/actions?query=workflow%3A%22Mocket%27s+CI%22\n\n.. image:: https://coveralls.io/repos/github/mindflayer/python-mocket/badge.svg?branch=master\n    :target: https://coveralls.io/github/mindflayer/python-mocket?branch=master\n\n.. image:: https://app.codacy.com/project/badge/Grade/6327640518ce42adaf59368217028f14\n    :target: https://www.codacy.com/gh/mindflayer/python-mocket/dashboard\n\n.. image:: https://img.shields.io/pypi/dm/mocket\n    :target: https://pypistats.org/packages/mocket\n\n\nA socket mock framework\n-------------------------\n    for all kinds of socket *animals*, web-clients included - with gevent/asyncio/SSL support\n\n...and then MicroPython's *urequests* (*mocket >= 3.9.1*)\n\nOutside GitHub\n==============\n\nMocket packages are available for `Arch Linux`_, `openSUSE`_, `NixOS`_, `ALT Linux`_ and `NetBSD`_.\n\n.. _`Arch Linux`: https://archlinux.org/packages/extra/any/python-mocket/\n.. _`openSUSE`: https://software.opensuse.org/search?baseproject=ALL&q=mocket\n.. _`NixOS`: https://search.nixos.org/packages?query=mocket\n.. _`ALT Linux`: https://packages.altlinux.org/en/sisyphus/srpms/python3-module-mocket/\n.. _`NetBSD`: https://cdn.netbsd.org/pub/pkgsrc/current/pkgsrc/devel/py-mocket/index.html\n\n\nVersioning\n==========\nStarting from *3.7.0*, Mocket major version will follow the same numbering pattern as Python's and therefore indicate the most recent Python version that is supported.\n\nFYI: the last version compatible with Python 2.7 is *3.9.4*, bugfixing or backporting of features introduced after that release will only be available as commercial support.\n\nSupport it\n==========\n*Star* the project on GitHub, *Buy Me a Coffee* clicking the button below or, even better, contribute with patches or documentation.\n\n.. image:: https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png\n     :target: https://www.buymeacoffee.com/mocket\n     :alt: Buy Me A Coffee\n\nHow to use it\n=============\nRead the following blog posts if you want to have a big picture of what *Mocket* is capable of:\n\n- https://medium.com/p/mocket-is-alive-and-is-fighting-with-us-b2810d52597a\n- https://hackernoon.com/make-development-great-again-faab769d264e\n- https://hackernoon.com/httpretty-now-supports-asyncio-e310814704c6\n- https://medium.com/@mindflayer/how-to-make-your-tests-fail-when-they-try-to-access-the-network-python-eb80090a6d24\n- https://medium.com/@mindflayer/testing-in-an-asyncio-world-a9a0ad41b0c5\n\nThe starting point to understand how to use *Mocket* to write a custom mock is the following example:\n\n- https://github.com/mindflayer/mocketoy\n\nAs next step, you are invited to have a look at the implementation of both the mocks it provides:\n\n- HTTP mock (similar to HTTPretty) - https://github.com/mindflayer/python-mocket/blob/master/mocket/mockhttp.py\n- Redis mock (basic implementation) - https://github.com/mindflayer/python-mocket/blob/master/mocket/mockredis.py\n\nPlease also have a look at the huge test suite:\n\n- Tests module at https://github.com/mindflayer/python-mocket/tree/master/tests\n\nInstallation\n============\nUsing pip::\n\n    $ pip install mocket\n\nSpeedups\n========\nMocket uses **xxhash** when available instead of *hashlib.md5* for creating hashes, you can install it as follows::\n\n    $ pip install mocket[speedups]\n\nIssues\n============\nWhen opening an **Issue**, please add few lines of code as failing test, or -better- open its relative **Pull request** adding this test to our test suite.\n\nExample of how to mock an HTTP[S] call\n======================================\nLet's create a new virtualenv with all we need::\n\n    $ python3 -m venv example\n    $ source example/bin/activate\n    $ pip install pytest requests mocket\n\nAs second step, we create an `example.py` file as the following one:\n\n.. code-block:: python\n\n    import json\n\n    from mocket import mocketize\n    from mocket.mockhttp import Entry\n    import requests\n    import pytest\n\n\n    @pytest.fixture\n    def response():\n        return {\n            \"integer\": 1,\n            \"string\": \"asd\",\n            \"boolean\": False,\n        }\n\n\n    @mocketize  # use its decorator\n    def test_json(response):\n        url_to_mock = 'https://testme.org/json'\n\n        Entry.single_register(\n            Entry.GET,\n            url_to_mock,\n            body=json.dumps(response),\n            headers={'content-type': 'application/json'}\n        )\n\n        mocked_response = requests.get(url_to_mock).json()\n\n        assert response == mocked_response\n\n    # OR use its context manager\n    from mocket import Mocketizer\n\n    def test_json_with_context_manager(response):\n        url_to_mock = 'https://testme.org/json'\n\n        Entry.single_register(\n            Entry.GET,\n            url_to_mock,\n            body=json.dumps(response),\n            headers={'content-type': 'application/json'}\n        )\n\n        with Mocketizer():\n            mocked_response = requests.get(url_to_mock).json()\n\n        assert response == mocked_response\n\nLet's fire our example test::\n\n    $ py.test example.py\n\nHow to make Mocket fail when it tries to write to a real `socket`?\n==================================================================\nNEW!!! Sometimes you just want your tests to fail when they attempt to use the network.\n\n.. code-block:: python\n\n    with Mocketizer(strict_mode=True):\n        with pytest.raises(StrictMocketException):\n            requests.get(\"https://duckduckgo.com/\")\n\n    # OR\n\n    @mocketize(strict_mode=True)\n    def test_get():\n        with pytest.raises(StrictMocketException):\n            requests.get(\"https://duckduckgo.com/\")\n\nYou can specify exceptions as a list of hosts or host-port pairs.\n\n.. code-block:: python\n\n    with Mocketizer(strict_mode=True, strict_mode_allowed=[\"localhost\", (\"intake.ourmetrics.net\", 443)]):\n        ...\n\n    # OR\n\n    @mocketize(strict_mode=True, strict_mode_allowed=[\"localhost\", (\"intake.ourmetrics.net\", 443)])\n    def test_get():\n        ...\n\n\nHow to be sure that all the Entry instances have been served?\n=============================================================\nAdd this instruction at the end of the test execution:\n\n.. code-block:: python\n\n    Mocket.assert_fail_if_entries_not_served()\n\nExample of how to fake socket errors\n====================================\n\nIt's very important that we test non-happy paths.\n\n.. code-block:: python\n\n    @mocketize\n    def test_raise_exception(self):\n        url = \"http://github.com/fluidicon.png\"\n        Entry.single_register(Entry.GET, url, exception=socket.error())\n        with self.assertRaises(requests.exceptions.ConnectionError):\n            requests.get(url)\n\nExample of how to record real socket traffic\n============================================\n\nYou probably know what *VCRpy* is capable of, that's the *mocket*'s way of achieving it:\n\n.. code-block:: python\n\n    @mocketize(truesocket_recording_dir=tempfile.mkdtemp())\n    def test_truesendall_with_recording_https():\n        url = 'https://httpbin.org/ip'\n\n        requests.get(url, headers={\"Accept\": \"application/json\"})\n        resp = requests.get(url, headers={\"Accept\": \"application/json\"})\n        assert resp.status_code == 200\n\n        dump_filename = os.path.join(\n            Mocket.get_truesocket_recording_dir(),\n            Mocket.get_namespace() + '.json',\n        )\n        with io.open(dump_filename) as f:\n            response = json.load(f)\n\n        assert len(response['httpbin.org']['443'].keys()) == 1\n\nHTTPretty compatibility layer\n=============================\nMocket HTTP mock can work as *HTTPretty* replacement for many different use cases. Two main features are missing:\n\n- URL entries containing regular expressions;\n- response body from functions (used mostly to fake errors, *mocket* doesn't need to do it this way).\n\nTwo features which are against the Zen of Python, at least imho (*mindflayer*), but of course I am open to call it into question.\n\nExample:\n\n.. code-block:: python\n\n    import json\n\n    import aiohttp\n    import asyncio\n    from unittest import TestCase\n\n    from mocket.plugins.httpretty import httpretty, httprettified\n\n\n    class AioHttpEntryTestCase(TestCase):\n        @httprettified\n        def test_https_session(self):\n            url = 'https://httpbin.org/ip'\n            httpretty.register_uri(\n                httpretty.GET,\n                url,\n                body=json.dumps(dict(origin='127.0.0.1')),\n            )\n\n            async def main(l):\n                async with aiohttp.ClientSession(\n                    loop=l, timeout=aiohttp.ClientTimeout(total=3)\n                ) as session:\n                    async with session.get(url) as get_response:\n                        assert get_response.status == 200\n                        assert await get_response.text() == '{\"origin\": \"127.0.0.1\"}'\n\n            loop = asyncio.new_event_loop()\n            loop.set_debug(True)\n            loop.run_until_complete(main(loop))\n\nWhat about the other socket animals?\n====================================\nUsing *Mocket* with asyncio based clients::\n\n    $ pip install aiohttp\n\nExample:\n\n.. code-block:: python\n\n    class AioHttpEntryTestCase(TestCase):\n        @mocketize\n        def test_http_session(self):\n            url = 'http://httpbin.org/ip'\n            body = \"asd\" * 100\n            Entry.single_register(Entry.GET, url, body=body, status=404)\n            Entry.single_register(Entry.POST, url, body=body*2, status=201)\n\n            async def main(l):\n                async with aiohttp.ClientSession(\n                    loop=l, timeout=aiohttp.ClientTimeout(total=3)\n                ) as session:\n                    async with session.get(url) as get_response:\n                        assert get_response.status == 404\n                        assert await get_response.text() == body\n\n                    async with session.post(url, data=body * 6) as post_response:\n                        assert post_response.status == 201\n                        assert await post_response.text() == body * 2\n\n            loop = asyncio.new_event_loop()\n            loop.run_until_complete(main(loop))\n\n    # or again with a unittest.IsolatedAsyncioTestCase\n    from mocket.async_mocket import async_mocketize\n\n    class AioHttpEntryTestCase(IsolatedAsyncioTestCase):\n        @async_mocketize\n        async def test_http_session(self):\n            url = 'http://httpbin.org/ip'\n            body = \"asd\" * 100\n            Entry.single_register(Entry.GET, url, body=body, status=404)\n            Entry.single_register(Entry.POST, url, body=body * 2, status=201)\n\n            async with aiohttp.ClientSession(\n                timeout=aiohttp.ClientTimeout(total=3)\n            ) as session:\n                async with session.get(url) as get_response:\n                    assert get_response.status == 404\n                    assert await get_response.text() == body\n\n                async with session.post(url, data=body * 6) as post_response:\n                    assert post_response.status == 201\n                    assert await post_response.text() == body * 2\n                    assert Mocket.last_request().method == 'POST'\n                    assert Mocket.last_request().body == body * 6\n\n\nWorks well with others\n=======================\nUsing *Mocket* as pook_ engine::\n\n    $ pip install mocket[pook]\n\n.. _pook: https://pypi.python.org/pypi/pook\n\nExample:\n\n.. code-block:: python\n\n    import pook\n    from mocket.plugins.pook_mock_engine import MocketEngine\n\n    pook.set_mock_engine(MocketEngine)\n\n    pook.on()\n\n    url = 'http://twitter.com/api/1/foobar'\n    status = 404\n    response_json = {'error': 'foo'}\n\n    mock = pook.get(\n        url,\n        headers={'content-type': 'application/json'},\n        reply=status,\n        response_json=response_json,\n    )\n    mock.persist()\n\n    requests.get(url)\n    assert mock.calls == 1\n\n    resp = requests.get(url)\n    assert resp.status_code == status\n    assert resp.json() == response_json\n    assert mock.calls == 2\n\nFirst appearance\n================\nEuroPython 2013, Florence\n\n- Video: https://www.youtube.com/watch?v=-LvXbl5d02U\n- Slides: https://prezi.com/tmuiaugamsti/mocket/\n- Slides as PDF: https://ep2013.europython.eu/media/conference/slides/mocket-a-socket-mock-framework.pdf\n",
    "bugtrack_url": null,
    "license": "Copyright (c) 2017-2023 Giorgio Salluzzo and individual contributors. All rights reserved. Copyright (c) 2013-2017 Andrea de Marco, Giorgio Salluzzo and individual contributors. All rights reserved.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.  3. Neither the name of the Mocket nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.",
    "summary": "Socket Mock Framework - for all kinds of socket animals, web-clients included - with gevent/asyncio/SSL support",
    "version": "3.12.5",
    "project_urls": {
        "github": "https://github.com/mindflayer/python-mocket"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3d37c2ed7fcd586d0c51c172d5502f6418960a3a19c8c929d88b9122b08731ce",
                "md5": "011e8d44126adf0a15bfb687617a05cd",
                "sha256": "eb25a8ed206556574af80c5406740e5e3401c73f476c80be0a1f7bef1899c5e9"
            },
            "downloads": -1,
            "filename": "mocket-3.12.5.tar.gz",
            "has_sig": false,
            "md5_digest": "011e8d44126adf0a15bfb687617a05cd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 72675,
            "upload_time": "2024-04-14T18:12:21",
            "upload_time_iso_8601": "2024-04-14T18:12:21.968070Z",
            "url": "https://files.pythonhosted.org/packages/3d/37/c2ed7fcd586d0c51c172d5502f6418960a3a19c8c929d88b9122b08731ce/mocket-3.12.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-14 18:12:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mindflayer",
    "github_project": "python-mocket",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "mocket"
}
        
Elapsed time: 0.27809s