mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
Move har_extractor tests to the examples file
This commit is contained in:
parent
7c5791e51a
commit
35204ecb1c
@ -1,4 +1,5 @@
|
|||||||
import glob
|
import glob
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
|
||||||
@ -114,3 +115,26 @@ def test_redirect_requests():
|
|||||||
with example("redirect_requests.py") as ex:
|
with example("redirect_requests.py") as ex:
|
||||||
ex.run("request", flow)
|
ex.run("request", flow)
|
||||||
assert flow.request.host == "mitmproxy.org"
|
assert flow.request.host == "mitmproxy.org"
|
||||||
|
|
||||||
|
|
||||||
|
def test_har_extractor():
|
||||||
|
with tutils.raises(script.ScriptException):
|
||||||
|
with example("har_extractor.py") as ex:
|
||||||
|
pass
|
||||||
|
|
||||||
|
times = dict(
|
||||||
|
timestamp_start=746203272,
|
||||||
|
timestamp_end=746203272,
|
||||||
|
)
|
||||||
|
|
||||||
|
flow = tutils.tflow(
|
||||||
|
req=netutils.treq(**times),
|
||||||
|
resp=netutils.tresp(**times)
|
||||||
|
)
|
||||||
|
|
||||||
|
with example("har_extractor.py -") as ex:
|
||||||
|
ex.run("response", flow)
|
||||||
|
|
||||||
|
with open(tutils.test_data.path("data/har_extractor.har")) as fp:
|
||||||
|
test_data = json.load(fp)
|
||||||
|
assert json.loads(ex.ctx.HARLog.json()) == test_data["test_response"]
|
||||||
|
@ -1,37 +0,0 @@
|
|||||||
import json
|
|
||||||
import netlib.tutils
|
|
||||||
from . import tutils
|
|
||||||
|
|
||||||
from examples import har_extractor
|
|
||||||
|
|
||||||
|
|
||||||
class Context(object):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
trequest = netlib.tutils.treq(
|
|
||||||
timestamp_start=746203272,
|
|
||||||
timestamp_end=746203272,
|
|
||||||
)
|
|
||||||
|
|
||||||
tresponse = netlib.tutils.tresp(
|
|
||||||
timestamp_start=746203272,
|
|
||||||
timestamp_end=746203272,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_start():
|
|
||||||
tutils.raises(ValueError, har_extractor.start, Context(), [])
|
|
||||||
|
|
||||||
|
|
||||||
def test_response():
|
|
||||||
ctx = Context()
|
|
||||||
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"]
|
|
Loading…
Reference in New Issue
Block a user