def test_delete_value(self): request = self._get_request("/foo/bar/?test_delete_value=3") with LoggingBuffer(name="django_tools.debug.delay", level=logging.DEBUG) as log: CacheDelay( key="delay", only_debug=False ).load( request, query_string="test_delete_value", ) log.assert_messages([ "INFO:django_tools.debug.delay:Add 'test_delete_value' value to cache", "WARNING:django_tools.debug.delay:Save 3 sec. from 'test_delete_value' for 'delay' into cache" ]) with LoggingBuffer(name="django_tools.debug.delay", level=logging.DEBUG) as log: CacheDelay( key="delay", only_debug=False ).load( request, query_string="not_existing_key", ) log.assert_messages(["DEBUG:django_tools.debug.delay:Delete 'delay' delay from cache"])
def test_not_set(self): with LoggingBuffer(name="django_tools.debug.delay", level=logging.DEBUG) as log: with mock.patch.object(time, 'sleep', return_value=None) as mock_method: CacheDelay(key="test_not_set", only_debug=False).sleep() log.assert_messages(["DEBUG:django_tools.debug.delay:No delay for 'test_not_set' from cache"]) mock_method.assert_not_called()
def test_not_set(self): with self.assertLogs(logger="django_tools.debug.delay", level=logging.DEBUG) as log: with mock.patch.object(time, 'sleep', return_value=None) as mock_method: CacheDelay(key="test_not_set", only_debug=False).sleep() assert log.output == ["DEBUG:django_tools.debug.delay:No delay for 'test_not_set' from cache"] mock_method.assert_not_called()
def test_only_debug(self): request = self._get_request("/foo/bar/?delay=2") with LoggingBuffer(name="django_tools.debug.delay", level=logging.DEBUG) as log: CacheDelay(key="delay").load( request, query_string="delay", ) log.assert_messages(["DEBUG:django_tools.debug.delay:Ignore ?delay, because DEBUG is not ON!"])
def test_only_debug(self): request = self._get_request("/foo/bar/?delay=2") with self.assertLogs(logger="django_tools.debug.delay", level=logging.DEBUG) as log: CacheDelay(key="delay").load( request, query_string="delay", ) assert log.output == ["DEBUG:django_tools.debug.delay:Ignore ?delay, because DEBUG is not ON!"]
def test_delay(self): request = self._get_request("/foo/bar/?delay=2") with LoggingBuffer(name="django_tools.debug.delay", level=logging.DEBUG) as log: CacheDelay( key="delay", only_debug=False ).load( request, query_string="delay", ) log.assert_messages([ "INFO:django_tools.debug.delay:Add 'delay' value to cache", "WARNING:django_tools.debug.delay:Save 2 sec. from 'delay' for 'delay' into cache" ]) with LoggingBuffer(name="django_tools.debug.delay", level=logging.DEBUG) as log: with mock.patch.object(time, 'sleep', return_value=None) as mock_method: CacheDelay(key="delay", only_debug=False).sleep() log.assert_messages(["WARNING:django_tools.debug.delay:Delay 2 sec. for 'delay'"]) mock_method.assert_called_once_with(2)
def test_default_value(self): request = self._get_request("/foo/bar/?test_default_value") with self.assertLogs(logger="django_tools.debug.delay", level=logging.DEBUG) as log: CacheDelay( key="delay", only_debug=False ).load( request, query_string="test_default_value", default=123, ) assert log.output == [ "INFO:django_tools.debug.delay:Add 'test_default_value' value to cache", "WARNING:django_tools.debug.delay:Save 123 sec. from 'test_default_value' for 'delay' into cache" ] with self.assertLogs(logger="django_tools.debug.delay", level=logging.DEBUG) as log: with mock.patch.object(time, 'sleep', return_value=None) as mock_method: CacheDelay(key="delay", only_debug=False).sleep() assert log.output == ["WARNING:django_tools.debug.delay:Delay 123 sec. for 'delay'"] mock_method.assert_called_once_with(123)