aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkira0204 <rshtmudgal@gmail.com>2018-03-12 00:28:43 +0530
committerkira0204 <rshtmudgal@gmail.com>2018-03-12 00:28:43 +0530
commit5dcc3b4ff832f817fc621d9116f1b399eb2ff137 (patch)
tree2e606791765ad80fe7384f66dbc67de5e435ef73
parent167e01acdfac792412b48fd2b30e7bd85b028cda (diff)
downloadmitmproxy-5dcc3b4ff832f817fc621d9116f1b399eb2ff137.tar.gz
mitmproxy-5dcc3b4ff832f817fc621d9116f1b399eb2ff137.tar.bz2
mitmproxy-5dcc3b4ff832f817fc621d9116f1b399eb2ff137.zip
Testing using addon
-rw-r--r--test/mitmproxy/test_command.py28
1 files changed, 17 insertions, 11 deletions
diff --git a/test/mitmproxy/test_command.py b/test/mitmproxy/test_command.py
index 0c8d7208..32498578 100644
--- a/test/mitmproxy/test_command.py
+++ b/test/mitmproxy/test_command.py
@@ -1,5 +1,4 @@
import typing
-from unittest import mock
from mitmproxy import command
from mitmproxy import flow
from mitmproxy import exceptions
@@ -310,20 +309,27 @@ class TDec:
pass
+class TAttr:
+ def __getattr__(self, item):
+ raise IOError
+
+
+class TCmds(TAttr):
+ def __init__(self):
+ self.TAttr = TAttr()
+
+
def test_collect_commands():
"""
This tests for the error thrown by hasattr()
"""
- with mock.patch("mitmproxy.command.hasattr") as mock_hasattr:
- mock_hasattr.return_value = False
- with taddons.context() as tctx:
- mock_hasattr.side_effect = OSError
- c = command.CommandManager(tctx.master)
- a = TDec()
- c.collect_commands(a)
- assert "cmd1" not in c.commands
- assert "cmd2" not in c.commands
- assert "empty" not in c.commands
+ with taddons.context() as tctx:
+ c = command.CommandManager(tctx.master)
+ a = TCmds()
+ c.collect_commands(a)
+ assert "cmd1" not in c.commands
+ assert "cmd2" not in c.commands
+ assert "empty" not in c.commands
def test_decorator():