Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package python-mocket for openSUSE:Factory checked in at 2022-01-20 00:11:56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-mocket (Old) and /work/SRC/openSUSE:Factory/.python-mocket.new.1892 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-mocket" Thu Jan 20 00:11:56 2022 rev:19 rq:946839 version:3.10.4 Changes: -------- --- /work/SRC/openSUSE:Factory/python-mocket/python-mocket.changes 2021-12-20 21:06:44.718954088 +0100 +++ /work/SRC/openSUSE:Factory/.python-mocket.new.1892/python-mocket.changes 2022-01-20 00:12:13.306573699 +0100 @@ -1,0 +2,29 @@ +Sun Jan 9 19:21:59 UTC 2022 - Sebastian Wagner <sebix+novell....@sebix.at> + +- - Add Mocket "strict mode" (#171) + * Add Mocket "strict mode". + - Update main.yml + - Introducing `request_list()` method (#170) + * Introducing `request_list()` method. + - Refactoring. (#169) + - Some cleaning/refactoring (#168) + * Some cleaning/refactoring. + * Improving coverage. + - Update README.rst + - Use literal syntax instead of function calls to create data structure (#167) + Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com> + +------------------------------------------------------------------- +Sat Jan 8 21:39:28 UTC 2022 - Sebastian Wagner <sebix+novell....@sebix.at> + +- - Introducing `request_list()` method (#170) + * Introducing `request_list()` method. + - Refactoring. (#169) + - Some cleaning/refactoring (#168) + * Some cleaning/refactoring. + * Improving coverage. + - Update README.rst + - Use literal syntax instead of function calls to create data structure (#167) + Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com> + +------------------------------------------------------------------- Old: ---- mocket-3.10.2.tar.gz New: ---- mocket-3.10.4.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-mocket.spec ++++++ --- /var/tmp/diff_new_pack.ZLX6l2/_old 2022-01-20 00:12:18.450577853 +0100 +++ /var/tmp/diff_new_pack.ZLX6l2/_new 2022-01-20 00:12:18.454577855 +0100 @@ -1,7 +1,7 @@ # # spec file # -# Copyright (c) 2021 SUSE LLC +# Copyright (c) 2022 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -26,7 +26,7 @@ %bcond_with test %endif Name: python-mocket%{psuffix} -Version: 3.10.2 +Version: 3.10.4 Release: 0 Summary: Python socket mock framework License: BSD-3-Clause ++++++ mocket-3.10.2.tar.gz -> mocket-3.10.4.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mocket-3.10.2/PKG-INFO new/mocket-3.10.4/PKG-INFO --- old/mocket-3.10.2/PKG-INFO 2021-12-01 19:58:33.368794700 +0100 +++ new/mocket-3.10.4/PKG-INFO 2022-01-09 17:57:03.872046000 +0100 @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: mocket -Version: 3.10.2 +Version: 3.10.4 Summary: Socket Mock Framework - for all kinds of socket animals, web-clients included - with gevent/asyncio/SSL support Home-page: https://github.com/mindflayer/python-mocket Author: Giorgio Salluzzo @@ -169,6 +169,31 @@ $ 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/") + +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 ==================================== diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mocket-3.10.2/README.rst new/mocket-3.10.4/README.rst --- old/mocket-3.10.2/README.rst 2021-11-23 19:02:53.000000000 +0100 +++ new/mocket-3.10.4/README.rst 2022-01-09 17:53:30.000000000 +0100 @@ -141,6 +141,31 @@ $ 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/") + +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 ==================================== diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mocket-3.10.2/mocket/__init__.py new/mocket-3.10.4/mocket/__init__.py --- old/mocket-3.10.2/mocket/__init__.py 2021-12-01 19:57:28.000000000 +0100 +++ new/mocket-3.10.4/mocket/__init__.py 2022-01-09 17:53:30.000000000 +0100 @@ -1,5 +1,6 @@ -from mocket.mocket import Mocket, MocketEntry, Mocketizer, mocketize +from .async_mocket import async_mocketize +from .mocket import Mocket, MocketEntry, Mocketizer, mocketize -__all__ = ("mocketize", "Mocket", "MocketEntry", "Mocketizer") +__all__ = ("async_mocketize", "mocketize", "Mocket", "MocketEntry", "Mocketizer") -__version__ = "3.10.2" +__version__ = "3.10.4" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mocket-3.10.2/mocket/async_mocket.py new/mocket-3.10.4/mocket/async_mocket.py --- old/mocket-3.10.2/mocket/async_mocket.py 2021-09-23 11:01:03.000000000 +0200 +++ new/mocket-3.10.4/mocket/async_mocket.py 2022-01-09 17:53:30.000000000 +0100 @@ -1,23 +1,11 @@ -from mocket import Mocketizer -from mocket.utils import get_mocketize +from .mocket import Mocketizer +from .utils import get_mocketize -async def wrapper(test, cls=Mocketizer, truesocket_recording_dir=None, *args, **kwargs): - instance = args[0] if args else None - namespace = None - if truesocket_recording_dir: - namespace = ".".join( - ( - instance.__class__.__module__, - instance.__class__.__name__, - test.__name__, - ) - ) - async with cls( - instance, - namespace=namespace, - truesocket_recording_dir=truesocket_recording_dir, - ): +async def wrapper( + test, truesocket_recording_dir=None, strict_mode=False, *args, **kwargs +): + async with Mocketizer.factory(test, truesocket_recording_dir, strict_mode, args): return await test(*args, **kwargs) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mocket-3.10.2/mocket/compat.py new/mocket-3.10.4/mocket/compat.py --- old/mocket-3.10.2/mocket/compat.py 2021-12-01 19:25:53.000000000 +0100 +++ new/mocket-3.10.4/mocket/compat.py 2022-01-08 13:36:13.000000000 +0100 @@ -26,7 +26,7 @@ return shlex.split(s) -def do_the_magic(lib_magic, body): +def do_the_magic(lib_magic, body): # pragma: no cover if hasattr(lib_magic, "from_buffer"): # PyPI python-magic return lib_magic.from_buffer(body, mime=True) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mocket-3.10.2/mocket/exceptions.py new/mocket-3.10.4/mocket/exceptions.py --- old/mocket-3.10.2/mocket/exceptions.py 1970-01-01 01:00:00.000000000 +0100 +++ new/mocket-3.10.4/mocket/exceptions.py 2022-01-09 17:53:30.000000000 +0100 @@ -0,0 +1,6 @@ +class MocketException(Exception): + pass + + +class StrictMocketException(MocketException): + pass diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mocket-3.10.2/mocket/mocket.py new/mocket-3.10.4/mocket/mocket.py --- old/mocket-3.10.2/mocket/mocket.py 2021-12-01 19:25:53.000000000 +0100 +++ new/mocket-3.10.4/mocket/mocket.py 2022-01-09 17:53:30.000000000 +0100 @@ -18,7 +18,15 @@ from urllib3.util.ssl_ import wrap_socket as urllib3_wrap_socket from .compat import basestring, byte_type, decode_from_bytes, encode_to_bytes, text_type -from .utils import SSL_PROTOCOL, MocketSocketCore, get_mocketize, hexdump, hexload +from .exceptions import StrictMocketException +from .utils import ( + SSL_PROTOCOL, + MocketMode, + MocketSocketCore, + get_mocketize, + hexdump, + hexload, +) xxh32 = None try: @@ -158,10 +166,7 @@ self._truesocket_recording_dir = None self.kwargs = kwargs - def __unicode__(self): # pragma: no cover - return str(self) - - def __str__(self): # pragma: no cover + def __str__(self): return "({})(family={} type={} protocol={})".format( self.__class__.__name__, self.family, self.type, self.proto ) @@ -289,6 +294,9 @@ raise exc def true_sendall(self, data, *args, **kwargs): + if MocketMode().STRICT: + raise StrictMocketException("Mocket tried to use the real `socket` module.") + req = decode_from_bytes(data) # make request unique again req_signature = _hash_request(hasher, req) @@ -296,7 +304,7 @@ port = text_type(self._port) # prepare responses dictionary - responses = dict() + responses = {} if Mocket.get_truesocket_recording_dir(): path = os.path.join( @@ -322,9 +330,9 @@ raise except KeyError: # preventing next KeyError exceptions - responses.setdefault(self._host, dict()) - responses[self._host].setdefault(port, dict()) - responses[self._host][port].setdefault(req_signature, dict()) + responses.setdefault(self._host, {}) + responses[self._host].setdefault(port, {}) + responses[self._host][port].setdefault(req_signature, {}) response_dict = responses[self._host][port][req_signature] # try to get the response from the dictionary @@ -425,7 +433,7 @@ @classmethod def collect(cls, data): - cls._requests.append(data) + cls.request_list().append(data) @classmethod def reset(cls): @@ -436,17 +444,21 @@ @classmethod def last_request(cls): - if cls._requests: - return cls._requests[-1] + if cls.has_requests(): + return cls.request_list()[-1] + + @classmethod + def request_list(cls): + return cls._requests @classmethod def remove_last_request(cls): - if cls._requests: + if cls.has_requests(): del cls._requests[-1] @classmethod def has_requests(cls): - return len(cls._requests) > 0 + return bool(cls.request_list()) @staticmethod def enable(namespace=None, truesocket_recording_dir=None): @@ -596,10 +608,17 @@ class Mocketizer: - def __init__(self, instance=None, namespace=None, truesocket_recording_dir=None): + def __init__( + self, + instance=None, + namespace=None, + truesocket_recording_dir=None, + strict_mode=False, + ): self.instance = instance self.truesocket_recording_dir = truesocket_recording_dir self.namespace = namespace or text_type(id(self)) + MocketMode().STRICT = strict_mode def enter(self): Mocket.enable( @@ -628,28 +647,34 @@ async def __aexit__(self, *args, **kwargs): self.exit() - def check_and_call(self, method): - method = getattr(self.instance, method, None) + def check_and_call(self, method_name): + method = getattr(self.instance, method_name, None) if callable(method): method() - -def wrapper(test, cls=Mocketizer, truesocket_recording_dir=None, *args, **kwargs): - instance = args[0] if args else None - namespace = None - if truesocket_recording_dir: - namespace = ".".join( - ( - instance.__class__.__module__, - instance.__class__.__name__, - test.__name__, + @staticmethod + def factory(test, truesocket_recording_dir, strict_mode, args): + instance = args[0] if args else None + namespace = None + if truesocket_recording_dir: + namespace = ".".join( + ( + instance.__class__.__module__, + instance.__class__.__name__, + test.__name__, + ) ) + + return Mocketizer( + instance, + namespace=namespace, + truesocket_recording_dir=truesocket_recording_dir, + strict_mode=strict_mode, ) - with cls( - instance, - namespace=namespace, - truesocket_recording_dir=truesocket_recording_dir, - ): + + +def wrapper(test, truesocket_recording_dir=None, strict_mode=False, *args, **kwargs): + with Mocketizer.factory(test, truesocket_recording_dir, strict_mode, args): return test(*args, **kwargs) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mocket-3.10.2/mocket/plugins/httpretty/__init__.py new/mocket-3.10.4/mocket/plugins/httpretty/__init__.py --- old/mocket-3.10.2/mocket/plugins/httpretty/__init__.py 2021-12-01 19:25:53.000000000 +0100 +++ new/mocket-3.10.4/mocket/plugins/httpretty/__init__.py 2022-01-08 17:50:17.000000000 +0100 @@ -102,15 +102,11 @@ Response = Response - def __init__(self): - pass - def __getattr__(self, name): if name == "last_request": - last_request = getattr(Mocket, "last_request")() - return last_request + return Mocket.last_request() if name == "latest_requests": - return getattr(Mocket, "_requests") + return Mocket.request_list() return getattr(Entry, name) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mocket-3.10.2/mocket/utils.py new/mocket-3.10.4/mocket/utils.py --- old/mocket-3.10.2/mocket/utils.py 2021-12-01 19:25:53.000000000 +0100 +++ new/mocket-3.10.4/mocket/utils.py 2022-01-09 17:53:30.000000000 +0100 @@ -39,6 +39,14 @@ def get_mocketize(wrapper_): import decorator - if decorator.__version__ < "5": + if decorator.__version__ < "5": # pragma: no cover return decorator.decorator(wrapper_) return decorator.decorator(wrapper_, kwsyntax=True) + + +class MocketMode: + __shared_state = {} + STRICT = None + + def __init__(self): + self.__dict__ = self.__shared_state diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mocket-3.10.2/mocket.egg-info/PKG-INFO new/mocket-3.10.4/mocket.egg-info/PKG-INFO --- old/mocket-3.10.2/mocket.egg-info/PKG-INFO 2021-12-01 19:58:33.000000000 +0100 +++ new/mocket-3.10.4/mocket.egg-info/PKG-INFO 2022-01-09 17:57:03.000000000 +0100 @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: mocket -Version: 3.10.2 +Version: 3.10.4 Summary: Socket Mock Framework - for all kinds of socket animals, web-clients included - with gevent/asyncio/SSL support Home-page: https://github.com/mindflayer/python-mocket Author: Giorgio Salluzzo @@ -169,6 +169,31 @@ $ 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/") + +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 ==================================== diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mocket-3.10.2/mocket.egg-info/SOURCES.txt new/mocket-3.10.4/mocket.egg-info/SOURCES.txt --- old/mocket-3.10.2/mocket.egg-info/SOURCES.txt 2021-12-01 19:58:33.000000000 +0100 +++ new/mocket-3.10.4/mocket.egg-info/SOURCES.txt 2022-01-09 17:57:03.000000000 +0100 @@ -6,6 +6,7 @@ mocket/__init__.py mocket/async_mocket.py mocket/compat.py +mocket/exceptions.py mocket/mocket.py mocket/mockhttp.py mocket/mockredis.py @@ -23,19 +24,18 @@ tests/fluidicon.png tests/main/__init__.py tests/main/test_http.py +tests/main/test_http_aiohttp.py tests/main/test_http_gevent.py tests/main/test_http_with_xxhash.py tests/main/test_httpretty.py tests/main/test_https.py tests/main/test_mocket.py +tests/main/test_mode.py tests/main/test_pook.py tests/main/test_redis.py tests/main/tests.main.test_http.HttpEntryTestCase.test_truesendall_with_dump_from_recording.json tests/main/tests.main.test_http_gevent.GeventHttpEntryTestCase.test_truesendall_with_dump_from_recording.json tests/main/tests.main.test_http_with_xxhash.HttpEntryTestCase.test_truesendall_with_dump_from_recording.json -tests/tests35/README.txt -tests/tests35/__init__.py -tests/tests35/test_http_aiohttp.py tests/tests37/test_asyncio.py tests/tests38/README.txt tests/tests38/__init__.py diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mocket-3.10.2/setup.py new/mocket-3.10.4/setup.py --- old/mocket-3.10.2/setup.py 2021-09-23 11:01:03.000000000 +0200 +++ new/mocket-3.10.4/setup.py 2022-01-08 13:36:13.000000000 +0100 @@ -1,13 +1,10 @@ import io import os -import sys from setuptools import find_packages, setup os.environ.setdefault("PIPENV_SKIP_LOCK", "1") -major, minor = sys.version_info[:2] - install_requires = [ line for line in io.open( diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mocket-3.10.2/tests/__init__.py new/mocket-3.10.4/tests/__init__.py --- old/mocket-3.10.2/tests/__init__.py 2021-03-20 19:51:56.000000000 +0100 +++ new/mocket-3.10.4/tests/__init__.py 2022-01-08 13:36:13.000000000 +0100 @@ -1,12 +0,0 @@ -from __future__ import unicode_literals -import sys - -PY2 = sys.version_info[0] == 2 - -if PY2: - from urllib2 import urlopen, HTTPError - from urllib import urlencode -else: - from urllib.request import urlopen - from urllib.parse import urlencode - from urllib.error import HTTPError diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mocket-3.10.2/tests/main/test_http.py new/mocket-3.10.4/tests/main/test_http.py --- old/mocket-3.10.2/tests/main/test_http.py 2021-12-01 19:57:28.000000000 +0100 +++ new/mocket-3.10.4/tests/main/test_http.py 2022-01-08 17:50:17.000000000 +0100 @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals - import io import json import os @@ -8,6 +6,9 @@ import tempfile import time from unittest import TestCase +from urllib.error import HTTPError +from urllib.parse import urlencode +from urllib.request import urlopen import mock import pytest @@ -15,7 +16,6 @@ from mocket import Mocket, mocketize from mocket.mockhttp import Entry, Response -from tests import HTTPError, urlencode, urlopen recording_directory = tempfile.mkdtemp() @@ -149,7 +149,7 @@ "Content-type": "text/plain; charset=utf-8", }, ) - self.assertEqual(len(Mocket._requests), 1) + self.assertEqual(len(Mocket.request_list()), 1) @mocketize def test_sendall_json(self): @@ -176,7 +176,7 @@ "content-type": "application/json", }, ) - self.assertEqual(len(Mocket._requests), 1) + self.assertEqual(len(Mocket.request_list()), 1) @mocketize def test_sendall_double(self): @@ -188,7 +188,7 @@ self.assertEqual(response.code, 200) response = urlopen("http://testme.org/") self.assertEqual(response.code, 200) - self.assertEqual(len(Mocket._requests), 3) + self.assertEqual(len(Mocket.request_list()), 3) @mocketize def test_mockhttp_entry_collect_duplicates(self): @@ -201,7 +201,7 @@ headers={"content-type": "application/json"}, ) requests.post("http://testme.org/") - self.assertEqual(len(Mocket._requests), 2) + self.assertEqual(len(Mocket.request_list()), 2) self.assertEqual(Mocket.last_request().path, "/") @mocketize @@ -235,7 +235,7 @@ "connection": "keep-alive", }, ) - self.assertEqual(len(Mocket._requests), 1) + self.assertEqual(len(Mocket.request_list()), 1) @mocketize def test_file_object(self): diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mocket-3.10.2/tests/main/test_http_aiohttp.py new/mocket-3.10.4/tests/main/test_http_aiohttp.py --- old/mocket-3.10.2/tests/main/test_http_aiohttp.py 1970-01-01 01:00:00.000000000 +0100 +++ new/mocket-3.10.4/tests/main/test_http_aiohttp.py 2022-01-08 17:50:17.000000000 +0100 @@ -0,0 +1,82 @@ +import asyncio +import json +from unittest import TestCase + +import aiohttp +import async_timeout + +from mocket.mocket import Mocket, mocketize +from mocket.mockhttp import Entry +from mocket.plugins.httpretty import HTTPretty, httprettified + + +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(_loop): + async with aiohttp.ClientSession(loop=_loop) 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 + + loop = asyncio.get_event_loop() + loop.set_debug(True) + loop.run_until_complete(main(loop)) + self.assertEqual(len(Mocket.request_list()), 2) + + @mocketize + def test_https_session(self): + url = "https://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(_loop): + async with aiohttp.ClientSession(loop=_loop) 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.set_debug(True) + loop.run_until_complete(main(loop)) + self.assertEqual(len(Mocket.request_list()), 2) + + @httprettified + def test_httprettish_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(_loop): + async with aiohttp.ClientSession(loop=_loop) 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)) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mocket-3.10.2/tests/main/test_https.py new/mocket-3.10.4/tests/main/test_https.py --- old/mocket-3.10.2/tests/main/test_https.py 2021-06-09 19:11:33.000000000 +0200 +++ new/mocket-3.10.4/tests/main/test_https.py 2022-01-08 13:36:13.000000000 +0100 @@ -2,13 +2,13 @@ import json import os import tempfile +from urllib.request import urlopen import pytest import requests from mocket import Mocket, Mocketizer, mocketize from mocket.mockhttp import Entry -from tests import urlopen @pytest.fixture @@ -51,7 +51,8 @@ assert resp.status_code == 200 dump_filename = os.path.join( - Mocket.get_truesocket_recording_dir(), Mocket.get_namespace() + ".json", + Mocket.get_truesocket_recording_dir(), + Mocket.get_namespace() + ".json", ) with io.open(dump_filename) as f: responses = json.load(f) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mocket-3.10.2/tests/main/test_mocket.py new/mocket-3.10.4/tests/main/test_mocket.py --- old/mocket-3.10.2/tests/main/test_mocket.py 2021-08-31 12:37:51.000000000 +0200 +++ new/mocket-3.10.4/tests/main/test_mocket.py 2022-01-08 17:50:17.000000000 +0100 @@ -1,7 +1,7 @@ from __future__ import unicode_literals -import os import io +import os import socket from unittest import TestCase from unittest.mock import patch @@ -18,17 +18,17 @@ def test_lastrequest(self): self.assertEqual(Mocket.last_request(), None) - Mocket._requests.extend([1, 2, 3]) + Mocket.request_list().extend([1, 2, 3]) self.assertEqual(Mocket.last_request(), 3) def test_reset(self): - Mocket._requests.extend([1, 2, 3]) - self.assertEqual(Mocket._requests, [1, 2, 3]) + Mocket.request_list().extend([1, 2, 3]) + self.assertEqual(Mocket.request_list(), [1, 2, 3]) Mocket.reset() - self.assertEqual(Mocket._requests, []) + self.assertEqual(Mocket.request_list(), []) def test_has_requests(self): - Mocket._requests.extend([1, 2, 3]) + Mocket.request_list().extend([1, 2, 3]) self.assertTrue(Mocket.has_requests()) Mocket.reset() self.assertFalse(Mocket.has_requests()) @@ -54,23 +54,26 @@ Mocket.register(entry_1, entry_2, entry_3) self.assertEqual( Mocket._entries, - {("localhost", 80): [entry_1, entry_2], ("localhost", 8080): [entry_3],}, + { + ("localhost", 80): [entry_1, entry_2], + ("localhost", 8080): [entry_3], + }, ) def test_collect(self): request = "GET /get/p/?b=2&a=1 HTTP/1.1\r\nAccept-Encoding: identity\r\nHost: testme.org\r\nConnection: close\r\nUser-Agent: Python-urllib/2.6\r\n\r\n" Mocket.collect(request) self.assertEqual(Mocket.last_request(), request) - self.assertEqual(Mocket._requests, [request]) + self.assertEqual(Mocket.request_list(), [request]) def test_remove_last(self): Mocket._requests = [1, 2] Mocket.remove_last_request() - self.assertEqual(Mocket._requests, [1]) + self.assertEqual(Mocket.request_list(), [1]) def test_remove_last_empty(self): Mocket.remove_last_request() - self.assertEqual(Mocket._requests, []) + self.assertEqual(Mocket.request_list(), []) def test_getentry(self): entry = MocketEntry(("localhost", 80), True) @@ -127,7 +130,7 @@ fp = _so.makefile("rb") _so.sendall(encode_to_bytes("...\r\n")) self.assertEqual(fp.read().strip(), encode_to_bytes("Show me.")) - self.assertEqual(len(Mocket._requests), 1) + self.assertEqual(len(Mocket.request_list()), 1) def test_socket_as_context_manager(self): addr = ("localhost", 80) @@ -138,6 +141,7 @@ _so.sendall(encode_to_bytes("Whatever...")) data = _so.recv(4096) self.assertEqual(data, encode_to_bytes("Show me.\r\n")) + self.assertEqual(str(_so), "(MocketSocket)(family=2 type=1 protocol=0)") class MocketizeTestCase(TestCase): @@ -172,5 +176,5 @@ def test_patch( method_patch, ): - method_patch.return_value = 'foo' + method_patch.return_value = "foo" assert os.getcwd() == "foo" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mocket-3.10.2/tests/main/test_mode.py new/mocket-3.10.4/tests/main/test_mode.py --- old/mocket-3.10.2/tests/main/test_mode.py 1970-01-01 01:00:00.000000000 +0100 +++ new/mocket-3.10.4/tests/main/test_mode.py 2022-01-09 17:53:30.000000000 +0100 @@ -0,0 +1,28 @@ +import pytest +import requests + +from mocket import Mocketizer, mocketize +from mocket.exceptions import StrictMocketException + + +@mocketize(strict_mode=True) +def test_strict_mode_fails(): + url = "https://httpbin.org/ip" + + with pytest.raises(StrictMocketException): + requests.get(url) + + +@pytest.mark.skipif('os.getenv("SKIP_TRUE_HTTP", False)') +def test_intermittent_strict_mode(): + url = "https://httpbin.org/ip" + + with Mocketizer(strict_mode=False): + requests.get(url) + + with Mocketizer(strict_mode=True): + with pytest.raises(StrictMocketException): + requests.get(url) + + with Mocketizer(strict_mode=False): + requests.get(url) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mocket-3.10.2/tests/main/test_redis.py new/mocket-3.10.4/tests/main/test_redis.py --- old/mocket-3.10.2/tests/main/test_redis.py 2021-03-20 19:51:56.000000000 +0100 +++ new/mocket-3.10.4/tests/main/test_redis.py 2022-01-08 17:50:17.000000000 +0100 @@ -99,7 +99,7 @@ self.rclient.flushdb() def mocketize_teardown(self): - self.assertEqual(len(Mocket._requests), 0) + self.assertEqual(len(Mocket.request_list()), 0) @mocketize def test_set(self): @@ -165,14 +165,14 @@ def mocketize_setup(self): Entry.register_response("FLUSHDB", OK) self.rclient.flushdb() - self.assertEqual(len(Mocket._requests), 1) + self.assertEqual(len(Mocket.request_list()), 1) Mocket.reset() @mocketize def test_set(self): Entry.register_response('SET mocket "is awesome!"', OK) self.assertTrue(self.rclient.set("mocket", "is awesome!")) - self.assertEqual(len(Mocket._requests), 1) + self.assertEqual(len(Mocket.request_list()), 1) self.assertEqual( Mocket.last_request().data, b"*3\r\n$3\r\nSET\r\n$6\r\nmocket\r\n$11\r\nis awesome!\r\n", @@ -184,17 +184,17 @@ self.assertEqual(self.rclient.incr("counter"), 1) self.assertEqual(self.rclient.incr("counter"), 2) self.assertEqual(self.rclient.incr("counter"), 3) - self.assertEqual(len(Mocket._requests), 3) + self.assertEqual(len(Mocket.request_list()), 3) self.assertEqual( - Mocket._requests[0].data, + Mocket.request_list()[0].data, b"*3\r\n$6\r\nINCRBY\r\n$7\r\ncounter\r\n$1\r\n1\r\n", ) self.assertEqual( - Mocket._requests[1].data, + Mocket.request_list()[1].data, b"*3\r\n$6\r\nINCRBY\r\n$7\r\ncounter\r\n$1\r\n1\r\n", ) self.assertEqual( - Mocket._requests[2].data, + Mocket.request_list()[2].data, b"*3\r\n$6\r\nINCRBY\r\n$7\r\ncounter\r\n$1\r\n1\r\n", ) @@ -203,34 +203,34 @@ h = {b"f1": b"one", b"f2": b"two"} Entry.register_response("HGETALL hash", h) self.assertEqual(self.rclient.hgetall("hash"), h) - self.assertEqual(len(Mocket._requests), 1) + self.assertEqual(len(Mocket.request_list()), 1) self.assertEqual( - Mocket._requests[0].data, b"*2\r\n$7\r\nHGETALL\r\n$4\r\nhash\r\n" + Mocket.request_list()[0].data, b"*2\r\n$7\r\nHGETALL\r\n$4\r\nhash\r\n" ) @mocketize def test_get(self): Entry.register_response("GET mocket", "is awesome!") self.assertEqual(self.rclient.get("mocket"), b"is awesome!") - self.assertEqual(len(Mocket._requests), 1) + self.assertEqual(len(Mocket.request_list()), 1) self.assertEqual( - Mocket._requests[0].data, b"*2\r\n$3\r\nGET\r\n$6\r\nmocket\r\n" + Mocket.request_list()[0].data, b"*2\r\n$3\r\nGET\r\n$6\r\nmocket\r\n" ) @mocketize def test_get_utf8(self): Entry.register_response("GET snowman", "???") self.assertEqual(self.rclient.get("snowman"), b"\xe2\x98\x83") - self.assertEqual(len(Mocket._requests), 1) + self.assertEqual(len(Mocket.request_list()), 1) self.assertEqual( - Mocket._requests[0].data, b"*2\r\n$3\r\nGET\r\n$7\r\nsnowman\r\n" + Mocket.request_list()[0].data, b"*2\r\n$3\r\nGET\r\n$7\r\nsnowman\r\n" ) @mocketize def test_get_unicode(self): Entry.register_response("GET snowman", "\u2603") self.assertEqual(self.rclient.get("snowman"), b"\xe2\x98\x83") - self.assertEqual(len(Mocket._requests), 1) + self.assertEqual(len(Mocket.request_list()), 1) self.assertEqual( Mocket.last_request().data, b"*2\r\n$3\r\nGET\r\n$7\r\nsnowman\r\n" ) @@ -240,7 +240,7 @@ l = [b"one", b"two", b"three"] Entry.register_response("LRANGE list 0 -1", l) self.assertEqual(self.rclient.lrange("list", 0, -1), l) - self.assertEqual(len(Mocket._requests), 1) + self.assertEqual(len(Mocket.request_list()), 1) self.assertEqual( Mocket.last_request().data, b"*4\r\n$6\r\nLRANGE\r\n$4\r\nlist\r\n$1\r\n0\r\n$2\r\n-1\r\n", @@ -252,7 +252,7 @@ "INCRBY counter one", ERROR("ERR value is not an integer or out of range") ) self.assertRaises(redis.ResponseError, self.rclient.incr, "counter", "one") - self.assertEqual(len(Mocket._requests), 1) + self.assertEqual(len(Mocket.request_list()), 1) self.assertEqual( Mocket.last_request().data, b"*3\r\n$6\r\nINCRBY\r\n$7\r\ncounter\r\n$3\r\none\r\n", diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mocket-3.10.2/tests/tests35/README.txt new/mocket-3.10.4/tests/tests35/README.txt --- old/mocket-3.10.2/tests/tests35/README.txt 2021-03-20 19:51:56.000000000 +0100 +++ new/mocket-3.10.4/tests/tests35/README.txt 1970-01-01 01:00:00.000000000 +0100 @@ -1 +0,0 @@ -Since asyncio is only available on Python >= 3.5, these tests won't be available to builds using previous versions. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mocket-3.10.2/tests/tests35/test_http_aiohttp.py new/mocket-3.10.4/tests/tests35/test_http_aiohttp.py --- old/mocket-3.10.2/tests/tests35/test_http_aiohttp.py 2021-03-20 19:51:56.000000000 +0100 +++ new/mocket-3.10.4/tests/tests35/test_http_aiohttp.py 1970-01-01 01:00:00.000000000 +0100 @@ -1,81 +0,0 @@ -import asyncio -import json -from unittest import TestCase - -import aiohttp -import async_timeout - -from mocket.mocket import Mocket, mocketize -from mocket.mockhttp import Entry -from mocket.plugins.httpretty import HTTPretty, httprettified - - -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 - assert Mocket.last_request().method == 'POST' - assert Mocket.last_request().body == body * 6 - - loop = asyncio.get_event_loop() - loop.set_debug(True) - loop.run_until_complete(main(loop)) - self.assertEqual(len(Mocket._requests), 2) - - @mocketize - def test_https_session(self): - url = 'https://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.set_debug(True) - loop.run_until_complete(main(loop)) - self.assertEqual(len(Mocket._requests), 2) - - @httprettified - def test_httprettish_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)) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/mocket-3.10.2/tests/tests38/test_http_aiohttp.py new/mocket-3.10.4/tests/tests38/test_http_aiohttp.py --- old/mocket-3.10.2/tests/tests38/test_http_aiohttp.py 2021-08-30 23:46:19.000000000 +0200 +++ new/mocket-3.10.4/tests/tests38/test_http_aiohttp.py 2022-01-08 17:50:17.000000000 +0100 @@ -13,7 +13,7 @@ class AioHttpEntryTestCase(IsolatedAsyncioTestCase): @async_mocketize async def test_http_session(self): - url = 'http://httpbin.org/ip' + 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) @@ -28,14 +28,14 @@ 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().method == "POST" assert Mocket.last_request().body == body * 6 - self.assertEqual(len(Mocket._requests), 2) + self.assertEqual(len(Mocket.request_list()), 2) @async_mocketize async def test_https_session(self): - url = 'https://httpbin.org/ip' + url = "https://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) @@ -51,15 +51,15 @@ assert post_response.status == 201 assert await post_response.text() == body * 2 - self.assertEqual(len(Mocket._requests), 2) + self.assertEqual(len(Mocket.request_list()), 2) @async_httprettified async def test_httprettish_session(self): - url = 'https://httpbin.org/ip' + url = "https://httpbin.org/ip" HTTPretty.register_uri( HTTPretty.GET, url, - body=json.dumps(dict(origin='127.0.0.1')), + body=json.dumps(dict(origin="127.0.0.1")), ) async with aiohttp.ClientSession() as session: