a socket mock framework - for all kinds of socket animals, web-clients included

Overview

mocket /mɔˈkɛt/

https://coveralls.io/repos/github/mindflayer/python-mocket/badge.svg?branch=master https://img.shields.io/lgtm/grade/python/g/mindflayer/python-mocket.svg?logo=lgtm&logoWidth=18 Requirements Status

A socket mock framework

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

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

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.

Thanks to @felixonmars Mocket is available in the Arch Linux repository.

Buy Me A Coffee

How to use it

Read these three blog posts if you want to have a big picture of what Mocket is capable of:

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

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

Please also have a look at the huge test suite:

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:

$ virtualenv example
$ source example/bin/activate
$ pip install pytest requests mocket

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

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

Example of how to fake socket errors

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

@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:

@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:

import json

import aiohttp
import asyncio
import async_timeout
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) as session:
                with async_timeout.timeout(3):
                    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.get_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:

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) as session:
                with async_timeout.timeout(3):
                    async with session.get(url) as get_response:
                        assert get_response.status == 404
                        assert await get_response.text() == body

                with async_timeout.timeout(3):
                    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.get_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() as session:
            with async_timeout.timeout(3):
                async with session.get(url) as get_response:
                    assert get_response.status == 404
                    assert await get_response.text() == body

            with async_timeout.timeout(3):
                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]

Example:

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

