def test_notes_displaying(self): """Acceptance: Action "display" prints the content given note names.""" list_of_notes = test_data.full_list_of_notes(self.m) todo = list_of_notes[1] python_work = list_of_notes[4] separator = os.linesep + "==========================" + os.linesep note_lines = test_data.note_contents_from_dbus["TODO-list"].splitlines() note_lines[0] = "%s (system:notebook:reminders, system:notebook:pim)" % (note_lines[0],) expected_result_list = [os.linesep.join(note_lines), test_data.note_contents_from_dbus["python-work"]] self.mock_out_get_notes_by_names([todo, python_work]) self.dbus_interface.GetNoteContents(todo.uri).AndReturn(test_data.note_contents_from_dbus["TODO-list"]) self.dbus_interface.GetNoteContents(python_work.uri).AndReturn(test_data.note_contents_from_dbus["python-work"]) self.m.ReplayAll() sys.argv = ["unused_prog_name", "display", "TODO-list", "python-work"] tomtom_cli = cli.CommandLine() tomtom_cli.main() self.m.VerifyAll() self.assertEquals(separator.join(expected_result_list) + os.linesep, sys.stdout.getvalue())
def test_filter_notes_by_books(self): """Acceptance: Using "-b" limits the notes by notebooks.""" list_of_notes = test_data.full_list_of_notes(self.m) self.mock_out_listing(list_of_notes) self.m.ReplayAll() sys.argv = ["app_name", "list", "-b", "pim", "-b", "reminders"] tomtom_cli = cli.CommandLine() tomtom_cli.main() self.m.VerifyAll() self.assertEqual(test_data.book_limited_list + os.linesep, sys.stdout.getvalue())
def test_action_list(self): """Acceptance: Action "list -n" prints a list of the last n notes.""" list_of_notes = test_data.full_list_of_notes(self.m) self.mock_out_listing(list_of_notes[:10]) self.m.ReplayAll() sys.argv = ["unused_prog_name", "list", "-n", "10"] tomtom_cli = cli.CommandLine() tomtom_cli.main() self.m.VerifyAll() self.assertEquals(test_data.expected_list + os.linesep, sys.stdout.getvalue())
def test_full_list(self): """Acceptance: Action "list" alone produces a list of all notes.""" list_of_notes = test_data.full_list_of_notes(self.m) self.mock_out_listing(list_of_notes) self.m.ReplayAll() sys.argv = ["unused_prog_name", "list"] tomtom_cli = cli.CommandLine() tomtom_cli.main() self.m.VerifyAll() self.assertEquals( os.linesep.join([test_data.expected_list, test_data.list_appendix]) + os.linesep, sys.stdout.getvalue() )
def test_search(self): """Acceptance: Action "search" searches in all notes, case-indep.""" list_of_notes = test_data.full_list_of_notes(self.m) self.mock_out_listing(list_of_notes) # Forget about the last note (a template) for note in list_of_notes[:-1]: self.dbus_interface.GetNoteContents(note.uri).AndReturn(test_data.note_contents_from_dbus[note.title]) self.m.ReplayAll() sys.argv = ["unused_prog_name", "search", "john doe"] tomtom_cli = cli.CommandLine() tomtom_cli.main() self.m.VerifyAll() self.assertEquals(test_data.search_results + os.linesep, sys.stdout.getvalue())
def test_list_using_gnote(self): """Acceptance: Specifying --gnote connects to Gnote.""" # Reset stubs and mocks. We need to mock out dbus differently. self.remove_mocks() self.mock_out_dbus("Gnote") list_of_notes = test_data.full_list_of_notes(self.m) self.mock_out_listing(list_of_notes[:10]) self.m.ReplayAll() sys.argv = ["unused_prog_name", "list", "-n", "10", "--gnote"] tomtom_cli = cli.CommandLine() tomtom_cli.main() self.m.VerifyAll() self.assertEquals(test_data.expected_list + os.linesep, sys.stdout.getvalue())
def test_search_specific_notes(self): """Acceptance: Action "search" restricts the search to given notes.""" list_of_notes = test_data.full_list_of_notes(self.m) requested_notes = [list_of_notes[3], list_of_notes[4], list_of_notes[6]] self.mock_out_get_notes_by_names(requested_notes) for note in requested_notes: self.dbus_interface.GetNoteContents(note.uri).AndReturn(test_data.note_contents_from_dbus[note.title]) self.m.ReplayAll() sys.argv = ["unused_prog_name", "search", "python"] + [n.title for n in requested_notes] tomtom_cli = cli.CommandLine() tomtom_cli.main() self.m.VerifyAll() self.assertEquals(test_data.specific_search_results + os.linesep, sys.stdout.getvalue())
def test_filter_notes_with_templates(self): """Acceptance: Using "--with-templates" lists notes and templates.""" list_of_notes = test_data.full_list_of_notes(self.m) self.mock_out_listing(list_of_notes) self.m.ReplayAll() sys.argv = ["app_name", "list", "--with-templates"] tomtom_cli = cli.CommandLine() tomtom_cli.main() self.m.VerifyAll() self.assertEqual( test_data.expected_list + os.linesep + test_data.list_appendix + os.linesep + test_data.normally_hidden_template + os.linesep, sys.stdout.getvalue(), )