Added tests for replace in request,message,header

This commit is contained in:
arjun23496
2016-08-31 10:23:33 +05:30
parent b3f0596652
commit d2cfa5ca41
4 changed files with 25 additions and 1 deletions

View File

@@ -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

View File

@@ -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):

View File

@@ -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.