Exemplo n.º 1
0
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]
Exemplo n.º 2
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)
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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
Exemplo n.º 5
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
        )
Exemplo n.º 6
0
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]
Exemplo n.º 7
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)
Exemplo n.º 8
0
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
Exemplo n.º 9
0
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
Exemplo n.º 10
0
def start():
    contentviews.add(pig_view)
Exemplo n.º 11
0
def load(l):
    contentviews.add(view)
Exemplo n.º 12
0
def load(l):
    contentviews.add(view)
Exemplo n.º 13
0
def start():
    contentviews.add(view)
Exemplo n.º 14
0
def start(opts):
    contentviews.add(view)
Exemplo n.º 15
0
 def add_contentview(self, view_obj):
     contentviews.add(view_obj)
Exemplo n.º 16
0
def start():
    contentviews.add(view)
Exemplo n.º 17
0
def start():
    contentviews.add(pig_view)
Exemplo n.º 18
0
 def add_contentview(self, view_obj):
     contentviews.add(view_obj)