Comments
  • Support for `fastapi`.`TestClient`

    Support for `fastapi`.`TestClient`

    Hi,

    I've discovered an issue using mocket and end-to-end testing. In the code below, Mocket breaks the TestClient, which is a FastAPI utility that is subclass of Request's Session, as it prevents it from sending the real requests to the app's host, causing the test to hang indefinitely. I only want to mock the requests made by the app, e.g. to "https://example.org/".

    Is it possible to exclude hosts from mocket's grasp? The TestClient internal sets the base_url to "http://testserver".

    import httpx
    import pytest
    from fastapi import FastAPI
    from fastapi.testclient import TestClient
    from mocket import mocketize
    from mocket.mockhttp import Entry
    
    app = FastAPI()
    
    
    @app.get("/")
    async def read_main() -> dict:
        async with httpx.AsyncClient() as client:
            r = await client.get("https://example.org/")
            return r.json()
    
    
    # End-to-end test
    
    @pytest.fixture
    def client() -> TestClient:
        return TestClient(app)
    
    
    @mocketize
    def test_read_main(client: TestClient) -> None:
        Entry.single_register(Entry.GET, "https://example.org/", body='{"id": 1}')
    
        response = client.get("/")
    
        assert response.status_code == 200
        assert response.json() == {"id": 1}
    
    
    enhancement 
    opened by gregbrowndev 36
  • Mocket fails when there are Redis calls using `hiredis`

    Mocket fails when there are Redis calls using `hiredis`

    Describe the bug I have a django based software that makes http requests using requests and uses django-redis to store some data of what it has fetched. I have noticed that if the first network call in a TestCase is for redis then mocket mocks redis, otherwise it mocks only requests.

    To Reproduce

    import requests
    from django.core.cache import cache
    from django.test.testcases import TestCase
    from mocket import Mocket, mocketize
    from mocket.mockhttp import Entry
    
    class TestMocketStrangeBehaviour(TestCase):
        def tearDown(self):
            cache.clear()
    
        @mocketize
        def test_b_random_url(self):
            url = "http://www.example.com"
            Entry.single_register(Entry.GET, url)
    
            requests.get(url)
    
            self.assertTrue(Mocket.has_requests())
    
        @mocketize
        def test_a_random_url(self):
            url = "http://www.example.com"
            Entry.single_register(Entry.GET, url)
    
            cache.set("key", "value")
    
            requests.get(url)
    
            self.assertTrue(Mocket.has_requests())
    

    will throw an exception

    Error
    Traceback (most recent call last):
      File "<decorator-gen-2>", line 2, in test_a_random_url
      File "/Users/anas/Projects/random_project/.venv/lib/python3.7/site-packages/mocket/mocket.py", line 627, in wrapper
        t(*args, **kw)
      File "/Users/anas/Projects/random_project/random_app/tests.py", line 34, in test_a_random_url
        cache.set("key", "value")
      File "/Users/anas/Projects/random_project/.venv/lib/python3.7/site-packages/django_redis/cache.py", line 27, in _decorator
        return method(self, *args, **kwargs)
      File "/Users/anas/Projects/random_project/.venv/lib/python3.7/site-packages/django_redis/cache.py", line 76, in set
        return self.client.set(*args, **kwargs)
      File "/Users/anas/Projects/random_project/.venv/lib/python3.7/site-packages/django_redis/client/default.py", line 156, in set
        return bool(client.set(nkey, nvalue, nx=nx, px=timeout, xx=xx))
      File "/Users/anas/Projects/random_project/.venv/lib/python3.7/site-packages/redis/client.py", line 1801, in set
        return self.execute_command('SET', *pieces)
      File "/Users/anas/Projects/random_project/.venv/lib/python3.7/site-packages/redis/client.py", line 898, in execute_command
        conn = self.connection or pool.get_connection(command_name, **options)
      File "/Users/anas/Projects/random_project/.venv/lib/python3.7/site-packages/redis/connection.py", line 1192, in get_connection
        connection.connect()
      File "/Users/anas/Projects/random_project/.venv/lib/python3.7/site-packages/redis/connection.py", line 567, in connect
        self.on_connect()
      File "/Users/anas/Projects/random_project/.venv/lib/python3.7/site-packages/redis/connection.py", line 664, in on_connect
        if nativestr(self.read_response()) != 'OK':
      File "/Users/anas/Projects/random_project/.venv/lib/python3.7/site-packages/redis/connection.py", line 739, in read_response
        response = self._parser.read_response()
      File "/Users/anas/Projects/random_project/.venv/lib/python3.7/site-packages/redis/connection.py", line 470, in read_response
        self.read_from_socket()
      File "/Users/anas/Projects/random_project/.venv/lib/python3.7/site-packages/redis/connection.py", line 427, in read_from_socket
        bufflen = recv_into(self._sock, self._buffer)
      File "/Users/anas/Projects/random_project/.venv/lib/python3.7/site-packages/redis/_compat.py", line 75, in recv_into
        return sock.recv_into(*args, **kwargs)
      File "/Users/anas/Projects/random_project/.venv/lib/python3.7/site-packages/mocket/mocket.py", line 264, in recv_into
        return buffer.write(self.read(buffersize))
    AttributeError: 'bytearray' object has no attribute 'write'
    

    If you swap names of the test functions it works as expected.

    Expected behavior Choose what to mock with some flag.

    Additional context It happens in macOS and ubuntu, with python3.7 and also 3.8

    enhancement wontfix 
    opened by WisdomPill 18
  • Minor fix for mocketoy example

    Minor fix for mocketoy example

    I think that the MocketSocketCore reference should be instantiated in makefile() rather then sendall(). Currently, makefile returns None, unless that is the intended behavior

    You can test this change with the mocketoy example: https://github.com/mindflayer/mocketoy/pull/1

    I don't know the ins-and-outs of mocket, so if this change makes sense, I can add tests and submit a more complete change. I just wanted to get input first

    opened by KyleKing 14
  • Add support for file's builtin magic module

    Add support for file's builtin magic module

    file's builtin magic module has a somewhat different API, and it's not co-installable with pypi:python-magic as both has the same name. Adding a fallback logic here makes mocket work with either one.

    All related tests are passing here.

    opened by felixonmars 11
  • MocketSocket support for context manager

    MocketSocket support for context manager

    Hi,

    MocketSocket doesn't seem to support context manager, so the construct:

    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
        s.connect((target.host, target.port, 0, 0))
        s.sendall(something)
        data = s.recv(4096)
    

    throws an AttributeError:

    Traceback (most recent call last):
      File "/home/scanner/scanner.py", line 32, in scan
        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    AttributeError: __enter__
    

    Is it by design? Any way to work around it (besides rewriting the original code that uses with socket.socket )?

    Thanks!

    opened by fvigo 10
  • build: don't have pinned reqs for distributed package

    build: don't have pinned reqs for distributed package

    A python package should not specify exact versions of it's dependencies but should instead state the minimal compatible requirements for it's dependencies.

    Otherwise we end up in unresolvable dependecy situations (like I find myself now with urllib3) where two packages require different specific versions. As of pip 20.3, which was released 2020-11-30, pip will refuse to install conflicting dependecies.

    You can read more about this here:

    • https://pipenv.pypa.io/en/latest/advanced/#pipfile-vs-setuppy
    • https://realpython.com/pipenv-guide/#package-distribution
    • https://blog.python.org/2020/11/pip-20-3-release-new-resolver.html
    opened by brycedrennan 10
  • Add missing truncate() call on BytesIO object

    Add missing truncate() call on BytesIO object

    When subsequent payload to be pushed by mocket was shorter than previous one, additional data were dumped. This was because BytesIO object had longer length; calling truncate() on the BytesIO object solves this problem

    code to reproduce the problem, before this patch:

    @mocketize
    def test_something():
        Mocket.register(
            MocketEntry(
                ('example.com', 80),
                [
                    b'this is some long payload'
                    b'short',
                ]
            ),
        )
    

    then, when one would use socket object, and call recv on it, one would get part of the first payload with the second call

    opened by toudi 10
  • Cannot inject HTTPX client as pytest fixture

    Cannot inject HTTPX client as pytest fixture

    Hi,

    Thanks for fixing the previous issue super quickly. However, I've noticed a json.decoder.JSONDecodeError problem when you inject HTTPX' AsyncClient as a pytest fixture. If you put the @mocketize decorator on the fixture it fixes the problem. However, this seems a bit odd.

    import asyncio
    import json
    
    import httpx
    import pytest
    from httpx import AsyncClient
    from mocket import mocketize
    from mocket.mockhttp import Entry
    
    
    @pytest.fixture
    def httpx_client() -> AsyncClient:
        # Note: should use 'async with'
        return httpx.AsyncClient()
    
    
    async def send_request(client: AsyncClient, url: str) -> dict:
        r = await client.get(url)
        return r.json()
    
    
    @mocketize
    def test_mocket(
        httpx_client: AsyncClient
    ):
        # works if you define httpx_client locally:
        # httpx_client = httpx.AsyncClient()
        url = "https://example.org/"
        data = {"message": "Hello"}
    
        Entry.single_register(
            Entry.GET,
            url,
            body=json.dumps(data),
            headers={'content-type': 'application/json'}
        )
    
        loop = asyncio.get_event_loop()
        
        coroutine = send_request(httpx_client, url)
        actual = loop.run_until_complete(coroutine)
        
        assert data == actual
    
    Stacktrack
    /Users/gregorybrown/.pyenv/versions/3.10.4/lib/python3.10/asyncio/base_events.py:646: in run_until_complete
        return future.result()
    test_mocket.py:22: in send_request
        return r.json()
    /Users/gregorybrown/Library/Caches/pypoetry/virtualenvs/tariff-management-6yv2RoDp-py3.10/lib/python3.10/site-packages/httpx/_models.py:743: in json
        return jsonlib.loads(self.text, **kwargs)
    /Users/gregorybrown/.pyenv/versions/3.10.4/lib/python3.10/json/__init__.py:346: in loads
        return _default_decoder.decode(s)
    /Users/gregorybrown/.pyenv/versions/3.10.4/lib/python3.10/json/decoder.py:337: in decode
        obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    
    self = <json.decoder.JSONDecoder object at 0x10c48b8e0>
    s = '<!doctype html>\n<html>\n<head>\n    <title>Example Domain</title>\n\n    <meta charset="utf-8" />\n    <meta http-eq...on.</p>\n    <p><a href="https://www.iana.org/domains/example">More information...</a></p>\n</div>\n</body>\n</html>\n'
    idx = 0
    
        def raw_decode(self, s, idx=0):
            """Decode a JSON document from ``s`` (a ``str`` beginning with
            a JSON document) and return a 2-tuple of the Python
            representation and the index in ``s`` where the document ended.
        
            This can be used to decode a JSON document from a string that may
            have extraneous data at the end.
        
            """
            try:
                obj, end = self.scan_once(s, idx)
            except StopIteration as err:
    >           raise JSONDecodeError("Expecting value", s, err.value) from None
    E           json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
    
    /Users/gregorybrown/.pyenv/versions/3.10.4/lib/python3.10/json/decoder.py:355: JSONDecodeError
    

    Also, I know there's a lot of weird/questionable stuff going on in this test but I'm just trying to verify the behaviour around using async HTTPX within a sync app.

    Thanks

    question 
    opened by gregbrowndev 9
  • Multiple HTTP writes fail

    Multiple HTTP writes fail

    Dear Giorgio,

    Introduction

    Our background is that we are currently building a test suite based on CPython/Pytest for invoking MicroPython programs, see also https://github.com/micropython/micropython/pull/5786 and https://github.com/micropython/micropython/issues/4955. It works pretty good so far. Thanks again for Mocket, it helped us tremendously already.

    Problem

    So, after successfully creating a Pytest LoRa socket mock fixture, we are now struggling creating a corresponding thing for the urequests module.

    The gist is that urequests will work like that:

    sock.connect(address[-1])
    sock.write("%s %s HTTP/1.0\r\n" % (method, path))
    sock.write("Host: %s\r\n" % host)
    

    which makes Mocket only see the first line:

    b'POST /api/data HTTP/1.0\r\n'
    

    so that it will croak with the following exception.

    Exception

    >       _, self.body = decode_from_bytes(data).split('\r\n\r\n', 1)
    E       ValueError: not enough values to unpack (expected 2, got 1)
    .venv3/lib/python3.8/site-packages/mocket/mockhttp.py:23: ValueError
    

    Reproduction

    I have been able to create a repro using pytest. https://gist.github.com/amotl/015ef6b336db55128798d7f1a9a67dea

    Thoughts

    I believe @sjaensch observed this within #66 already and apparently #67 didn't fix it yet.

    Thanks already for looking into this!

    With kind regards, Andreas.

    enhancement 
    opened by amotl 9
  • md5 hashing is slow

    md5 hashing is slow

    In https://github.com/mindflayer/python-mocket/blob/master/mocket/mocket.py#L265 we hash the response so we'll have a key. Using md5 to do so is slower than what can be done. There are more modern hashing algorithms such as xxhash. Would you accept a PR that replaces MD5 with a non-cryptographic hash function?

    enhancement 
    opened by thedrow 8
  • How about mocking sockets with trio ?

    How about mocking sockets with trio ?

    Using mocket with trio, I get :

    TypeError: descriptor 'send' requires a '_socket.socket' object but received a 'MocketSocket'
    

    Is there any known way for this to work ?

    enhancement not sure 
    opened by asmodehn 8
