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.
pull/69/head
Stuart Longland 2021-07-08 07:52:01 +10:00 zatwierdzone przez Florian Ludwig
rodzic 1f31e1668a
commit 744a6868fe
1 zmienionych plików z 67 dodań i 67 usunięć

Wyświetl plik

@ -28,21 +28,21 @@ async def test_base_no_config(logdog):
authorised = plugin.topic_filtering() authorised = plugin.topic_filtering()
assert authorised is False assert authorised is False
# Should have printed a couple of warnings # Should have printed a couple of warnings
log_records = list(pile.drain(name="testlog")) log_records = list(pile.drain(name="testlog"))
assert len(log_records) == 2 assert len(log_records) == 2
assert log_records[0].levelno == logging.WARN assert log_records[0].levelno == logging.WARN
assert ( assert (
log_records[0].message log_records[0].message
== "'topic-check' section not found in context configuration" == "'topic-check' section not found in context configuration"
) )
assert log_records[1].levelno == logging.WARN assert log_records[1].levelno == logging.WARN
assert ( assert (
log_records[1].message log_records[1].message
== "'auth' section not found in context configuration" == "'auth' section not found in context configuration"
) )
assert pile.is_empty() assert pile.is_empty()
@pytest.mark.asyncio @pytest.mark.asyncio
@ -59,14 +59,14 @@ async def test_base_empty_config(logdog):
authorised = plugin.topic_filtering() authorised = plugin.topic_filtering()
assert authorised is False assert authorised is False
# Should have printed just one warning # Should have printed just one warning
log_records = list(pile.drain(name="testlog")) log_records = list(pile.drain(name="testlog"))
assert len(log_records) == 1 assert len(log_records) == 1
assert log_records[0].levelno == logging.WARN assert log_records[0].levelno == logging.WARN
assert ( assert (
log_records[0].message log_records[0].message
== "'auth' section not found in context configuration" == "'auth' section not found in context configuration"
) )
@pytest.mark.asyncio @pytest.mark.asyncio
@ -83,9 +83,9 @@ async def test_base_disabled_config(logdog):
authorised = plugin.topic_filtering() authorised = plugin.topic_filtering()
assert authorised is True assert authorised is True
# Should NOT have printed warnings # Should NOT have printed warnings
log_records = list(pile.drain(name="testlog")) log_records = list(pile.drain(name="testlog"))
assert len(log_records) == 0 assert len(log_records) == 0
@pytest.mark.asyncio @pytest.mark.asyncio
@ -102,9 +102,9 @@ async def test_base_enabled_config(logdog):
authorised = plugin.topic_filtering() authorised = plugin.topic_filtering()
assert authorised is True assert authorised is True
# Should NOT have printed warnings # Should NOT have printed warnings
log_records = list(pile.drain(name="testlog")) log_records = list(pile.drain(name="testlog"))
assert len(log_records) == 0 assert len(log_records) == 0
# Taboo plug-in # Taboo plug-in
@ -123,19 +123,19 @@ async def test_taboo_empty_config(logdog):
plugin = TopicTabooPlugin(context) plugin = TopicTabooPlugin(context)
assert (await plugin.topic_filtering()) is False assert (await plugin.topic_filtering()) is False
# Should have printed a couple of warnings # Should have printed a couple of warnings
log_records = list(pile.drain(name="testlog")) log_records = list(pile.drain(name="testlog"))
assert len(log_records) == 2 assert len(log_records) == 2
assert log_records[0].levelno == logging.WARN assert log_records[0].levelno == logging.WARN
assert ( assert (
log_records[0].message log_records[0].message
== "'topic-check' section not found in context configuration" == "'topic-check' section not found in context configuration"
) )
assert log_records[1].levelno == logging.WARN assert log_records[1].levelno == logging.WARN
assert ( assert (
log_records[1].message log_records[1].message
== "'auth' section not found in context configuration" == "'auth' section not found in context configuration"
) )
@pytest.mark.asyncio @pytest.mark.asyncio
@ -156,9 +156,9 @@ async def test_taboo_not_taboo_topic(logdog):
await plugin.topic_filtering(session=session, topic="not/prohibited") await plugin.topic_filtering(session=session, topic="not/prohibited")
) is True ) is True
# Should NOT have printed warnings # Should NOT have printed warnings
log_records = list(pile.drain(name="testlog")) log_records = list(pile.drain(name="testlog"))
assert len(log_records) == 0 assert len(log_records) == 0
@pytest.mark.asyncio @pytest.mark.asyncio
@ -179,9 +179,9 @@ async def test_taboo_not_taboo_topic(logdog):
await plugin.topic_filtering(session=session, topic="not/prohibited") await plugin.topic_filtering(session=session, topic="not/prohibited")
) is True ) is True
# Should NOT have printed warnings # Should NOT have printed warnings
log_records = list(pile.drain(name="testlog")) log_records = list(pile.drain(name="testlog"))
assert len(log_records) == 0 assert len(log_records) == 0
@pytest.mark.asyncio @pytest.mark.asyncio
@ -202,9 +202,9 @@ async def test_taboo_anon_taboo_topic(logdog):
await plugin.topic_filtering(session=session, topic="prohibited") await plugin.topic_filtering(session=session, topic="prohibited")
) is False ) is False
# Should NOT have printed warnings # Should NOT have printed warnings
log_records = list(pile.drain(name="testlog")) log_records = list(pile.drain(name="testlog"))
assert len(log_records) == 0 assert len(log_records) == 0
@pytest.mark.asyncio @pytest.mark.asyncio
@ -225,9 +225,9 @@ async def test_taboo_notadmin_taboo_topic(logdog):
await plugin.topic_filtering(session=session, topic="prohibited") await plugin.topic_filtering(session=session, topic="prohibited")
) is False ) is False
# Should NOT have printed warnings # Should NOT have printed warnings
log_records = list(pile.drain(name="testlog")) log_records = list(pile.drain(name="testlog"))
assert len(log_records) == 0 assert len(log_records) == 0
@pytest.mark.asyncio @pytest.mark.asyncio
@ -248,9 +248,9 @@ async def test_taboo_admin_taboo_topic(logdog):
await plugin.topic_filtering(session=session, topic="prohibited") await plugin.topic_filtering(session=session, topic="prohibited")
) is True ) is True
# Should NOT have printed warnings # Should NOT have printed warnings
log_records = list(pile.drain(name="testlog")) log_records = list(pile.drain(name="testlog"))
assert len(log_records) == 0 assert len(log_records) == 0
# TopicAccessControlListPlugin tests # TopicAccessControlListPlugin tests
@ -324,17 +324,17 @@ async def test_taclp_empty_config(logdog):
plugin = TopicAccessControlListPlugin(context) plugin = TopicAccessControlListPlugin(context)
assert (await plugin.topic_filtering()) is False assert (await plugin.topic_filtering()) is False
# Should have printed a couple of warnings # Should have printed a couple of warnings
log_records = list(pile.drain(name="testlog")) log_records = list(pile.drain(name="testlog"))
assert len(log_records) == 2 assert len(log_records) == 2
assert ( assert (
log_records[0].message log_records[0].message
== "'topic-check' section not found in context configuration" == "'topic-check' section not found in context configuration"
) )
assert ( assert (
log_records[1].message log_records[1].message
== "'auth' section not found in context configuration" == "'auth' section not found in context configuration"
) )
@pytest.mark.asyncio @pytest.mark.asyncio