Beef up unit tests for HAR utility functions - flow.py coverage now 100%.
This commit is contained in:
parent
6f157d936f
commit
53792a5a28
|
@ -892,6 +892,22 @@ class TestRequest:
|
|||
assert not r.headers["content-encoding"]
|
||||
assert r.content == "falafel"
|
||||
|
||||
def test_get_decoded_content(self):
|
||||
r = tutils.treq()
|
||||
r.content = None
|
||||
r.headers["content-encoding"] = ["identity"]
|
||||
assert r.get_decoded_content() == None
|
||||
|
||||
r.content = "falafel"
|
||||
r.encode("gzip")
|
||||
assert r.get_decoded_content() == "falafel"
|
||||
|
||||
def test_get_cookies_none(self):
|
||||
h = flow.ODictCaseless()
|
||||
c = flow.ClientConnect(("addr", 2222))
|
||||
r = flow.Request(c, (1, 1), "host", 22, "https", "GET", "/", h, "content")
|
||||
assert r.get_cookies() == None
|
||||
|
||||
def test_get_cookies_single(self):
|
||||
h = flow.ODictCaseless()
|
||||
h["Cookie"] = ["cookiename=cookievalue"]
|
||||
|
@ -936,6 +952,8 @@ class TestRequest:
|
|||
r = flow.Request(c, (1, 1), "host", 22, "https", "GET", "/", h, "content")
|
||||
result = r.get_transmitted_size()
|
||||
assert result==len("content")
|
||||
r.content = None
|
||||
assert r.get_transmitted_size() == 0
|
||||
|
||||
def test_get_content_type(self):
|
||||
h = flow.ODictCaseless()
|
||||
|
@ -1045,12 +1063,10 @@ class TestResponse:
|
|||
result = r.get_header_size()
|
||||
assert result==49
|
||||
|
||||
def test_get_transmitted_size(self):
|
||||
r = tutils.tresp()
|
||||
r.headers["content-encoding"] = ["identity"]
|
||||
r.content = "falafel"
|
||||
result = r.get_transmitted_size()
|
||||
assert result==len("falafel")
|
||||
def test_get_cookies_none(self):
|
||||
h = flow.ODictCaseless()
|
||||
resp = flow.Response(None, (1, 1), 200, "OK", h, "content", None)
|
||||
assert not resp.get_cookies()
|
||||
|
||||
def test_get_cookies_simple(self):
|
||||
h = flow.ODictCaseless()
|
||||
|
|
|
@ -98,28 +98,26 @@ class TestProxy(tutils.HTTPProxTest):
|
|||
def test_response_timestamps(self):
|
||||
# test that we notice at least 2 sec delay between timestamps
|
||||
# in response object
|
||||
f = self.pathod("304:b@1k:p50,2")
|
||||
f = self.pathod("304:b@1k:p50,1")
|
||||
assert f.status_code == 304
|
||||
|
||||
response = self.master.state.view[0].response
|
||||
assert 2 <= response.timestamp_end - response.timestamp_start <= 2.2
|
||||
assert 1 <= response.timestamp_end - response.timestamp_start <= 1.2
|
||||
|
||||
def test_request_timestamps(self):
|
||||
# test that we notice at least 2 sec delay between timestamps
|
||||
# in request object
|
||||
# test that we notice a delay between timestamps in request object
|
||||
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
connection.connect(("127.0.0.1", self.proxy.port))
|
||||
|
||||
# call pathod server, wait a second to complete the request
|
||||
connection.send("GET http://localhost:%d/p/304:b@1k HTTP/1.1\r\n"%self.server.port)
|
||||
time.sleep(0.1)
|
||||
connection.send("\r\n");
|
||||
connection.recv(50000)
|
||||
connection.close()
|
||||
|
||||
request, response = self.master.state.view[0].request, self.master.state.view[0].response
|
||||
assert response.code == 304 # sanity test for our low level request
|
||||
assert 0 <= request.timestamp_end - request.timestamp_start <= 0.2
|
||||
assert request.timestamp_end - request.timestamp_start > 0
|
||||
|
||||
def test_request_timestamps_not_affected_by_client_time(self):
|
||||
# test that don't include user wait time in request's timestamps
|
||||
|
|
Loading…
Reference in New Issue