Releases(3.10.9)
  • 3.10.9(Dec 3, 2022)

    What's Changed

    • Small improvement for socketpair by @mindflayer in https://github.com/mindflayer/python-mocket/pull/189
    • Fix for an unconvential usage of Mocket by @mindflayer in https://github.com/mindflayer/python-mocket/pull/192
    • Improve efficiency on CI by @amotl in https://github.com/mindflayer/python-mocket/pull/194

    New Contributors

    • @amotl made their first contribution in https://github.com/mindflayer/python-mocket/pull/194

    Full Changelog: https://github.com/mindflayer/python-mocket/compare/3.10.8...3.10.9

    Source code(tar.gz)
    Source code(zip)
  • 3.10.8(Aug 23, 2022)

    What's Changed

    • Improving tests for httpx by @mindflayer in https://github.com/mindflayer/python-mocket/pull/186
    • Support for calls made by fastapi by @mindflayer in https://github.com/mindflayer/python-mocket/pull/188

    Full Changelog: https://github.com/mindflayer/python-mocket/compare/3.10.7...3.10.8

    Source code(tar.gz)
    Source code(zip)
  • 3.10.7(Aug 16, 2022)

    What's Changed

    • Change methods not using its bound instance to staticmethods by @deepsource-autofix in https://github.com/mindflayer/python-mocket/pull/180
    • Adding support for httpx by @mindflayer in https://github.com/mindflayer/python-mocket/pull/183

    Thanks to @gregbrowndev for openinig #182.

    Full Changelog: https://github.com/mindflayer/python-mocket/compare/3.10.6...3.10.7

    Source code(tar.gz)
    Source code(zip)
  • 3.10.6(May 17, 2022)

    What's Changed

    • No need for the external mock dependency by @mindflayer in https://github.com/mindflayer/python-mocket/pull/179

    Full Changelog: https://github.com/mindflayer/python-mocket/compare/3.10.5...3.10.6

    Source code(tar.gz)
    Source code(zip)
  • 3.10.5(Apr 25, 2022)

    What's Changed

    • Small refactor by @mindflayer in https://github.com/mindflayer/python-mocket/pull/172
    • Remove assert statement from non-test files by @deepsource-autofix in https://github.com/mindflayer/python-mocket/pull/173
    • Remove blank lines after docstring by @deepsource-autofix in https://github.com/mindflayer/python-mocket/pull/174
    • MocketEntry.request_class str vs bytes (fix for #175 ) by @michael-lazar in https://github.com/mindflayer/python-mocket/pull/177

    Full Changelog: https://github.com/mindflayer/python-mocket/compare/3.10.4...3.10.5

    Source code(tar.gz)
    Source code(zip)
  • 3.10.4(Jan 9, 2022)

    Pass strict_mode=True when calling @mocketizer() or with Mocketizer() to make your test case fail in case it tries to use the real socket module.

    Source code(tar.gz)
    Source code(zip)
  • 3.10.3(Jan 8, 2022)

  • 3.10.1(Nov 25, 2021)

    Entry.collect() is now able to tell us (but it does not have to) to skip consuming a response and leave the current socket untouched.

    Thanks @ykharko for opening issue #158.

    Source code(tar.gz)
    Source code(zip)
  • 3.9.44(Aug 31, 2021)

  • 3.9.42(Jun 10, 2021)

  • 3.9.41(May 21, 2021)

  • 3.9.40(Jan 21, 2021)

  • 3.9.39(Jan 15, 2021)

    • Adding support for using a socket as a context manager as requested by #139.
    • Closing real socket.
    • Bump version.

    Thanks to @fvigo for the contribution.

    Source code(tar.gz)
    Source code(zip)
  • 3.9.4(Dec 2, 2020)

  • 3.9.3(Nov 9, 2020)

  • 3.9.2(Oct 11, 2020)

    https://github.com/mindflayer/python-mocket#example-of-how-to-fake-a-socket-errors

    @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)
    
    Source code(tar.gz)
    Source code(zip)
  • 3.9.1(Oct 9, 2020)

  • 3.9.0(Sep 20, 2020)

  • 3.8.9(Sep 11, 2020)

  • 3.8.8(Aug 19, 2020)

  • 3.8.7(Jul 27, 2020)

    This version ships the change to support the libmagic wrapper distributed with file's command.

    With this change, thanks to @felixonmars contribution, Mocket is now available as Arch Linux package: https://www.archlinux.org/packages/community/any/python-mocket/

    Source code(tar.gz)
    Source code(zip)
  • 3.8.6(Jun 18, 2020)

    Support for tests based on unittest.IsolatedAsyncioTestCase (Python 3.8). See: https://github.com/mindflayer/python-mocket/blob/master/tests/tests38/test_http_aiohttp.py

    Thanks to @WisdomPill for the amazing contribution.

    Source code(tar.gz)
    Source code(zip)
