import libpry
import libmproxy.console.contentview as cv
from libmproxy import utils, flow, encoding
class uContentView(libpry.AutoTree):
def test_trailer(self):
txt = []
cv.trailer(5, txt)
assert not txt
cv.trailer(cv.VIEW_CUTOFF + 10, txt)
assert txt
def test_get_view_func(self):
f = cv.get_view_func(
cv.VIEW_HEX,
flow.ODictCaseless(),
"foo"
)
assert f is cv.view_hex
f = cv.get_view_func(
cv.VIEW_AUTO,
flow.ODictCaseless(),
"foo"
)
assert f is cv.view_raw
f = cv.get_view_func(
cv.VIEW_AUTO,
flow.ODictCaseless(
[["content-type", "text/html"]],
),
"foo"
)
assert f is cv.view_html
f = cv.get_view_func(
cv.VIEW_AUTO,
flow.ODictCaseless(
[["content-type", "text/flibble"]],
),
"foo"
)
assert f is cv.view_raw
f = cv.get_view_func(
cv.VIEW_AUTO,
flow.ODictCaseless(
[["content-type", "text/flibble"]],
),
"
one
" assert cv.view_html([], s) s = "gobbledygook" assert not cv.view_html([], s) def test_view_json(self): cv.VIEW_CUTOFF = 100 assert cv.view_json([], "{}") assert not cv.view_urlencoded([], "{") assert cv.view_json([], "[" + ",".join(["0"]*cv.VIEW_CUTOFF) + "]") def test_view_xml(self): assert cv.view_xml([], "