From 82a90511bc61b4ed98cd7ff2455b79dec015c45f Mon Sep 17 00:00:00 2001 From: Chris Czub Date: Mon, 9 Nov 2015 11:06:16 -0500 Subject: [PATCH] Add "add" ContentView method & test --- libmproxy/contentviews.py | 8 ++++++++ test/test_contentview.py | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/libmproxy/contentviews.py b/libmproxy/contentviews.py index 9af080335..8d5aadfce 100644 --- a/libmproxy/contentviews.py +++ b/libmproxy/contentviews.py @@ -515,6 +515,14 @@ def get_by_shortcut(c): return i +def add(obj): + for i in views: + if i.name == obj.name: + raise ContentViewException("Duplicate view: " + obj.name) + + views.append(obj) + + def get(name): for i in views: if i.name == name: diff --git a/test/test_contentview.py b/test/test_contentview.py index 976085209..68272fca3 100644 --- a/test/test_contentview.py +++ b/test/test_contentview.py @@ -210,6 +210,19 @@ Larry assert "decoded gzip" in r[0] assert "Raw" in r[0] + def test_add_cv(self): + class TestContentView(cv.View): + name = "test" + + tcv = TestContentView() + cv.add(tcv) + + tutils.raises( + ContentViewException, + cv.add, + tcv + ) + if pyamf: def test_view_amf_request():