class TestUser(unittest.TestCase): """ Test class that defines test cases for the user class behaviours. """ def setUp(self): self.created_user = User("Kiptoo", "1997") def tearDown(self): User.user_list = [] def test_init(self): self.assertEqual(self.created_user.name, "Kiptoo") self.assertEqual(self.created_user.user_password, "1997") def test_save_user(self): """ test_save_user test case to test if the user object is saved into the user list """ self.created_user.save_user() # saving the new user self.assertEqual(len(User.user_list), 1) def test_save_multiple_user(self): self.created_user.save_user() test_user = User("Kevin", "1050") 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 users list """ self.created_user.save_user() test_user = User("Kevin", "1050") test_user.save_user() self.created_user.delete_user() self.assertEqual(len(User.user_list), 1)
class TestUser(unittest.TestCase): def setUp(self): ''' Set up method to run before each test cases. ''' self.new_user = User("feven", "abc123") # create User object def tearDown(self): ''' tearDown method that does clean up after each test case has run. ''' User.user_list = [] def test_init(self): ''' test_init test case to test if the object is initialized properly ''' self.assertEqual(self.new_user.first_name, "feven") self.assertEqual(self.new_user.password, "abc123") 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() self.assertEqual(len(User.user_list), 1) def test_save_multiple_user(self): ''' test_save_multiple_contact to check if we can save multiple contact objects to our contact_list ''' self.new_user.save_user() test_user = User("fname", "abc123") # 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("feven", "a1b1c1") # 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_all_users(self): ''' method that returns a list of all users saved ''' self.assertEqual(User.display_users(), User.user_list) def test_user_exists(self): ''' test to check if we can return a Boolean if we cannot find the user. ''' self.new_user.save_user() test_user = User("feven", "a1b1c1") # new user test_user.save_user() user_exists = User.user_exist("feven") self.assertTrue(user_exists)
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 tearDown(self): ''' tear down method that cleans up after each test case is run ''' User.user_List = [] def setUp(self): ''' Set up method to run before each test cases. ''' self.new_user = User("tu276","nathan") #create user object def test_init(self): ''' test_init test case to test if the object is initialized properly ''' self.assertEqual(self.new_user.login_username,"tu276") self.assertEqual(self.new_user.user_password,"nathan") def test_save_user(self): ''' test case to see if user ogject is saved into ''' self.new_user.save_user() #save user self.assertEqual(len(User.user_List),1) def test_save_multiple_user(self): self.new_user.save_user() test_user = User("Test_user","password")#new user test_user.save_user() self.assertEqual(len(User.user_List),2) def test_delete_user(self): self.new_user.save_user() test_user = User("Test_user","password") test_user.save_user() self.new_user.delete_user() #del user self.assertEqual(len(User.user_List),1) def test_users_exists(self): ''' returns boolean if users not found test ''' self.new_user.save_user() test_user = User("test_user","password",) test_user.save_user() user_exists = User.user_exist("test") self.assertTrue(user_exists)
class TestUser(unittest.TestCase): ''' Test class that defines test cases for user class behaviours Args: unittest.TestCase: class that helps in creating test cases ''' def setUp(self): ''' Set up method to run before each test cases. ''' self.new_user = User("Joe", "Instagram", "@joe.com", "killshot18") def tearDown(self): ''' tearDown method that does clean up after each test case has run ''' User.user_list = [] def test_init(self): ''' test_init test case to case to test if the object is initialized properly ''' self.assertEqual(self.new_user.user_name, "Joe") self.assertEqual(self.new_user.account_name, "Instagram") self.assertEqual(self.new_user.email, "@joe.com") self.assertEqual(self.new_user.password, "killshot18") def test_save_user(self): ''' test_save_user test case to test if the user object is saved into user list ''' self.new_user.save_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 users object to our lists ''' self.new_user.save_user() test_user = User("Roman", "Facebook", "@roman.com", "reigns18") test_user.save_user() self.assertEqual(len(User.user_list), 2) def test_delete_user(self): ''' test_delete_contact to test if we can remove a contact from our contact list ''' self.new_user.save_user() test_user = User("Roman", "Facebook", "@roman.com", "reigns18") test_user.save_user() self.new_user.delete_user() self.assertEqual(len(User.user_list), 1) def test_find_user_by_account_name(self): ''' test to check if we can find user by account name and display information ''' self.new_user.save_user() test_user = User("Roman", "Facebook", "@roman.com", "reigns18") test_user.save_user() found_user = User.find_by_account_name("Facebook") self.assertEqual(found_user.password, test_user.password) def test_user_exists(self): ''' test to check if we can return a boolean if cannot find the contact. ''' self.new_user.save_user() test_user = User("Roman", "Facebook", "@roman.com", "reigns18") test_user.save_user() user_exists = User.user_exist("Facebook") self.assertTrue(user_exists) def test_display_all_users(self): ''' method that returns a list of all contacts saved ''' self.assertEqual(Credential.display_users(), Credential.user_list) def test_copy_email(self): ''' test to confirm that we are copying email from found user ''' self.new_user.save_user() User.copy_email("Instagram") self.assertEqual(self.new_user.email, pyperclip.paste())
class TestUser(unittest.TestCase, User, Credentials): ''' This is test class that defines test cases for the user and credentials 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("Derrick", "Kariuki", "0718016066", "*****@*****.**") # creates user object self.new_account = Credentials( "Instagram", "dero1234") # creates credentials object def tearDown(self): ''' tearDown method that cleans up after each test case has run ''' User.user_list = [] Credentials.account_list = [] def test_init(self): ''' test init test case to test if the object is initialized properly ''' self.assertEqual(self.new_user.first_name, "Derrick") self.assertEqual(self.new_user.last_name, "Kariuki") self.assertEqual(self.new_user.phone_number, "0718016066") self.assertEqual(self.new_user.email, "*****@*****.**") self.assertEqual(self.new_account.account_name, "Instagram") self.assertEqual(self.new_account.account_password, "dero1234") def test_save_user(self): ''' test_save_user test case tests whether the user object is saved in the user list ''' self.new_user.save_user() # saving the new user self.assertEqual(len(User.user_list), 1) def test_save_account(self): ''' test_save_account test case tests whether the account object is saved in the account list ''' self.new_account.save_account() # saving the new account self.assertEqual(len(Credentials.account_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", "user", "0712345678", "*****@*****.**") # the new user test_user.save_user() self.assertEqual(len(User.user_list), 2) def test_save_multiple_account(self): ''' test_save_multiple_account to check if we can save multiple account objects to our account_list ''' self.new_account.save_account() test_account = Credentials("Test", "account12") # the new account test_account.save_account() self.assertEqual(len(Credentials.account_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", "user", "0712345678", "*****@*****.**") # new user test_user.save_user() self.new_user.delete_user() # Deleting a user object self.assertEqual(len(User.user_list), 1) def test_delete_account(self): ''' test_delete_account to test if we can remove an account from our account list ''' self.new_account.save_account() test_account = Credentials("Test", "account12") # new account test_account.save_account() self.new_account.delete_account() # Deleting a account object self.assertEqual(len(Credentials.account_list), 1) def test_find_user_by_number(self): ''' test to check if we can find a user by phone number and display information ''' self.new_user.save_user() test_user = User("Test", "user", "0711223344", "*****@*****.**") # new user test_user.save_user() found_user = User.find_by_number("0711223344") self.assertEqual(found_user.email, test_user.email) def test_user_exists(self): ''' test to check if we can return a Boolean if we cannot find the user. ''' self.new_user.save_user() test_user = User("Test", "user", "0711223344", "test@user") #new user test_user.save_user() user_exists = User.user_exist("0711223344") self.assertTrue(user_exists) def test_display_all_users(self): ''' test to check that a list of all users saved is returned. ''' self.assertEqual(User.display_users(), User.user_list) def test_display_all_accounts(self): ''' test to check that a list of all accounts saved is returned. ''' self.assertEqual(Credentials.display_accounts(), Credentials.account_list)