class GetAllNotesTest(TestCase): def setUp(self): self.database = Database("Test") def test_get_all_notes(self): # given title1 = "Title" content1 = "Content" title2 = "Title2" content2 = "Content2" self.database.create_note(title1, content1) self.database.create_note(title2, content2) # when result = self.database.get_all_notes() # then self.assertTrue(len(result) == 2) self.assertTrue(result[0].title_and_content_equals(title1, content1)) self.assertTrue(result[1].title_and_content_equals(title2, content2)) def test_with_empty_database(self): # given # when then with self.assertRaises(NoteNotFound): self.database.get_all_notes() def tearDown(self): self.database.close_connection()
class DeleteNoteTest(TestCase): def setUp(self): self.database = Database("Test") def test_delete_note(self): # given title = "Title" content = "Content" self.database.create_note(title, content) # when self.database.delete_note_by_id(1) # then with self.assertRaises(NoteNotFound): note = self.database.get_note_by_id(1) def test_cant_modify_deleted_note(self): # given title = "Title" content = "Content" self.database.create_note(title, content) # when self.database.delete_note_by_id(1) # then with self.assertRaises(NoteNotFound): note = self.database.get_raw_note_by_id(1) def tearDown(self): self.database.close_connection()
class VersionedNoteTest(TestCase): def setUp(self): self.database = Database("Test") def test_versioned_note(self): # given title = "Title" content = "Content" self.database.create_note(title, content) # when sleep(1) self.database.update_note_by_id(1, "Title2", "Modified") # then notes = self.database.get_versioned_note_by_id(1) self.assertEqual(notes[0].title, title) self.assertEqual(notes[1].title, "Title2") def test_count_number_of_versions(self): # given title = "Title" content = "Content" self.database.create_note(title, content) # when sleep(1) self.database.update_note_by_id(1, "Title2", "Modified") # then result = self.database.query_executor.execute( "Select count(*) from Note_version") self.assertEqual(result[0], 2) def tearDown(self): self.database.close_connection()
class UpdateNoteTest(TestCase): def setUp(self): self.database = Database("Test") def test_update_note(self): # given title = "Title" content = "Content" self.database.create_note(title, content) # when sleep(1) self.database.update_note_by_id(1, "Title2", "Modified") # then result = self.database.get_raw_note_by_id(1) self.assertEqual("Title2", result[0]) self.assertEqual("Modified", result[1]) self.assertNotEqual(result[2], result[3]) def test_update_one_note(self): # given title = "Title" content = "Content" title2 = "Title2" content2 = "Content2" self.database.create_note(title, content) self.database.create_note(title2, content2) # when sleep(1) self.database.update_note_by_id(1, "Title2", "Modified") # then result = self.database.get_raw_note_by_id(1) unchanged_note = self.database.get_note_by_id(2) self.assertEqual("Title2", result[0]) self.assertEqual("Modified", result[1]) self.assertNotEqual(result[2], result[3]) self.assertTrue( unchanged_note.title_and_content_equals(title2, content2)) def test_count_number_of_versions(self): # given title = "Title" content = "Content" self.database.create_note(title, content) # when sleep(1) self.database.update_note_by_id(1, "Title2", "Modified") # then result = self.database.query_executor.execute( "Select count(*) from Note_version") self.assertEqual(result[0], 2) def tearDown(self): self.database.close_connection()
class GetNoteByIdTest(TestCase): def setUp(self): self.database = Database("Test") def test_get_note_by_id(self): # given self.database.create_note("Title", "Content") # when note = self.database.get_note_by_id(1) # then self.assertEqual(note.title, "Title") self.assertEqual(note.content, "Content") def test_no_note_like_this(self): # given # when then with self.assertRaises(NoteNotFound): self.database.get_note_by_id(2) def tearDown(self): self.database.close_connection()
class CreateNoteTest(TestCase): def setUp(self): self.database = Database("Test") def test_create_note_and_check_quantity(self): # given title = "Title" content = "Content" # when self.database.create_note(title, content) result = self.database.query_executor.execute( 'Select count(*) from Notes') # then self.assertEqual(1, result[0]) def test_create_note_and_check_content(self): # given title = "Title" content = "content" version = 1 deleted = False # when self.database.create_note(title, content) result = self.database.query_executor.execute('Select * from Notes') # then self.assertEqual(title, result[0]) self.assertEqual(content, result[1]) self.assertEqual(version, result[4]) self.assertEqual(deleted, result[5]) def test_create_note_and_check_in_note_version(self): # given title = "Title" content = "content" # when self.database.create_note(title, content) result = self.database.query_executor.execute( 'Select * from Note_version') # then self.assertEqual(title, result[1]) self.assertEqual(content, result[2]) def tearDown(self): self.database.close_connection()