-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugins.topic_checking tests: Test BaseTopicPlugin.
- Loading branch information
1 parent
6ab32a1
commit 60f3bee
Showing
1 changed file
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Copyright (c) 2015 Nicolas JOUANIN | ||
# | ||
# See the file license.txt for copying permission. | ||
|
||
import pytest | ||
|
||
from amqtt.plugins.manager import BaseContext | ||
from amqtt.plugins.topic_checking import BaseTopicPlugin, TopicTabooPlugin, TopicAccessControlListPlugin | ||
|
||
|
||
class DummyLogger(object): | ||
def __init__(self): | ||
self.messages = [] | ||
|
||
def warning(self, *args, **kwargs): | ||
self.messages.append((args, kwargs)) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_base_no_config(): | ||
""" | ||
Check BaseTopicPlugin returns false if no topic-check is present. | ||
""" | ||
context = BaseContext() | ||
context.logger = DummyLogger() | ||
context.config = {} | ||
|
||
plugin = BaseTopicPlugin(context) | ||
assert plugin.topic_filtering() is False | ||
|
||
# Should have printed a couple of warnings | ||
assert len(context.logger.messages) == 2 | ||
assert context.logger.messages[0] == ( | ||
("'topic-check' section not found in context configuration",), | ||
{} | ||
) | ||
assert context.logger.messages[1] == ( | ||
("'auth' section not found in context configuration",), | ||
{} | ||
) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_base_empty_config(): | ||
""" | ||
Check BaseTopicPlugin returns false if topic-check is empty. | ||
""" | ||
context = BaseContext() | ||
context.logger = DummyLogger() | ||
context.config = { | ||
'topic-check': {} | ||
} | ||
|
||
plugin = BaseTopicPlugin(context) | ||
assert plugin.topic_filtering() is False | ||
|
||
# Should NOT have printed warnings | ||
assert len(context.logger.messages) == 1 | ||
assert context.logger.messages[0] == ( | ||
("'auth' section not found in context configuration",), | ||
{} | ||
) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_base_enabled_config(): | ||
""" | ||
Check BaseTopicPlugin returns true if enabled. | ||
""" | ||
context = BaseContext() | ||
context.logger = DummyLogger() | ||
context.config = { | ||
'topic-check': { | ||
'enabled': True | ||
} | ||
} | ||
|
||
plugin = BaseTopicPlugin(context) | ||
assert plugin.topic_filtering() is True | ||
|
||
# Should NOT have printed warnings | ||
assert len(context.logger.messages) == 0 |