Owner
Giorgio Salluzzo
Python developer and FLOSS user, RPG player, Android bricker, beer drinker, food producer and consumer.
Giorgio Salluzzo
gunicorn 'Green Unicorn' is a WSGI HTTP Server for UNIX, fast clients and sleepy applications.

Gunicorn Gunicorn 'Green Unicorn' is a Python WSGI HTTP Server for UNIX. It's a pre-fork worker model ported from Ruby's Unicorn project. The Gunicorn

Benoit Chesneau 8.7k Jan 1, 2023
splinter - python test framework for web applications

splinter - python tool for testing web applications splinter is an open source tool for testing web applications using Python. It lets you automate br

Cobra Team 2.6k Dec 27, 2022
A modern API testing tool for web applications built with Open API and GraphQL specifications.

Schemathesis Schemathesis is a modern API testing tool for web applications built with Open API and GraphQL specifications. It reads the application s

Schemathesis.io 1.6k Jan 4, 2023
Radically simplified static file serving for Python web apps

WhiteNoise Radically simplified static file serving for Python web apps With a couple of lines of config WhiteNoise allows your web app to serve its o

Dave Evans 2.1k Jan 8, 2023
Meinheld is a high performance asynchronous WSGI Web Server (based on picoev)

What's this This is a high performance python wsgi web server. And Meinheld is a WSGI compliant web server. (PEP333 and PEP3333 supported) You can als

