Skip to content

Commit d9d181b

Browse files
committed
test_enable_devtools and remove redundant guards for None and "" which was there due to a bug
1 parent c8f928f commit d9d181b

File tree

2 files changed

+45
-16
lines changed

2 files changed

+45
-16
lines changed

proxy/proxy.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,7 @@ def load_plugins(
412412
}
413413
for plugin_ in plugins:
414414
klass, module_name = Proxy.import_plugin(plugin_)
415-
if klass is None and module_name is None:
416-
continue
415+
assert klass and module_name
417416
mro = list(inspect.getmro(klass))
418417
mro.reverse()
419418
iterator = iter(mro)
@@ -432,8 +431,7 @@ def import_plugin(plugin: Union[bytes, type]) -> Any:
432431
klass = plugin
433432
else:
434433
plugin_ = text_(plugin.strip())
435-
if plugin_ == '':
436-
return (None, None)
434+
assert plugin_ != ''
437435
module_name, klass_name = plugin_.rsplit(text_(DOT), 1)
438436
klass = getattr(
439437
importlib.import_module(
@@ -449,8 +447,9 @@ def import_plugin(plugin: Union[bytes, type]) -> Any:
449447
def get_default_plugins(
450448
args: argparse.Namespace,
451449
) -> List[str]:
452-
# Prepare list of plugins to load based upon
453-
# --enable-*, --disable-* and --basic-auth flags.
450+
"""Prepare list of plugins to load based upon
451+
--enable-*, --disable-* and --basic-auth flags.
452+
"""
454453
default_plugins: List[str] = []
455454
if args.basic_auth is not None:
456455
default_plugins.append(PLUGIN_PROXY_AUTH)
@@ -514,7 +513,7 @@ def main(
514513
# at runtime. Example, updating flags, plugin
515514
# configuration etc.
516515
#
517-
# TODO: Python shell within running proxy.py environment
516+
# TODO: Python shell within running proxy.py environment?
518517
while True:
519518
time.sleep(1)
520519
except KeyboardInterrupt:

tests/test_main.py

+39-9
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,39 @@ def test_enable_dashboard(
177177
mock_event_manager.return_value.start_event_dispatcher.assert_called_once()
178178
mock_event_manager.return_value.stop_event_dispatcher.assert_called_once()
179179

180+
@mock.patch('time.sleep')
181+
@mock.patch('proxy.proxy.Proxy.load_plugins')
182+
@mock.patch('proxy.common.flag.FlagParser.parse_args')
183+
@mock.patch('proxy.proxy.EventManager')
184+
@mock.patch('proxy.proxy.AcceptorPool')
185+
def test_enable_devtools(
186+
self,
187+
mock_acceptor_pool: mock.Mock,
188+
mock_event_manager: mock.Mock,
189+
mock_parse_args: mock.Mock,
190+
mock_load_plugins: mock.Mock,
191+
mock_sleep: mock.Mock,
192+
) -> None:
193+
mock_sleep.side_effect = KeyboardInterrupt()
194+
mock_args = mock_parse_args.return_value
195+
self.mock_default_args(mock_args)
196+
mock_args.enable_devtools = True
197+
main(['--enable-devtools'])
198+
mock_load_plugins.assert_called()
199+
print(mock_load_plugins.call_args_list[0][0][0])
200+
self.assertEqual(
201+
mock_load_plugins.call_args_list[0][0][0], [
202+
b'proxy.http.inspector.DevtoolsProtocolPlugin',
203+
b'proxy.http.server.HttpWebServerPlugin',
204+
b'proxy.http.proxy.HttpProxyPlugin',
205+
],
206+
)
207+
mock_parse_args.assert_called_once()
208+
mock_acceptor_pool.assert_called()
209+
mock_acceptor_pool.return_value.setup.assert_called()
210+
# Currently --enable-devtools alone doesn't enable eventing core
211+
mock_event_manager.assert_not_called()
212+
180213
@mock.patch('time.sleep')
181214
@mock.patch('os.remove')
182215
@mock.patch('os.path.exists')
@@ -284,14 +317,11 @@ def test_main_version(
284317
mock_print.assert_called_with(__version__)
285318
self.assertEqual(e.exception.code, 0)
286319

287-
def test_enable_devtools(self) -> None:
288-
pass
289-
290-
def test_pac_file(self) -> None:
291-
pass
320+
# def test_pac_file(self) -> None:
321+
# pass
292322

293-
def test_imports_plugin(self) -> None:
294-
pass
323+
# def test_imports_plugin(self) -> None:
324+
# pass
295325

296-
def test_cannot_enable_https_proxy_and_tls_interception_mutually(self) -> None:
297-
pass
326+
# def test_cannot_enable_https_proxy_and_tls_interception_mutually(self) -> None:
327+
# pass

0 commit comments

Comments
 (0)