def test_custom_views(): class ViewNoop(cv.View): name = "noop" prompt = ("noop", "n") content_types = ["text/none"] def __call__(self, data, **metadata): return "noop", cv.format_text(data) view_obj = ViewNoop() cv.add(view_obj) assert cv.get("noop") r = cv.get_content_view(cv.get("noop"), "[1, 2, 3]", headers=Headers(content_type="text/plain")) assert "noop" in r[0] # now try content-type matching r = cv.get_content_view(cv.get("Auto"), "[1, 2, 3]", headers=Headers(content_type="text/none")) assert "noop" in r[0] # now try removing the custom view cv.remove(view_obj) r = cv.get_content_view(cv.get("Auto"), b"[1, 2, 3]", headers=Headers(content_type="text/none")) assert "noop" not in r[0]
def test_add_cv(self): class TestContentView(cv.View): name = "test" prompt = ("t", "test") tcv = TestContentView() cv.add(tcv) # repeated addition causes exception tutils.raises(ContentViewException, cv.add, tcv)
def test_add_remove(): tcv = TestContentView() contentviews.add(tcv) assert tcv in contentviews.views # repeated addition causes exception with pytest.raises(ValueError, match="Duplicate view"): contentviews.add(tcv) contentviews.remove(tcv) assert tcv not in contentviews.views
def test_add_remove(): tcv = TestContentView() contentviews.add(tcv) assert tcv in contentviews.views # repeated addition causes exception with pytest.raises(ContentViewException, match="Duplicate view"): contentviews.add(tcv) contentviews.remove(tcv) assert tcv not in contentviews.views
def test_add_cv(self): class TestContentView(cv.View): name = "test" prompt = ("t", "test") tcv = TestContentView() cv.add(tcv) # repeated addition causes exception tutils.raises( ContentViewException, cv.add, tcv )
def test_custom_views(): class ViewNoop(cv.View): name = "noop" prompt = ("noop", "n") content_types = ["text/none"] def __call__(self, data, **metadata): return "noop", cv.format_text(data) view_obj = ViewNoop() cv.add(view_obj) assert cv.get("noop") r = cv.get_content_view( cv.get("noop"), "[1, 2, 3]", headers=Headers( content_type="text/plain" ) ) assert "noop" in r[0] # now try content-type matching r = cv.get_content_view( cv.get("Auto"), "[1, 2, 3]", headers=Headers( content_type="text/none" ) ) assert "noop" in r[0] # now try removing the custom view cv.remove(view_obj) r = cv.get_content_view( cv.get("Auto"), b"[1, 2, 3]", headers=Headers( content_type="text/none" ) ) assert "noop" not in r[0]
def test_add_remove(): tcv = TestContentView() contentviews.add(tcv) # repeated addition causes exception with tutils.raises(ContentViewException): contentviews.add(tcv) # Same shortcut doesn't work either. with tutils.raises(ContentViewException): contentviews.add(TestContentView()) contentviews.remove(tcv)
def test_add_remove(): tcv = TestContentView() contentviews.add(tcv) assert tcv in contentviews.views # repeated addition causes exception with pytest.raises(ContentViewException, match="Duplicate view"): contentviews.add(tcv) tcv2 = TestContentView() tcv2.name = "test2" tcv2.prompt = ("test2", "t") # Same shortcut doesn't work either. with pytest.raises(ContentViewException, match="Duplicate view shortcut"): contentviews.add(tcv2) contentviews.remove(tcv) assert tcv not in contentviews.views
def start(): contentviews.add(pig_view)
def load(l): contentviews.add(view)
def start(): contentviews.add(view)
def start(opts): contentviews.add(view)
def add_contentview(self, view_obj): contentviews.add(view_obj)