Skip to content
This repository was archived by the owner on Apr 27, 2019. It is now read-only.

Commit c33e3ce

Browse files
committed
[142] Added tests for mapping and demapping overridden packets.
1 parent f0e1def commit c33e3ce

3 files changed

Lines changed: 100 additions & 2 deletions

File tree

plugin_manager.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,11 @@ def do(self, protocol, when, data):
255255
try:
256256
plugin.protocol = protocol
257257
res = packet_method(data)
258-
if res is None:
258+
if res is False:
259+
return False
260+
elif res is None:
259261
res = True
262+
260263
return_values.append(res)
261264
except:
262265
self.logger.exception(

tests/test_base_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def test_mapping_override_packets_dont_include_base_plugin(self):
99
with self.assertRaises(AttributeError):
1010
base_plugin.overridden_packets
1111

12-
def test_activation_defactivation(self):
12+
def test_activation_deactivation(self):
1313
class TestPlugin(BasePlugin):
1414
pass
1515

tests/test_plugin_manager.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,101 @@ def test_installed_plugins(self, mock_config, mock_path, mock_sys):
105105

106106
self.assertListEqual(result, ['plugin'])
107107

108+
@patch('plugin_manager.sys')
109+
@patch('plugin_manager.path')
110+
@patch('plugin_manager.ConfigurationManager')
111+
def test_de_map_plugin_packets(self, mock_config, mock_path, mock_sys):
112+
mock_plugin = Mock()
113+
mock_plugin.name = 'Test'
114+
115+
pm = PluginManager(Mock())
116+
pm.packets = {
117+
1: {
118+
'on': {
119+
'Test': 'remove me'
120+
},
121+
'after': {'Test2': 'test'}
122+
},
123+
2: {
124+
'on': {
125+
'Test': 'remove me',
126+
'Test3': 'test'
127+
},
128+
'after': {
129+
'Test': 'remove me'
130+
},
131+
}
132+
}
133+
pm.de_map_plugin_packets(mock_plugin)
134+
self.assertDictEqual(
135+
pm.packets,
136+
{
137+
1: {
138+
'on': {},
139+
'after': {'Test2': 'test'}
140+
},
141+
2: {
142+
'on': {
143+
'Test3': 'test'
144+
},
145+
'after': {},
146+
}
147+
}
148+
)
149+
150+
@patch('plugin_manager.sys')
151+
@patch('plugin_manager.path')
152+
@patch('plugin_manager.ConfigurationManager')
153+
def test_map_plugin_packets(self, mock_config, mock_path, mock_sys):
154+
mock_plugin = Mock()
155+
mock_plugin.name = 'Test'
156+
mock_plugin.overridden_packets = {
157+
1: {
158+
'on': 'add me on 1',
159+
'after': 'add me after 1'
160+
}
161+
}
162+
mock_plugin2 = Mock()
163+
mock_plugin2.name = 'Test2'
164+
mock_plugin2.overridden_packets = {
165+
2: {
166+
'on': 'add me on 2'
167+
},
168+
3: {
169+
'after': 'add me after 2'
170+
}
171+
}
172+
173+
pm = PluginManager(Mock())
174+
pm.map_plugin_packets(mock_plugin)
175+
176+
self.assertDictEqual(
177+
pm.packets,
178+
{
179+
1: {
180+
'on': {'Test': (mock_plugin, 'add me on 1')},
181+
'after': {'Test': (mock_plugin, 'add me after 1')}
182+
}
183+
}
184+
)
185+
186+
pm.map_plugin_packets(mock_plugin2)
187+
self.assertDictEqual(
188+
pm.packets,
189+
{
190+
1: {
191+
'on': {'Test': (mock_plugin, 'add me on 1')},
192+
'after': {'Test': (mock_plugin, 'add me after 1')}
193+
},
194+
2: {
195+
'on': {'Test2': (mock_plugin2, 'add me on 2')}
196+
},
197+
3: {
198+
'after': {'Test2': (mock_plugin2, 'add me after 2')}
199+
}
200+
}
201+
)
202+
108203

109204
class RouteTestCase(TestCase):
110205
@patch('plugin_manager.reactor')

0 commit comments

Comments
 (0)