class TestCredentials(unittest.TestCase): ''' Test class that defines test cases for the credential class behaviours. Args: unittest.TestCase: TestCase class that helps in creating test cases ''' #1 def setUp(self): ''' Set up method to run before each test cases. ''' # create user object self.new_account = Credentials("Youtube","Wainaina","password") def tearDown(self): ''' tearDown method that does clean up after each test case has run. ''' Credentials.accounts = [] def test_init(self): ''' test_init test case to test if the object is initialized properly ''' self.assertEqual(self.new_account.account_name,"Youtube") self.assertEqual(self.new_account.user_account,"Wainaina") self.assertEqual(self.new_account.account_password,"password") def test_save_account(self): ''' test_save_user test case to test if the credential object is saved into the account list ''' # saving the new credential account self.new_account.save_account() self.assertEqual(len(Credentials.accounts),1) def test_save_multiple_accounts(self): ''' test_save_multiple_accounts to check if we can save multiple accounts objects to our accounts ''' self.new_account.save_account() test_account = Credentials("WhatsApp","Wainaina","password") # new account test_account.save_account() self.assertEqual(len(Credentials.accounts),2) def test_delete_account(self): ''' test_delete_user to test if we can remove a account from our accounts ''' self.new_account.save_account() test_account = Credentials("Test","user","password") # new account test_account.save_account() self.new_account.accounts self.new_account.delete_account()# Deleting a account object self.assertEqual(len(Credentials.accounts),1) # Test if account exist def test_account_exists(self): ''' test to check if we can return a Boolean if we cannot find the user. ''' self.new_account.save_account() test_account = Credentials("Google","Wainaina","12345") # new account test_account.save_account() account_exists = Credentials.account_exist("Wainaina") self.assertTrue(account_exists) """ Dispaly account user """ def test_display_all_account(self): ''' method that returns a list of all account saved ''' self.assertEqual(Credentials.display_accounts(),Credentials.accounts)
class TestCredentials(unittest.TestCase): def setUp(self): """ Test class that defines test cases for the Credentials Class behaviours """ self.newaccount = Credentials("donaldkiplagat","Instagram","donald123") def tearDown(self): """ tearDown method that does clean up after each test case has been return """ Credentials.accounts=[] def test_init(self): """ test_init case to test if the object is initialized properly """ self.assertEqual(self.newaccount.accountusername,"donaldkiplagat") self.assertEqual(self.newaccount.accountname,"Instagram") self.assertEqual(self.newaccount.accountpassword,"donald123") def test_save_account(self): """ test_save_account test case to test if the credentials object is saved into accounts """ self.newaccount.save_account() self.assertEqual(len(Credentials.accounts),1) def test_save_multiple_accounts(self): """ test_save_multiple_accounts to test if we can save multiple credentials to accounts """ self.newaccount.save_account() testaccount=Credentials("TestUsername","TestAccount","Password") testaccount.save_account() self.assertEqual(len(Credentials.accounts),2) def test_delete_account(self): """ test_delete_account to test if we can remove a credential from our account """ self.newaccount.save_account() testaccount=Credentials("donaldkiplagat","Twitter","twitter123") testaccount.save_account() self.newaccount.delete_account() self.assertEqual(len(Credentials.accounts),1) def test_display_all_accounts(self): """ method that returns a list of all credentials saved """ self.assertEqual(Credentials.display_accounts(),Credentials.accounts) def test_find_user_by_number(self): """ test to check if we can find a credential by their accountusername and display the credential """ self.newaccount.save_account() testaccount=Credentials("TestUsername","TestAccount","Password") testaccount.save_account() found_account = Credentials.find_by_number("TestUsername") self.assertEqual(found_account.accountusername,testaccount.accountusername)
def delete_account(Credentials): Credentials.delete_account()