Yutaka Matsubara 1.4k Jan 1, 2023
Generic automation framework for acceptance testing and RPA

Robot Framework Introduction Installation Example Usage Documentation Support and contact Contributing License Introduction Robot Framework is a gener

Robot Framework 7.7k Dec 31, 2022
Sixpack is a language-agnostic a/b-testing framework

Sixpack Sixpack is a framework to enable A/B testing across multiple programming languages. It does this by exposing a simple API for client libraries

null 1.7k Dec 24, 2022
a socket mock framework - for all kinds of socket animals, web-clients included

mocket /mɔˈkɛt/ A socket mock framework for all kinds of socket animals, web-clients included - with gevent/asyncio/SSL support ...and then MicroPytho

Giorgio Salluzzo 249 Dec 14, 2022
a socket mock framework - for all kinds of socket animals, web-clients included

mocket /mɔˈkɛt/ A socket mock framework for all kinds of socket animals, web-clients included - with gevent/asyncio/SSL support ...and then MicroPytho

Giorgio Salluzzo 208 Jan 31, 2021
A web porting for NVlabs' StyleGAN2, to facilitate exploring all kinds characteristic of StyleGAN networks

This project is a web porting for NVlabs' StyleGAN2, to facilitate exploring all kinds characteristic of StyleGAN networks. Thanks for NVlabs' excelle

