def testSaveMultiCred(self): ''' testSaveMultiUser test checks if we can save multiple credential objects to our userList ''' self.newCred.saveCred() testCred=Cred("hangout1","anny1","aabc@1") testCred.saveCred() self.assertEqual(len(Cred.listCred),2)
def testCheckCredCForm(self): ''' test to check if we can return a Boolean if we cannot find the platform. ''' self.newCred.saveCred() testCred=Cred("hangout1","anny1","aabc@1") testCred.saveCred() existCForm=Cred.checkCform('hangout1') self.assertTrue(existCForm)
def testFindCredCForm(self): ''' test to check if we can find a credential by platform ''' self.newCred.saveCred() testCred=Cred("hangout1","anny1","aabc@1") testCred.saveCred() findCForm=Cred.findCredCform('hangout1') self.assertEqual(findCForm,'hangout1')
def test_save_multiple_cred(self): ''' test_save_multiple_cred to check if we can save multiple cred objects to our credentials_array ''' self.new_cred.save_cred() test_cred = Cred("TC", "CredTest", "Tcred", "CT1999") test_cred.save_cred() self.assertEqual(len(Cred.credentials_array), 2)
def test_cred_test(self): ''' test to check if we can return a Boolean if we cannot find the credentials ''' self.new_cred.save_cred() test_cred = Cred("TC", "CredTest", "Tcred", "CT1999") test_cred.save_cred() cred_exists = Cred.cred_exist("CredTest") self.assertTrue(cred_exists)
def test_delete_contact(self): ''' test_deleteCred to test if we can remove a credential from our credential list ''' self.newCred.saveCred() testCred=Cred("hangout1","anny1","aabc@1") testCred.saveCred() self.newCred.deleteCred()# Deleting a credential object self.assertEqual(len(Cred.listCred),1)
def test_delete_cred(self): ''' test_delete_cred to test if we can remove a credential from our credentials array ''' self.new_cred.save_cred() test_cred = Cred("TC", "CredTest", "Tcred", "CT1999") test_cred.save_cred() self.new_cred.delete_cred() self.assertEqual(len(Cred.credentials_array), 1)
def test_find_cred_by_account(self): ''' test to check if we can find credentials by account and display information ''' self.new_cred.save_cred() test_cred = Cred("TC", "CredTest", "Tcred", "CT1999") test_cred.save_cred() found_cred = Cred.find_by_account("TC", "CredTest") self.assertEqual(found_cred.account, test_cred.account)
def test_delete_credentials(self): ''' test_delete_credentials to test if we can remove an account from our cred list ''' self.new_cred.save_cred() test_cred = Cred("facebook", "*****@*****.**", "Bart-Menz", "!Bmenz@fb") test_cred.save_cred() self.new_cred.delete_cred() self.assertEqual(len(Cred.cred_list), 1)
def test_cred_exists(self): ''' test to check if we can return a Boolean if we cannot find the user's credentials. ''' self.new_cred.save_cred() test_cred = Cred("facebook", "*****@*****.**", "Bart-Menz", "!Bmenz@fb") test_cred.save_cred() cred_exists = Cred.cred_exists("facebook") self.assertTrue(cred_exists)
def test_find_cred_by_accountName(self): ''' test to check if we can find a user's credentials by accountName and display information ''' self.new_cred.save_cred() test_cred = Cred("facebook", "*****@*****.**", "Bart-Menz", "!Bmenz@fb") test_cred.save_cred() found_cred = Cred.find_by_accountName("facebook") self.assertEqual(found_cred.accountName, test_cred.accountName)
def createUserCred(cForm, cName, cWord): ''' Function to create a new user ''' newCred = Cred(cForm, cName, cWord) return newCred
def test_gen_password(self): ''' test to check if we can generate a password based on username ''' self.new_cred.save_cred() test_cred = Cred("instagram", "*****@*****.**", "Bart-Menz", "") test_cred.password = Cred.gen_password("Bart-Menz") test_cred.save_cred() self.assertTrue(len(test_cred.password) > 2)
def setUp(self): ''' Set up method to run before each test case. ''' self.new_cred = Cred("IJacco", "Faceb", "IJaccojwang", "I1999")
def find_cred(username_login, account): ''' Function that finds a cred by number and returns the cred ''' return Cred.find_by_account(username_login, account)
def setUp(self): self.newCred=Cred("hangout","anny","aabc@") '''
def check_existing_creds(number): ''' Function to check is a cred exists with that number and return a Boolean ''' return Cred.cred_exist(number)
class TestClasse2(unittest.TestCase): def setUp(self): self.newCred=Cred("hangout","anny","aabc@") ''' test_init test case to test if the object is initialized properly ''' def test2Init(self): self.assertEqual(self.newCred.cForm,"hangout") self.assertEqual(self.newCred.cName,"anny") self.assertEqual(self.newCred.cWord,"aabc@") ############################################################## #saving credentials def testSaveCred(self): ''' testSaveUser test case to test if the user object is saved into the user list ''' self.newCred.saveCred() self.assertEqual(len(Cred.listCred),1) ############################################################## #saving multiple credentials def tearDown(self): ''' tearDown method that cleans up after each test case has run. ''' Cred.listCred = [] def testSaveMultiCred(self): ''' testSaveMultiUser test checks if we can save multiple credential objects to our userList ''' self.newCred.saveCred() testCred=Cred("hangout1","anny1","aabc@1") testCred.saveCred() self.assertEqual(len(Cred.listCred),2) ############################################################## #displaying credentials def testDisplayCred(self): ''' method that returns a list of all user credentials ''' self.assertEqual(Cred.displayCred(),Cred.listCred) ############################################################## #testing the user password by finding it def testFindCredCForm(self): ''' test to check if we can find a credential by platform ''' self.newCred.saveCred() testCred=Cred("hangout1","anny1","aabc@1") testCred.saveCred() findCForm=Cred.findCredCform('hangout1') self.assertEqual(findCForm,'hangout1') # ############################################################## #testing the user password by checking if it already exits def testCheckCredCForm(self): ''' test to check if we can return a Boolean if we cannot find the platform. ''' self.newCred.saveCred() testCred=Cred("hangout1","anny1","aabc@1") testCred.saveCred() existCForm=Cred.checkCform('hangout1') self.assertTrue(existCForm) ############################################################## # Delete test def test_delete_contact(self): ''' test_deleteCred to test if we can remove a credential from our credential list ''' self.newCred.saveCred() testCred=Cred("hangout1","anny1","aabc@1") testCred.saveCred() self.newCred.deleteCred()# Deleting a credential object self.assertEqual(len(Cred.listCred),1)
def checkByCform(cForm): ''' Function for checking user password ''' Cred.checkCform(cForm)
def findUserByCform(cForm): ''' Function for finding user password ''' return Cred.findCredCform(cForm)
def gen_password(username): return Cred.gen_password(username)
def find_cred(accountName): ''' Function that finds a user's credentials by accountName and returns the credentials ''' return Cred.find_by_accountName(accountName)
def check_existing_cred(accountName): ''' Function that check if credentials exist with that accountName and return a Boolean ''' return Cred.cred_exists(accountName)
def testDisplayCred(self): ''' method that returns a list of all user credentials ''' self.assertEqual(Cred.displayCred(),Cred.listCred)
class Testcred(unittest.TestCase): ''' Test class that defines test cases for the 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 case. ''' self.new_cred = Cred("IJacco", "Faceb", "IJaccojwang", "I1999") def tearDown(self): ''' tearDown method that does clean up after each test case has run. ''' Cred.credentials_array = [] def test_init_cred(self): ''' test_init test case to test if the cred object is initialized properly ''' self.assertEqual(self.new_cred.username_login, "IJacco") self.assertEqual(self.new_cred.account, "Faceb") self.assertEqual(self.new_cred.username_cred, "IJaccojwang") self.assertEqual(self.new_cred.password_cred, "I1999") def test_save_cred(self): ''' test_save_cred test case to test if the cred object is saved to credentials array ''' self.new_cred.save_cred() self.assertEqual(len(Cred.credentials_array), 1) def test_save_multiple_cred(self): ''' test_save_multiple_cred to check if we can save multiple cred objects to our credentials_array ''' self.new_cred.save_cred() test_cred = Cred("TC", "CredTest", "Tcred", "CT1999") test_cred.save_cred() self.assertEqual(len(Cred.credentials_array), 2) def test_delete_cred(self): ''' test_delete_cred to test if we can remove a credential from our credentials array ''' self.new_cred.save_cred() test_cred = Cred("TC", "CredTest", "Tcred", "CT1999") test_cred.save_cred() self.new_cred.delete_cred() self.assertEqual(len(Cred.credentials_array), 1) def test_find_cred_by_account(self): ''' test to check if we can find credentials by account and display information ''' self.new_cred.save_cred() test_cred = Cred("TC", "CredTest", "Tcred", "CT1999") test_cred.save_cred() found_cred = Cred.find_by_account("TC", "CredTest") self.assertEqual(found_cred.account, test_cred.account) def test_cred_test(self): ''' test to check if we can return a Boolean if we cannot find the credentials ''' self.new_cred.save_cred() test_cred = Cred("TC", "CredTest", "Tcred", "CT1999") test_cred.save_cred() cred_exists = Cred.cred_exist("CredTest") self.assertTrue(cred_exists) def test_display_all_credentials(self): ''' method that returns a array of all users saved ''' self.assertEqual(Cred.display_creds(), Cred.credentials_array)
def display_creds(): ''' Function that returns all saved creds ''' return Cred.display_creds()
def display_accounts(): ''' Function that returns all the saved accounts ''' return Cred.display_accounts()
def displayCreds(): ''' Function that returns all the saved contacts ''' return Cred.displayCred()
def test_display_all_credentials(self): ''' method that returns a array of all users saved ''' self.assertEqual(Cred.display_creds(), Cred.credentials_array)
def main(): print("Welcome to PassLocker") print("-"*10) while True: print("Please use the following short codes:") print ("su - Sign-up, li - Login, ex - Exit") print('\n') short_code = input().lower() if short_code == 'su': print("Sign up to create a PassLocker account") print("-"*20) print("Fullname.....") fullname = input() print("Email Address.....") email = input() print("Username.....") username = input() print("Password.....") password = input() save_new_user(User(fullname, email, username, password)) print('\n') print(f"Welcome {username}, your account has successfully been created") print ('\n') elif short_code == 'li': print("Login to your PassLocker account") print("-"*20) # while True: print("Username.....") search_user = input() if check_existing_user(search_user): search_user = find_user(search_user) # while True: print("Password.....") password = input() if password == search_user.password: print(f"Welcome {username}, you are logged in!") print ('\n') while True: print("Please use the following short codes:") print(""" add - Add & save existing accounts, gen - Generate password for new account, disp - display accounts, del - Delete account, lo - Log out """) short_code = input().lower() if short_code == 'add': print ('\n') print("Add new account") print("-"*10) print("Account Name.....") accountName = input() print("Email Address.....") email = input() print("Username.....") username = input() print("Password.....") password = input() save_new_cred(Cred(accountName, email, username, password)) print('\n') print(f"Your {accountName} account has successfully been added!") print ('\n') elif short_code == 'gen': print ('\n') print("A random password will be created for this account") print("-"*30) print("Account Name.....") accountName = input() print("Email Address.....") email = input() print("Username.....") username = input() password = gen_password(username) print(f"Your password is {password}") save_new_cred(Cred(accountName, email, username, password)) print('\n') print(f"Your {accountName} account has successfully been added!") print ('\n') elif short_code == 'disp': if display_accounts(): print ('\n') print("Here is a list of all your accounts") print('\n') for cred in display_accounts(): print(f"{cred.accountName}, {cred.email}, {cred.username}, {cred.password}") print('\n') else: print('\n') print("You dont seem to have any contacts saved yet") print('\n') elif short_code == 'del': print ('\n') print("What is the name of the account you want to delete?...") accountName = input() if find_cred(accountName): del_cred(Cred((accountName, email, username, password))) print('\n') print(f"Your {accountName} account has successfully been deleted!") print ('\n') elif short_code == 'lo': print ('\n') print("Sorry to see you go... Come back soon!") print ('\n') break else: print ('\n') print("I really didn't get that. Please use the short codes") print ('\n') # break else: print("Incorrect password") print ('\n') else: print(f"{username} does not exist, please sign up.") elif short_code == 'ex': print("Bye .......") break else: print("I really didn't get that. Please use the short codes")