class TestUser(unittest.TestCase): def setUp(self): self.new_user = User("Wanjala", 12345) def test_init(self): self.assertEqual(self.new_user.username,"Wanjala") self.assertEqual(self.new_user.password,12345) def test_save_user(self): self.new_user.save_new_user() self.assertEqual(len(User.User_List),1) def test_save_multiple_user(self): self.new_user.save_new_user() second_user = User("Rovine",2345) second_user.save_new_user() self.assertEqual(len(User.User_List),2) def tearDown (second_user): User.User_List = [] def test_display_all_users(self): self.assertEqual(User.display_users(),User.User_List) def test_delete_user(self): self.new_user.save_new_user() test_user = User("Rovine", 2345) test_user.save_new_user() self.new_user.delete_user() self.assertEqual(len(User.User_List),1)
class testUser(unittest.TestCase): ''' Test class that defines test cases for the user class behaviours. Args: unittest.TestCase: TestCase class that helps in creating test cases ''' def setUp(self): ''' Set up method to run before each test cases. ''' self.new_user = User("mwalo","mwalo9214") # create contact object def test_init(self): ''' test_init test case to test if the object is initialized properly ''' self.assertEqual(self.new_user.lockname,"mwalo") self.assertEqual(self.new_user.password,"mwalo9214") def test_save_user(self): ''' test_save_user test case to test if the user's object is saved into the user's list ''' self.new_user.save_user() self.assertEqual(len(User.user_list),2) def test_delete_user(self): ''' delete user's account ''' self.new_user.save_user() test_user=User("mwalo254","mwalo254") test_user.save_user() self.new_user.delete_user() self.assertEqual(len(User.user_list),1)