mirror of
https://github.com/mitmproxy/mitmproxy.git
synced 2024-11-23 21:30:04 +00:00
Bump unit tests for flow.py and dump.py
This commit is contained in:
parent
9c5c3c2b1a
commit
d7ace1ce9e
@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
import sys
|
||||
sys.path.insert(0, "..")
|
||||
print >> sys.stderr, "output"
|
||||
sys.exit(1)
|
||||
|
||||
|
@ -6,19 +6,21 @@ import utils
|
||||
|
||||
|
||||
class uDumpMaster(libpry.AutoTree):
|
||||
def _cycle(self, m):
|
||||
def _cycle(self, m, content):
|
||||
req = utils.treq()
|
||||
req.content = content
|
||||
cc = req.client_conn
|
||||
resp = utils.tresp(req)
|
||||
resp.content = content
|
||||
m.handle_clientconnect(cc)
|
||||
m.handle_request(req)
|
||||
m.handle_response(resp)
|
||||
|
||||
def _dummy_cycle(self, filt, **options):
|
||||
def _dummy_cycle(self, filt, content, **options):
|
||||
cs = StringIO()
|
||||
o = dump.Options(**options)
|
||||
m = dump.DumpMaster(None, o, filt, outfile=cs)
|
||||
self._cycle(m)
|
||||
self._cycle(m, content)
|
||||
return cs.getvalue()
|
||||
|
||||
def test_options(self):
|
||||
@ -27,16 +29,18 @@ class uDumpMaster(libpry.AutoTree):
|
||||
libpry.raises(AttributeError, dump.Options, nonexistent = 2)
|
||||
|
||||
def test_filter(self):
|
||||
assert not "GET" in self._dummy_cycle("~u foo", verbosity=1)
|
||||
assert not "GET" in self._dummy_cycle("~u foo", "", verbosity=1)
|
||||
|
||||
def test_basic(self):
|
||||
for i in (1, 2, 3):
|
||||
assert "GET" in self._dummy_cycle("~s", verbosity=i)
|
||||
assert "GET" in self._dummy_cycle("~s", "", verbosity=i)
|
||||
assert "GET" in self._dummy_cycle("~s", "\x00\x00\x00", verbosity=i)
|
||||
assert "GET" in self._dummy_cycle("~s", "ascii", verbosity=i)
|
||||
|
||||
def test_write(self):
|
||||
d = self.tmpdir()
|
||||
p = os.path.join(d, "a")
|
||||
self._dummy_cycle(None, wfile=p, verbosity=0)
|
||||
self._dummy_cycle(None, "", wfile=p, verbosity=0)
|
||||
assert len(list(flow.FlowReader(open(p)).stream())) == 1
|
||||
|
||||
def test_write_err(self):
|
||||
@ -44,33 +48,34 @@ class uDumpMaster(libpry.AutoTree):
|
||||
dump.DumpError,
|
||||
self._dummy_cycle,
|
||||
None,
|
||||
"",
|
||||
wfile = "nonexistentdir/foo"
|
||||
)
|
||||
|
||||
def test_request_script(self):
|
||||
ret = self._dummy_cycle(None, request_script="scripts/a", verbosity=1)
|
||||
ret = self._dummy_cycle(None, "", request_script="scripts/a", verbosity=1)
|
||||
assert "TESTOK" in ret
|
||||
assert "DEBUG" in ret
|
||||
libpry.raises(
|
||||
dump.DumpError,
|
||||
self._dummy_cycle, None, request_script="nonexistent"
|
||||
self._dummy_cycle, None, "", request_script="nonexistent"
|
||||
)
|
||||
libpry.raises(
|
||||
dump.DumpError,
|
||||
self._dummy_cycle, None, request_script="scripts/err_data"
|
||||
self._dummy_cycle, None, "", request_script="scripts/err_return"
|
||||
)
|
||||
|
||||
def test_response_script(self):
|
||||
ret = self._dummy_cycle(None, response_script="scripts/a", verbosity=1)
|
||||
ret = self._dummy_cycle(None, "", response_script="scripts/a", verbosity=1)
|
||||
assert "TESTOK" in ret
|
||||
assert "DEBUG" in ret
|
||||
libpry.raises(
|
||||
dump.DumpError,
|
||||
self._dummy_cycle, None, response_script="nonexistent"
|
||||
self._dummy_cycle, None, "", response_script="nonexistent"
|
||||
)
|
||||
libpry.raises(
|
||||
dump.DumpError,
|
||||
self._dummy_cycle, None, response_script="scripts/err_data"
|
||||
self._dummy_cycle, None, "", response_script="scripts/err_return"
|
||||
)
|
||||
|
||||
|
||||
|
@ -51,6 +51,14 @@ class uFlow(libpry.AutoTree):
|
||||
state = f.get_state()
|
||||
assert f == flow.Flow.from_state(state)
|
||||
|
||||
f2 = utils.tflow()
|
||||
f2.error = proxy.Error(f, "e2")
|
||||
assert not f == f2
|
||||
f.load_state(f2.get_state())
|
||||
assert f == f2
|
||||
|
||||
|
||||
|
||||
def test_kill(self):
|
||||
f = utils.tflow()
|
||||
f.request = utils.treq()
|
||||
|
Loading…
Reference in New Issue
Block a user