K.L. 150 Dec 15, 2022
The ultimate Python library in building OAuth, OpenID Connect clients and servers. JWS,JWE,JWK,JWA,JWT included.

Authlib The ultimate Python library in building OAuth and OpenID Connect servers. JWS, JWK, JWA, JWT are included. Authlib is compatible with Python2.

Hsiaoming Yang 3.4k Jan 4, 2023
The ultimate Python library in building OAuth, OpenID Connect clients and servers. JWS,JWE,JWK,JWA,JWT included.

Authlib The ultimate Python library in building OAuth and OpenID Connect servers. JWS, JWK, JWA, JWT are included. Authlib is compatible with Python2.

Hsiaoming Yang 2.3k Feb 17, 2021
ml4h is a toolkit for machine learning on clinical data of all kinds including genetics, labs, imaging, clinical notes, and more

ml4h is a toolkit for machine learning on clinical data of all kinds including genetics, labs, imaging, clinical notes, and more

Broad Institute 65 Dec 20, 2022
Python package for multiple object tracking research with focus on laboratory animals tracking.

motutils is a Python package for multiple object tracking research with focus on laboratory animals tracking. Features loads: MOTChallenge CSV, sleap

Matěj Šmíd 2 Sep 5, 2022
Aioresponses is a helper for mock/fake web requests in python aiohttp package.

aioresponses Aioresponses is a helper to mock/fake web requests in python aiohttp package. For requests module there are a lot of packages that help u

null 402 Jan 6, 2023
Hack computer in the form of RAR files from all types of clients, even Linux

Program Features ?? Hide malware ?? Vulnerability software vulnerabilities RAR ?? Creating malware ?? Access client files ?? Client Hacking ?? Link Do

hack4lx 5 Nov 25, 2022
shiv is a command line utility for building fully self contained Python zipapps as outlined in PEP 441, but with all their dependencies included.

shiv shiv is a command line utility for building fully self-contained Python zipapps as outlined in PEP 441, but with all their dependencies included!

LinkedIn 1.5k Dec 28, 2022
The RAP community of practice includes all analysts and data scientists who are interested in adopting the working practices included in reproducible analytical pipelines (RAP) at NHS Digital.

The RAP community of practice includes all analysts and data scientists who are interested in adopting the working practices included in reproducible analytical pipelines (RAP) at NHS Digital.

NHS Digital 50 Dec 22, 2022