diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2012-03-16 11:12:56 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2012-03-16 11:12:56 +1300 |
commit | d51b8cab0c0d1352865155865dfd258f66103ffe (patch) | |
tree | f5e950d77224908da351d5d809486d3c0c9c1588 /test | |
parent | 8d662e6636b534bdb9fd2f2312589b6e8e453378 (diff) | |
download | mitmproxy-d51b8cab0c0d1352865155865dfd258f66103ffe.tar.gz mitmproxy-d51b8cab0c0d1352865155865dfd258f66103ffe.tar.bz2 mitmproxy-d51b8cab0c0d1352865155865dfd258f66103ffe.zip |
Add a decoded context manager.
This simplifies a common chore when modifying traffic - decoding the object,
modifying it, then re-encoding it with the same encoding afterwards. You can
now simply say:
with flow.decoded(request):
request.content = "bar"
Diffstat (limited to 'test')
-rw-r--r-- | test/test_flow.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test/test_flow.py b/test/test_flow.py index b6818960..56303881 100644 --- a/test/test_flow.py +++ b/test/test_flow.py @@ -996,6 +996,29 @@ class uODictCaseless(libpry.AutoTree): assert len(self.od) == 1 +class udecoded(libpry.AutoTree): + def test_del(self): + r = tutils.treq() + assert r.content == "content" + assert not r.headers["content-encoding"] + r.encode("gzip") + assert r.headers["content-encoding"] + assert r.content != "content" + with flow.decoded(r): + assert not r.headers["content-encoding"] + assert r.content == "content" + assert r.headers["content-encoding"] + assert r.content != "content" + + with flow.decoded(r): + r.content = "foo" + + assert r.content != "foo" + r.decode() + assert r.content == "foo" + + + tests = [ uStickyCookieState(), @@ -1012,4 +1035,5 @@ tests = [ uClientConnect(), uODict(), uODictCaseless(), + udecoded() ] |