class TestUser(unittest.TestCase): def setUp(self): ''' Set up method to run before each test cases. ''' self.new_user = User("Collins", "Akumu", "akumu_collins", "4321", "4321") # create user object def test_init(self): ''' Test_init test case to test if the object is initialized properly ''' self.assertEqual(self.new_user.first_name, "Collins") self.assertEqual(self.new_user.last_name, "Akumu") self.assertEqual(self.new_user.user_name, "akumu_collins") self.assertEqual(self.new_user.password, "4321") self.assertEqual(self.new_user.confirm_password, "4321") def test_save_user(self): ''' Test_save_credentials test case to test if the contact object is saved into the contact list ''' self.new_user.save_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): ''' setUp method to run before each test cases ''' self.new_user = User("User1", "TheFirst") def tearDown(self): ''' tearDown method to clean up after each test case has run ''' User.user_list = [] def test_init(self): ''' test_init case to test if object is initialized properly ''' self.assertEqual(self.new_user.user_name, "User1") self.assertEqual(self.new_user.password, "TheFirst") def test_save_user(self): ''' test_save_user case to test if object is saved to user_list list ''' self.test_user = User("User2", "The2") self.test_user.save_user() self.assertEqual(len(User.user_list), 1) def test_save_multiple_user(self): ''' test_save_multiple_user case to test if multiple user objects can be saved to user_list ''' self.test_user = User("User2", "The2") self.new_user.save_user() self.test_user.save_user() self.assertEqual(len(User.user_list), 2) def test_delete_user(self): ''' test_delete_user case to test if user can be deleted from user_list ''' self.new_user.save_user() self.test_user = User("User2", "The2") self.test_user.save_user() self.test_user.delete_user() self.assertEqual(len(User.user_list), 1)
def test_save_multiple_user(self): ''' test_save_multiple_user to check if we can save multiple user objects to our user_list ''' self.new_user.save_user() test_user = User("Test", "0000", "*****@*****.**") # new user test_user.save_user() self.assertEqual(len(User.user_list), 2)
def test_delete_user(self): ''' Test to check if users can be deleted from the users list ''' self.new_user.save_user() test_user = User("Test", "user", "1234") test_user.save_user() self.new_user.delete_user() self.assertEqual(len(User.user_list), 1)
def test_delete_user(self): ''' test_delete_user to test if we can remove a user from our user list ''' self.new_user.save_user() test_user = User("Test", "0000", "*****@*****.**") # new user test_user.save_user() self.new_user.delete_user() # Deleting a user object self.assertEqual(len(User.user_list), 1)
def test_save_multiple_user(self): ''' Test save multiple user test case to see whether we can save multiple user accounts to our user list ''' self.new_user.save_user() test_user = User("marymukami", "0714253689", "*****@*****.**", "mary90") test_user.save_user() self.assertEqual(len(User.user_list), 2)
def test_user_exists(self): ''' Test to check if we can return a Boolean if account isn't found ''' self.new_user.save_user() test_user = User("marymukami", "0714253689", "*****@*****.**", "mary90") test_user.save_user() user_exists = User.user_exists("marymukami") self.assertTrue(user_exists)
def test_login(self): ''' Test to check if user can log into their credentials ''' self.new_user.save_user() #saving new user test_user = User("mwerumuchai", "07142536", "*****@*****.**", "mweru90") test_user.save_user() # Connect with credential account found_credential = User.login("mwerumuchai", "07142536", "*****@*****.**", "mweru90") self.assertEqual(found_credential, Credential.credential_account_list)
class TestUser(unittest.TestCase): def setUp(self): self.new_user = User("Vincentmuya", "vincent12345") def test_init(self): self.assertEqual(self.new_user.locker_userName, "Vincentmuya") self.assertEqual(self.new_user.locker_password, "vincent12345") def test_save_user(self): self.new_user.save_user() self.assertEqual(len(User.user_list),1) def tearDown(self): User.user_list = []
class TestUser(unittest.TestCase): def setUp(self): ''' Set up method to run before each test ''' self.new_user = User("Beryl", "Onyancha", "skittles") def tearDown(self): ''' Tear down method performs clean up after each test method completes ''' User.user_list = [] def test_init(self): ''' Test to check if initialization has been done ''' self.assertEqual(self.new_user.first_name, "Beryl") self.assertEqual(self.new_user.last_name, "Onyancha") self.assertEqual(self.new_user.password, "skittles") def test_save_user(self): ''' Test to check if users are added to the user list ''' self.new_user.save_user() self.assertEqual(len(User.user_list), 1) def test_delete_user(self): ''' Test to check if users can be deleted from the users list ''' self.new_user.save_user() test_user = User("Test", "user", "1234") test_user.save_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 behaviors. 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("toni", "1234", "*****@*****.**") # create contact object def test_init(self): ''' test_init test case to test if the object is initialized properly ''' self.assertEqual(self.new_user.user_name, "toni") self.assertEqual(self.new_user.password, "1234") self.assertEqual(self.new_user.email, "*****@*****.**") def tearDown(self): ''' tearDown method that does clean up after each test case has run. ''' User.user_list = [] def test_save_user(self): ''' test_save_user test case to test if the user object is saved into the user list ''' self.new_user.save_user() # saving the new user self.assertEqual(len(User.user_list), 1) def test_save_multiple_user(self): ''' test_save_multiple_user to check if we can save multiple user objects to our user_list ''' self.new_user.save_user() test_user = User("Test", "0000", "*****@*****.**") # new user test_user.save_user() self.assertEqual(len(User.user_list), 2) def test_delete_user(self): ''' test_delete_user to test if we can remove a user from our user list ''' self.new_user.save_user() test_user = User("Test", "0000", "*****@*****.**") # new user test_user.save_user() self.new_user.delete_user() # Deleting a user object self.assertEqual(len(User.user_list), 1) def test_display_user(self): ''' method that returns a list of all users saved ''' self.assertEqual(User.display_users(), User.user_list)
class TestUser(unittest.TestCase): # TestUser is a subclass ''' Test class that defines test cases for the user class behaviours ''' def setUp(self): ''' Set up method runs before each test case ''' self.new_user = User("mwerumuchai", "0711215485", "*****@*****.**", "mweru90") def test_init(self): ''' Test if the object is initialized properly ''' self.assertEqual(self.new_user.user_name, "mwerumuchai") self.assertEqual(self.new_user.user_phone_number, "0711215485") self.assertEqual(self.new_user.user_email, "*****@*****.**") self.assertEqual(self.new_user.user_password, "mweru90") # Check if user information is saved def test_save_user(self): ''' Tests save user test case to see if the user object is saved into the user_list ''' self.new_user.save_user() #saving new user self.assertEqual(len(User.user_list), 1) # this method executes a set of instructions after every test def tearDown(self): ''' This cleans up after each test case has run ''' User.user_list = [] # Check if user can save multiple user accounts def test_save_multiple_user(self): ''' Test save multiple user test case to see whether we can save multiple user accounts to our user list ''' self.new_user.save_user() test_user = User("marymukami", "0714253689", "*****@*****.**", "mary90") test_user.save_user() self.assertEqual(len(User.user_list), 2) # Use assertTrue method to check if the user account exists def test_user_exists(self): ''' Test to check if we can return a Boolean if account isn't found ''' self.new_user.save_user() test_user = User("marymukami", "0714253689", "*****@*****.**", "mary90") test_user.save_user() user_exists = User.user_exists("marymukami") self.assertTrue(user_exists) # Log into Credentials def test_login(self): ''' Test to check if user can log into their credentials ''' self.new_user.save_user() #saving new user test_user = User("mwerumuchai", "07142536", "*****@*****.**", "mweru90") test_user.save_user() # Connect with credential account found_credential = User.login("mwerumuchai", "07142536", "*****@*****.**", "mweru90") self.assertEqual(found_credential, Credential.credential_account_list) # Display all users def test_display_users(self): ''' test_display_users to test that it returns a list of all users saved ''' self.assertEqual(User.display_users(), User.user_list)