def test_update_then_list(self): cda = CommentDataAccess("test.ini") cda.load() c = Comment() c.set_id("id1") c.set_time(2015, 1, 1, 1) c.set_message("message0") c.set_user_id("user0") self.assertTrue(cda.update_comment(c)) clist = cda.list_all_comments() self.assertEqual(len(clist), 3) c = clist[0] self.assertEqual(c.get_id(), "id1") self.assertEqual(c.get_user_id(), "user0") self.assertEqual(c.get_message(), "message0") self.assertEqual(c.get_time(), datetime.datetime(2015, 1, 1, 1)) c = clist[1] self.assertEqual(c.get_id(), "id2") self.assertEqual(c.get_user_id(), "user2") self.assertEqual(c.get_message(), "message2") self.assertEqual(c.get_time(), datetime.datetime(2015, 6, 10, 12)) c = clist[2] self.assertEqual(c.get_id(), "id3") self.assertEqual(c.get_user_id(), "user3") self.assertEqual(c.get_message(), "message3") self.assertEqual(c.get_time(), datetime.datetime(2015, 6, 11, 12))
def test_delete_then_list(self): cda = CommentDataAccess("test.ini") cda.load() cda.delete_comment_by_id("id1") allCmt = cda.list_all_comments() self.assertEqual(len(allCmt), 2) self.assertEqual(allCmt[0].get_id(), "id2") self.assertEqual(allCmt[0].get_user_id(), "user2") self.assertEqual(allCmt[0].get_message(), "message2") self.assertEqual(allCmt[0].get_time_as_str(), "06/10/15 12:00:00") self.assertEqual(allCmt[1].get_id(), "id3") self.assertEqual(allCmt[1].get_user_id(), "user3") self.assertEqual(allCmt[1].get_message(), "message3") self.assertEqual(allCmt[1].get_time_as_str(), "06/11/15 12:00:00")
def test_add_then_list(self): cda = CommentDataAccess("test.ini") cda.load() c = Comment() c.set_id("id4") c.set_user_id("user4") c.set_message("message3") c.set_time(2015, 6, 12, 16) self.assertTrue(cda.add_comment(c)) allCmt = cda.list_all_comments() self.assertEqual(len(allCmt), 4) lastCmt = allCmt[3] self.assertFalse(lastCmt is c) self.assertEqual(lastCmt.get_id(), "id4") self.assertEqual(lastCmt.get_user_id(), "user4") self.assertEqual(lastCmt.get_message(), "message3") self.assertEqual(lastCmt.get_time_as_str(), "06/12/15 16:00:00")
def test_load(self): cda = CommentDataAccess("test.ini") cda.load() rlist = cda.list_all_comments() self.assertEqual(len(rlist), 3) c = rlist[0] self.assertEqual(c.get_id(), "id1") self.assertEqual(c.get_user_id(), "user1") self.assertEqual(c.get_message(), "message1") self.assertEqual(c.get_time(), datetime.datetime(2015, 6, 10, 12)) c = rlist[1] self.assertEqual(c.get_id(), "id2") self.assertEqual(c.get_user_id(), "user2") self.assertEqual(c.get_message(), "message2") self.assertEqual(c.get_time(), datetime.datetime(2015, 6, 10, 12)) c = rlist[2] self.assertEqual(c.get_id(), "id3") self.assertEqual(c.get_user_id(), "user3") self.assertEqual(c.get_message(), "message3") self.assertEqual(c.get_time(), datetime.datetime(2015, 6, 11, 12))