Exemple #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]
Exemple #2
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
Exemple #3
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
Exemple #4
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)
Exemple #5
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
Exemple #6
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
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 done():
    contentviews.remove(view)
def done():
    contentviews.remove(view)
def done():
    contentviews.remove(pig_view)
Exemple #11
0
def done():
    contentviews.remove(pig_view)
Exemple #12
0
 def remove_contentview(self, view_obj):
     contentviews.remove(view_obj)
Exemple #13
0
 def remove_contentview(self, view_obj):
     contentviews.remove(view_obj)