Increase contentviews api coverage

This commit is contained in:
Ujjwal Verma 2017-05-17 11:04:43 +05:30
parent ca46b1e340
commit 8eea05fcaf
1 changed files with 11 additions and 4 deletions

View File

@ -9,23 +9,28 @@ from mitmproxy.test import tutils
class TestContentView(contentviews.View): class TestContentView(contentviews.View):
name = "test" name = "test"
prompt = ("t", "test") prompt = ("test", "t")
content_types = ["test/123"] content_types = ["test/123"]
def test_add_remove(): def test_add_remove():
tcv = TestContentView() tcv = TestContentView()
contentviews.add(tcv) contentviews.add(tcv)
assert tcv in contentviews.views
# repeated addition causes exception # repeated addition causes exception
with pytest.raises(ContentViewException): with pytest.raises(ContentViewException, match="Duplicate view"):
contentviews.add(tcv) contentviews.add(tcv)
tcv2 = TestContentView()
tcv2.name = "test2"
tcv2.prompt = ("test2", "t")
# Same shortcut doesn't work either. # Same shortcut doesn't work either.
with pytest.raises(ContentViewException): with pytest.raises(ContentViewException, match="Duplicate view shortcut"):
contentviews.add(TestContentView()) contentviews.add(tcv2)
contentviews.remove(tcv) contentviews.remove(tcv)
assert tcv not in contentviews.views
def test_get_content_view(): def test_get_content_view():
@ -43,6 +48,7 @@ def test_get_content_view():
headers=Headers(content_type="application/json") headers=Headers(content_type="application/json")
) )
assert desc == "JSON" assert desc == "JSON"
assert list(lines)
desc, lines, err = contentviews.get_content_view( desc, lines, err = contentviews.get_content_view(
contentviews.get("JSON"), contentviews.get("JSON"),
@ -84,3 +90,4 @@ def test_get_message_content_view():
def test_get_by_shortcut(): def test_get_by_shortcut():
assert contentviews.get_by_shortcut("s") assert contentviews.get_by_shortcut("s")
assert not contentviews.get_by_shortcut("b")