diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2017-03-07 10:28:15 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2017-03-07 10:28:15 +1300 |
commit | b51df9a0b1cc9da1d7381421dfac481da6205a7a (patch) | |
tree | f61be6a2e0d0ac526ff237cf42b5270c3c42378a /test | |
parent | 2312cf6fb08e6c3f208a9bfe4af93c193dfd9ab1 (diff) | |
download | mitmproxy-b51df9a0b1cc9da1d7381421dfac481da6205a7a.tar.gz mitmproxy-b51df9a0b1cc9da1d7381421dfac481da6205a7a.tar.bz2 mitmproxy-b51df9a0b1cc9da1d7381421dfac481da6205a7a.zip |
Cleanups and test coverage
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/addons/test_core.py | 12 | ||||
-rw-r--r-- | test/mitmproxy/test_optmanager.py | 21 | ||||
-rw-r--r-- | test/mitmproxy/tools/test_dump.py | 5 |
3 files changed, 34 insertions, 4 deletions
diff --git a/test/mitmproxy/addons/test_core.py b/test/mitmproxy/addons/test_core.py index 533eb58e..7b9e9614 100644 --- a/test/mitmproxy/addons/test_core.py +++ b/test/mitmproxy/addons/test_core.py @@ -13,6 +13,18 @@ def test_simple(): tctx.configure(sa, body_size_limit = "1m") assert tctx.options._processed["body_size_limit"] + with pytest.raises(exceptions.OptionsError, match="mutually exclusive"): + tctx.configure( + sa, + add_upstream_certs_to_client_chain = True, + upstream_cert = False + ) + with pytest.raises(exceptions.OptionsError, match="Invalid mode"): + tctx.configure( + sa, + mode = "Flibble" + ) + @mock.patch("mitmproxy.platform.original_addr", None) def test_no_transparent(): diff --git a/test/mitmproxy/test_optmanager.py b/test/mitmproxy/test_optmanager.py index 1989cc0d..a38662d5 100644 --- a/test/mitmproxy/test_optmanager.py +++ b/test/mitmproxy/test_optmanager.py @@ -38,6 +38,12 @@ class TM(optmanager.OptManager): self.add_option("one", None, typing.Optional[str]) +def test_add_option(): + o = TO() + with pytest.raises(ValueError, match="already exists"): + o.add_option("one", None, typing.Optional[int]) + + def test_defaults(): o = TD2() defaults = { @@ -162,6 +168,8 @@ def test_rollback(): def err(opts, updated): if opts.one == 10: raise exceptions.OptionsError() + if opts.bool is True: + raise exceptions.OptionsError() o.changed.connect(sub) o.changed.connect(err) @@ -169,15 +177,24 @@ def test_rollback(): assert o.one is None o.one = 10 + o.bool = True assert isinstance(recerr[0]["exc"], exceptions.OptionsError) assert o.one is None - assert len(rec) == 2 + assert o.bool is False + assert len(rec) == 4 assert rec[0].one == 10 assert rec[1].one is None + assert rec[2].bool is True + assert rec[3].bool is False + + with pytest.raises(exceptions.OptionsError): + with o.rollback(set(["one"]), reraise=True): + raise exceptions.OptionsError() -def test_repr(): +def test_simple(): assert repr(TO()) + assert "one" in TO() def test_serialize(): diff --git a/test/mitmproxy/tools/test_dump.py b/test/mitmproxy/tools/test_dump.py index 3210b0bb..2542ec4b 100644 --- a/test/mitmproxy/tools/test_dump.py +++ b/test/mitmproxy/tools/test_dump.py @@ -3,6 +3,7 @@ import pytest from unittest import mock from mitmproxy import proxy +from mitmproxy import exceptions from mitmproxy import log from mitmproxy import controller from mitmproxy import options @@ -26,9 +27,9 @@ class TestDumpMaster(tservers.MasterTest): self.mkmaster(None, rfile=p), 1, b"", ) - with pytest.raises(dump.DumpError): + with pytest.raises(exceptions.OptionsError): self.mkmaster(None, rfile="/nonexistent") - with pytest.raises(dump.DumpError): + with pytest.raises(exceptions.OptionsError): self.mkmaster(None, rfile="test_dump.py") def test_has_error(self): |