sidebar: Commit the database after creating a new playlist
Otherwise we could have data loss if the application crashes. Fixes: #63 ("The database isn't being committed enough") Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
01a37dbbc1
commit
cae93cae11
|
@ -59,6 +59,7 @@ class Section(section.Section):
|
|||
|
||||
def __add_new_playlist(self, entry: Gtk.Entry) -> None:
|
||||
if self.table.create(entry.get_text()) is not None:
|
||||
self.table.sql.commit()
|
||||
self.extra_widget.popdown()
|
||||
|
||||
def __entry_changed(self, entry: Gtk.Entry) -> None:
|
||||
|
|
|
@ -68,23 +68,28 @@ class TestPlaylists(tests.util.TestCase):
|
|||
|
||||
with unittest.mock.patch.object(self.playlists.extra_widget,
|
||||
"popdown") as mock_popdown:
|
||||
self.playlists._entry.emit("activate")
|
||||
self.assertEqual(len(self.sql.playlists), 0)
|
||||
mock_popdown.assert_not_called()
|
||||
with unittest.mock.patch.object(self.sql, "commit") as mock_commit:
|
||||
self.playlists._entry.emit("activate")
|
||||
self.assertEqual(len(self.sql.playlists), 0)
|
||||
mock_popdown.assert_not_called()
|
||||
mock_commit.assert_not_called()
|
||||
|
||||
self.playlists._entry.set_text("Test 1")
|
||||
self.playlists._entry.emit("activate")
|
||||
self.assertEqual(len(self.sql.playlists), 1)
|
||||
self.assertEqual(self.sql.playlists.get_item(0).name, "Test 1")
|
||||
mock_popdown.assert_called()
|
||||
self.playlists._entry.set_text("Test 1")
|
||||
self.playlists._entry.emit("activate")
|
||||
self.assertEqual(len(self.sql.playlists), 1)
|
||||
self.assertEqual(self.sql.playlists.get_item(0).name, "Test 1")
|
||||
mock_popdown.assert_called()
|
||||
mock_commit.assert_called()
|
||||
|
||||
mock_popdown.reset_mock()
|
||||
self.playlists._entry.set_text("Test 2")
|
||||
self.playlists._entry.emit("icon-release",
|
||||
Gtk.EntryIconPosition.PRIMARY)
|
||||
self.assertEqual(len(self.sql.playlists), 2)
|
||||
self.assertEqual(self.sql.playlists.get_item(1).name, "Test 2")
|
||||
mock_popdown.assert_called()
|
||||
mock_popdown.reset_mock()
|
||||
mock_commit.reset_mock()
|
||||
self.playlists._entry.set_text("Test 2")
|
||||
self.playlists._entry.emit("icon-release",
|
||||
Gtk.EntryIconPosition.PRIMARY)
|
||||
self.assertEqual(len(self.sql.playlists), 2)
|
||||
self.assertEqual(self.sql.playlists.get_item(1).name, "Test 2")
|
||||
mock_popdown.assert_called()
|
||||
mock_commit.assert_called()
|
||||
|
||||
self.playlists._entry.set_text("Test 3")
|
||||
self.assertEqual(self.playlists._entry.get_icon_name(
|
||||
|
|
Loading…
Reference in New Issue