コード例 #1
0
def test_link_add_single():
    """Ensure that we can add a single link to the database."""

    db = Database(":memory:", create=True, verbose=True)

    Link.add(db, name="Github", url="https://www.github.com/")
    assert Link.get(db, 1) == Link(id=1, name="Github", url="https://www.github.com/")
コード例 #2
0
def test_link_add_default_visits():
    """Ensure that the visits field on a link is initialised to a sane value."""

    db = Database(":memory:", create=True, verbose=True)
    Link.add(db, name="Github", url="https://github.com/")

    link = Link.get(db, 1)
    assert link.visits == 0
コード例 #3
0
def test_link_open_updates_stats():
    """Ensure that when we visit a link, its stats are updated."""

    db = Database(":memory:", create=True, verbose=True)
    Link.add(db, name="Github", url="https://www.github.com", visits=1)

    with mock.patch("llyfrau.data.webbrowser") as m_webbrowser:
        Link.open(db, 1)

    m_webbrowser.open.assert_called_with("https://www.github.com")

    link = Link.get(db, 1)
    assert link.visits == 2
コード例 #4
0
def test_add_link(workdir):
    """Ensure that we can add a link to the database"""

    filepath = pathlib.Path(workdir.name, "links.db")
    add_link(str(filepath),
             url="https://www.github.com",
             name="Github",
             tags=None)

    db = Database(str(filepath), create=False)
    assert Link.get(db, 1) == Link(id=1,
                                   name="Github",
                                   url="https://www.github.com")
コード例 #5
0
def test_link_source_reference():
    """Ensure that a link can reference to source it was added by"""

    db = Database(":memory:", create=True, verbose=True)
    Source.add(
        db,
        name="Numpy",
        prefix="https://docs.scipy.org/doc/numpy/",
        uri="sphinx://https://docs.scipy.org/doc/numpy/",
    )

    Link.add(db, name="Reference Guide", url="reference/", source_id=1)

    link = Link.get(db, 1)
    assert link.source_id == 1

    source = Source.get(db, 1)
    assert source.links == [link]
    assert link.source == source
コード例 #6
0
def test_tag_link():
    """Ensure that it is possible to associate a tag with a link."""

    db = Database(":memory:", create=True, verbose=True)
    session = db.session

    tag = Tag(name="search-engine")
    link = Link(name="Google", url="https://www.google.com/")

    link.tags.append(tag)

    session.add(tag)
    session.add(link)
    db.commit()

    tag.id = 1
    link = Link.get(db, 1)

    assert link.tags[0] == tag
    assert tag.links[0] == link