mirror of
https://github.com/zhigang1992/mitmproxy.git
synced 2026-04-27 19:15:33 +08:00
Added tests for replace in request,message,header
This commit is contained in:
@@ -75,6 +75,10 @@ class TestHeaders(object):
|
||||
assert replacements == 0
|
||||
assert headers["Host"] == "example.com"
|
||||
|
||||
def test_replace_with_count(self):
|
||||
headers = Headers(Host="foobarfoo.com", Accept="foo/bar")
|
||||
replacements = headers.replace("foo","bar",count=1)
|
||||
assert replacements == 1
|
||||
|
||||
def test_parse_content_type():
|
||||
p = parse_content_type
|
||||
|
||||
@@ -99,6 +99,15 @@ class TestMessage(object):
|
||||
def test_http_version(self):
|
||||
_test_decoded_attr(tresp(), "http_version")
|
||||
|
||||
def test_replace(self):
|
||||
r = tresp()
|
||||
r.content = b"foofootoo"
|
||||
r.replace(b"foo","gg")
|
||||
assert r.content == b"ggggtoo"
|
||||
|
||||
r.content = b"foofootoo"
|
||||
r.replace(b"foo","gg",count=1)
|
||||
assert r.content == b"ggfootoo"
|
||||
|
||||
class TestMessageContentEncoding(object):
|
||||
def test_simple(self):
|
||||
|
||||
@@ -26,6 +26,16 @@ class TestRequestCore(object):
|
||||
request.host = None
|
||||
assert repr(request) == "Request(GET /path)"
|
||||
|
||||
def replace(self):
|
||||
r = treq()
|
||||
r.path = b"foobarfoo"
|
||||
r.replace(b"foo","bar")
|
||||
assert r.path == b"barbarbar"
|
||||
|
||||
r.path = b"foobarfoo"
|
||||
r.replace(b"foo","bar",count=1)
|
||||
assert r.path == b"barbarfoo"
|
||||
|
||||
def test_first_line_format(self):
|
||||
_test_passthrough_attr(treq(), "first_line_format")
|
||||
|
||||
@@ -87,7 +97,6 @@ class TestRequestCore(object):
|
||||
request.host = "example.org"
|
||||
assert request.headers["Host"] == "example.org"
|
||||
|
||||
|
||||
class TestRequestUtils(object):
|
||||
"""
|
||||
Tests for additional convenience methods.
|
||||
|
||||
Reference in New Issue
Block a user