mitmproxy/test/mitmproxy/test_har_extractor.py

38 lines
784 B
Python
Raw Normal View History

2016-03-03 21:40:29 +00:00
import json
import netlib.tutils
2016-03-03 21:02:01 +00:00
from . import tutils
from examples import har_extractor
2016-03-03 21:43:40 +00:00
class Context(object):
pass
2016-03-03 21:40:29 +00:00
trequest = netlib.tutils.treq(
timestamp_start=746203272,
timestamp_end=746203272,
)
tresponse = netlib.tutils.tresp(
timestamp_start=746203272,
timestamp_end=746203272,
)
2016-03-03 21:02:01 +00:00
def test_start():
2016-03-03 21:43:40 +00:00
tutils.raises(ValueError, har_extractor.start, Context(), [])
2016-03-03 21:40:29 +00:00
def test_response():
2016-03-03 21:43:40 +00:00
ctx = Context()
2016-03-03 21:40:29 +00:00
ctx.HARLog = har_extractor._HARLog([])
ctx.seen_server = set()
fl = tutils.tflow(req=trequest, resp=tresponse)
har_extractor.response(ctx, fl)
with open(tutils.test_data.path("data/har_extractor.har")) as fp:
test_data = json.load(fp)
assert json.loads(ctx.HARLog.json()) == test_data["test_response"]