Ejemplo 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)]
Ejemplo 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)]