Esempio n. 1
0
def test_single_history():
    doc = Document('http://example.com', 'Example')
    history = History([doc])
    assert history.is_at_most_recent
    assert history.is_at_oldest
    assert history.current == doc
    assert list(history.get_items()) == [(True, doc)]
    assert load_history(dump_history(history)) == history

    with pytest.raises(ValueError):
        history.back()
    with pytest.raises(ValueError):
        history.forward()

    # Adding same document does not change history.
    new_doc = Document('http://example.com', 'Example')
    new_history = history.add(new_doc)
    assert list(new_history.get_items()) == [(True, doc)]

    # Adding same URL, different title changes existing item.
    new_doc = Document('http://example.com', 'New')
    new_history = history.add(new_doc)
    assert list(new_history.get_items()) == [(True, new_doc)]

    # Adding different document changes history.
    new_doc = Document('http://other.com', 'Example')
    new_history = history.add(new_doc)
    assert list(new_history.get_items()) == [(True, new_doc), (False, doc)]
Esempio n. 2
0
def test_empty_history():
    history = History()
    assert history.is_at_most_recent
    assert history.is_at_oldest
    assert history.current is None
    assert list(history.get_items()) == []
    assert load_history(dump_history(history)) == history

    with pytest.raises(ValueError):
        history.back()
    with pytest.raises(ValueError):
        history.forward()

    # Adding new document changes history.
    new_doc = Document('http://example.com', 'Example')
    new_history = history.add(new_doc)
    assert list(new_history.get_items()) == [(True, new_doc)]
Esempio n. 3
0
def test_navigating_forward():
    first = Document('http://first.com', 'First')
    second = Document('http://second.com', 'Second')
    history = History([second, first], idx=1)
    assert not history.is_at_most_recent
    assert history.is_at_oldest
    assert history.current == first
    assert list(history.get_items()) == [(False, second), (True, first)]

    doc, history = history.forward()
    assert doc == second
    assert list(history.get_items()) == [(True, second), (False, first)]