예제 #1
0
def test_focus():
    # Special case - initialising with a view that already contains data
    v = view.View()
    v.add(tft())
    f = view.Focus(v)
    assert f.index is 0
    assert f.flow is v[0]

    # Start empty
    v = view.View()
    f = view.Focus(v)
    assert f.index is None
    assert f.flow is None

    v.add(tft(start=1))
    assert f.index == 0
    assert f.flow is v[0]

    v.add(tft(start=0))
    assert f.index == 1
    assert f.flow is v[1]

    v.add(tft(start=2))
    assert f.index == 1
    assert f.flow is v[1]

    v.remove(v[1])
    assert f.index == 1
    assert f.flow is v[1]

    v.remove(v[1])
    assert f.index == 0
    assert f.flow is v[0]

    v.remove(v[0])
    assert f.index is None
    assert f.flow is None

    v.add(tft(method="get", start=0))
    v.add(tft(method="get", start=1))
    v.add(tft(method="put", start=2))
    v.add(tft(method="get", start=3))

    f.flow = v[2]
    assert f.flow.request.method == "PUT"

    filt = flowfilter.parse("~m get")
    v.set_filter(filt)
    assert f.index == 2

    filt = flowfilter.parse("~m oink")
    v.set_filter(filt)
    assert f.index is None
예제 #2
0
def test_focus():
    # Special case - initialising with a view that already contains data
    v = view.View()
    v.add([tft()])
    f = view.Focus(v)
    assert f.index is 0
    assert f.flow is v[0]

    # Start empty
    v = view.View()
    f = view.Focus(v)
    assert f.index is None
    assert f.flow is None

    v.add([tft(start=1)])
    assert f.index == 0
    assert f.flow is v[0]

    # Try to set to something not in view
    with pytest.raises(ValueError):
        f.__setattr__("flow", tft())
    with pytest.raises(ValueError):
        f.__setattr__("index", 99)

    v.add([tft(start=0)])
    assert f.index == 1
    assert f.flow is v[1]

    v.add([tft(start=2)])
    assert f.index == 1
    assert f.flow is v[1]

    f.index = 0
    assert f.index == 0
    f.index = 1

    v.remove([v[1]])
    v[1].intercept()
    assert f.index == 1
    assert f.flow is v[1]

    v.remove([v[1]])
    assert f.index == 0
    assert f.flow is v[0]

    v.remove([v[0]])
    assert f.index is None
    assert f.flow is None

    v.add([
        tft(method="get", start=0),
        tft(method="get", start=1),
        tft(method="put", start=2),
        tft(method="get", start=3),
    ])

    f.flow = v[2]
    assert f.flow.request.method == "PUT"

    filt = flowfilter.parse("~m get")
    v.set_filter(filt)
    assert f.index == 2

    filt = flowfilter.parse("~m oink")
    v.set_filter(filt)
    assert f.index is None