From 744a6868fe2d645c16ebe217b807b817e0c1517b Mon Sep 17 00:00:00 2001 From: Stuart Longland Date: Thu, 8 Jul 2021 07:52:01 +1000 Subject: [PATCH] plugins.topic_checking: De-indent logging checks As pointed out, the `logdog` docs do the checks outside of the context manager scope, so we should do so as well. --- tests/plugins/test_topic_checking.py | 134 +++++++++++++-------------- 1 file changed, 67 insertions(+), 67 deletions(-) diff --git a/tests/plugins/test_topic_checking.py b/tests/plugins/test_topic_checking.py index a198c38..36192f1 100644 --- a/tests/plugins/test_topic_checking.py +++ b/tests/plugins/test_topic_checking.py @@ -28,21 +28,21 @@ async def test_base_no_config(logdog): authorised = plugin.topic_filtering() assert authorised is False - # Should have printed a couple of warnings - log_records = list(pile.drain(name="testlog")) - assert len(log_records) == 2 - assert log_records[0].levelno == logging.WARN - assert ( - log_records[0].message - == "'topic-check' section not found in context configuration" - ) + # Should have printed a couple of warnings + log_records = list(pile.drain(name="testlog")) + assert len(log_records) == 2 + assert log_records[0].levelno == logging.WARN + assert ( + log_records[0].message + == "'topic-check' section not found in context configuration" + ) - assert log_records[1].levelno == logging.WARN - assert ( - log_records[1].message - == "'auth' section not found in context configuration" - ) - assert pile.is_empty() + assert log_records[1].levelno == logging.WARN + assert ( + log_records[1].message + == "'auth' section not found in context configuration" + ) + assert pile.is_empty() @pytest.mark.asyncio @@ -59,14 +59,14 @@ async def test_base_empty_config(logdog): authorised = plugin.topic_filtering() assert authorised is False - # Should have printed just one warning - log_records = list(pile.drain(name="testlog")) - assert len(log_records) == 1 - assert log_records[0].levelno == logging.WARN - assert ( - log_records[0].message - == "'auth' section not found in context configuration" - ) + # Should have printed just one warning + log_records = list(pile.drain(name="testlog")) + assert len(log_records) == 1 + assert log_records[0].levelno == logging.WARN + assert ( + log_records[0].message + == "'auth' section not found in context configuration" + ) @pytest.mark.asyncio @@ -83,9 +83,9 @@ async def test_base_disabled_config(logdog): authorised = plugin.topic_filtering() assert authorised is True - # Should NOT have printed warnings - log_records = list(pile.drain(name="testlog")) - assert len(log_records) == 0 + # Should NOT have printed warnings + log_records = list(pile.drain(name="testlog")) + assert len(log_records) == 0 @pytest.mark.asyncio @@ -102,9 +102,9 @@ async def test_base_enabled_config(logdog): authorised = plugin.topic_filtering() assert authorised is True - # Should NOT have printed warnings - log_records = list(pile.drain(name="testlog")) - assert len(log_records) == 0 + # Should NOT have printed warnings + log_records = list(pile.drain(name="testlog")) + assert len(log_records) == 0 # Taboo plug-in @@ -123,19 +123,19 @@ async def test_taboo_empty_config(logdog): plugin = TopicTabooPlugin(context) assert (await plugin.topic_filtering()) is False - # Should have printed a couple of warnings - log_records = list(pile.drain(name="testlog")) - assert len(log_records) == 2 - assert log_records[0].levelno == logging.WARN - assert ( - log_records[0].message - == "'topic-check' section not found in context configuration" - ) - assert log_records[1].levelno == logging.WARN - assert ( - log_records[1].message - == "'auth' section not found in context configuration" - ) + # Should have printed a couple of warnings + log_records = list(pile.drain(name="testlog")) + assert len(log_records) == 2 + assert log_records[0].levelno == logging.WARN + assert ( + log_records[0].message + == "'topic-check' section not found in context configuration" + ) + assert log_records[1].levelno == logging.WARN + assert ( + log_records[1].message + == "'auth' section not found in context configuration" + ) @pytest.mark.asyncio @@ -156,9 +156,9 @@ async def test_taboo_not_taboo_topic(logdog): await plugin.topic_filtering(session=session, topic="not/prohibited") ) is True - # Should NOT have printed warnings - log_records = list(pile.drain(name="testlog")) - assert len(log_records) == 0 + # Should NOT have printed warnings + log_records = list(pile.drain(name="testlog")) + assert len(log_records) == 0 @pytest.mark.asyncio @@ -179,9 +179,9 @@ async def test_taboo_not_taboo_topic(logdog): await plugin.topic_filtering(session=session, topic="not/prohibited") ) is True - # Should NOT have printed warnings - log_records = list(pile.drain(name="testlog")) - assert len(log_records) == 0 + # Should NOT have printed warnings + log_records = list(pile.drain(name="testlog")) + assert len(log_records) == 0 @pytest.mark.asyncio @@ -202,9 +202,9 @@ async def test_taboo_anon_taboo_topic(logdog): await plugin.topic_filtering(session=session, topic="prohibited") ) is False - # Should NOT have printed warnings - log_records = list(pile.drain(name="testlog")) - assert len(log_records) == 0 + # Should NOT have printed warnings + log_records = list(pile.drain(name="testlog")) + assert len(log_records) == 0 @pytest.mark.asyncio @@ -225,9 +225,9 @@ async def test_taboo_notadmin_taboo_topic(logdog): await plugin.topic_filtering(session=session, topic="prohibited") ) is False - # Should NOT have printed warnings - log_records = list(pile.drain(name="testlog")) - assert len(log_records) == 0 + # Should NOT have printed warnings + log_records = list(pile.drain(name="testlog")) + assert len(log_records) == 0 @pytest.mark.asyncio @@ -248,9 +248,9 @@ async def test_taboo_admin_taboo_topic(logdog): await plugin.topic_filtering(session=session, topic="prohibited") ) is True - # Should NOT have printed warnings - log_records = list(pile.drain(name="testlog")) - assert len(log_records) == 0 + # Should NOT have printed warnings + log_records = list(pile.drain(name="testlog")) + assert len(log_records) == 0 # TopicAccessControlListPlugin tests @@ -324,17 +324,17 @@ async def test_taclp_empty_config(logdog): plugin = TopicAccessControlListPlugin(context) assert (await plugin.topic_filtering()) is False - # Should have printed a couple of warnings - log_records = list(pile.drain(name="testlog")) - assert len(log_records) == 2 - assert ( - log_records[0].message - == "'topic-check' section not found in context configuration" - ) - assert ( - log_records[1].message - == "'auth' section not found in context configuration" - ) + # Should have printed a couple of warnings + log_records = list(pile.drain(name="testlog")) + assert len(log_records) == 2 + assert ( + log_records[0].message + == "'topic-check' section not found in context configuration" + ) + assert ( + log_records[1].message + == "'auth' section not found in context configuration" + ) @pytest.mark.asyncio