def open_link(event): cursor = self.selection.content.text idx = len(cursor) selected = self.ids.col.text[idx - 1] link_id = int(selected[1]) Link.open(self.db, link_id)
def test_link_open(): """Ensure that we can open a link in the database""" db = Database(":memory:", create=True, verbose=True) Link.add(db, name="Github", url="https://www.github.com") with mock.patch("llyfrau.data.webbrowser") as m_webbrowser: Link.open(db, 1) m_webbrowser.open.assert_called_with("https://www.github.com")
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
def test_link_open_with_prefix(): """Ensure that we can open a link that has a prefix on its source""" 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) with mock.patch("llyfrau.data.webbrowser") as m_webbrowser: Link.open(db, 1) m_webbrowser.open.assert_called_with("https://docs.scipy.org/doc/numpy/reference/")