def setUp(self): # set up the test method self.new_credentials = Credential( "facebook", "673766") # create credentials object
def display_credentials(user_name): ''' function to display credentials saved by a user ''' return Credential.display_credentials(user_name)
def generate_password(): ''' Function to generate a password automatically ''' password_generate = Credential.generate_password() return password_generate
def save_credential(credential): '''/home/pricilla Function to save a newly created credential ''' Credential.save_credentials(credential)
def copy_credential(site_name): ''' Function to copy a credentials details to the clipboard ''' return Credential.copy_credential(site_name)
def create_credential(account_name, passkey): ''' function to create a new credential ''' new_credential = Credential(account_name, passkey) return new_credential
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 ''' def setUp(self): ''' Set up method to run before each test cases. ''' self.new_credential = Credential("IG", "Dema", 'd30') def test_init(self): ''' test_init test case to test if the object is initialized properly ''' self.assertEqual(self.new_credential.site_name, "IG") self.assertEqual(self.new_credential.username, "Dema") self.assertEqual(self.new_credential.password, "d30") def test_save_credential(self): ''' test_save_credential test case to test if the credential object is saved into the contact list ''' self.new_credential.save_credential() self.assertEqual(len(Credential.credential_list), 1) # setup and class creation up here def tearDown(self): ''' tearDown method that does clean up after each test case has run. ''' Credential.credential_list = [] def test_save_multiple_credentials(self): ''' test_save_multiple_credential to check if we can save multiple contact objects to our credential_list ''' self.new_credential.save_credential() test_credential = Credential('instagram', "user", "12dgj") test_credential.save_credential() self.assertEqual(len(Credential.credential_list), 2) def test_delete_credentials(self): ''' test_delete_contact to test if we can remove a credential from our credential list ''' self.new_credential.save_credential() test_save_credential = Credential("instagram", "user", "tes333") test_save_credential.save_credential() self.new_credential.delete_credential() self.assertEqual(len(Credential.credential_list), 1) def test_display_credentials(self): ''' Test to check if the display_credentials method, displays the correct credentials. ''' self.new_credential.save_credential() new_credential = Credential('Twitter', 'user', '1200') new_credential.save_credential() new_credential = Credential('Google', 'user2', 'we300') new_credential.save_credential() self.assertEqual(len(Credential.display_credentials()), 3) def test_find_by_site(self): ''' Test to check if the find_by_site method returns the correct credential ''' self.new_credential.save_credential() new_credential = Credential('Twitter', 'user', '1200') new_credential.save_credential() credential_exists = Credential.find_by_site('Twitter') self.assertEqual(credential_exists, new_credential)
def search_credential(name): return Credential.search_account(name)
def verify_user(first_name, password): ''' Function that verifies the existance of the user before creating credentials ''' checking_user = Credential.check_user(first_name, password) return checking_user
def create_credential_account(acc, pasw, usr): new_credential = Credential(acc, pasw, usr) return new_credential
def display_credentials(): return Credential.displayCredentials()
def main(): home = True head = ' ***********************************************************************************************' while home: print(head) print('|\t\t\t\t\t\t\t\t\t\t\t\t| \n|\tHi There!.Welcome to the Password-Locker System.\t\t\t\t\t\t|\n|\t\t\t\t\t\t\t\t\t\t\t\t|\n|\t\t\t***Have all your credentials from one point.***\t\t\t\t\t|\n|\t\t\t\t\t\t\t\t\t\t\t\t|\n|\tSelect a number to proceed...\t\t\t\t\t\t\t\t|\n|1. Create a Password Account\t\t\t\t\t\t\t\t\t\t|\n|2. Login with an existing account credentials\t\t\t\t\t\t\t\t\t\t|\n|3. Exit Password-Locker\t\t\t\t\t\t\t\t\t\t|\n|\t\t\t\t\t\t\t\t\t\t\t\t|') print(head) option = input() if option == '1': signup = False while not signup: print('--------------------------------------------------------') print('|\t\t\t\t\t\t\t|\n|\tHi! the system says- "Happy you are running me".\t\t\t|\n|\t\t\t\t\t\t\t|\n|Enter Your first name\t\t\t\t|\n|\t\t\t\t\t\t\t|\n|\t\tEnter\t\t1. Cancel\t\t|') print('--------------------------------------------------------') first_name = input() if first_name == '1': signup = not signup else: print('--------------------------------------------------------') print('|\t\t\t\t\t\t\t|\n|\tHi! the system says- "Happy you are running me"\t\t\t|\n|\t\t\t\t\t\t\t|\n|Enter Your last name\t\t\t\t|\n|\t\t\t\t\t\t\t|\n|\t\tEnter\t\t1. Cancel\t\t|') print('--------------------------------------------------------') last_name = input() if last_name == '1': signup = not signup else: print('--------------------------------------------------------') print('|\t\t\t\t\t\t\t|\n|\tHi! the system says- "Happy you are running me"\t\t\t|\n|\t\t\t\t\t\t\t|\n|Enter your email\t\t\t\t|\n|\t\t\t\t\t\t\t|\n|\t\tEnter\t\t1. Cancel\t\t|') print('--------------------------------------------------------') email = input() if email == '1': signup = not signup else: print('--------------------------------------------------------') print('|\t\t\t\t\t\t\t|\n|\tHi! the system says- "Happy you are running me"\t\t\t|\n|\t\t\t\t\t\t\t|\n|Enter a password\t\t\t\t|\n|\t\t\t\t\t\t\t|\n|\t\tEnter\t\t1. Cancel\t\t|') print('--------------------------------------------------------') password = input() if password == '1': signup = not signup else: user_created = User(first_name, last_name, email, password) if user_created.create_account(): print('--------------------------------------------------------') print('|\t\t\t\t\t\t\t|\n|\t\t\t\t\t\t\t|\n|\t\t Hello! User created successfully!\t\t|\n|\t\t\t\t\t\t\t|\n|\t\t\tEnter\t\t\t\t|') print('--------------------------------------------------------') status = input() if status == '1': signup = not signup else: signup = not signup else: print('--------------------------------------------------------') print('|\t\t\t\t\t\t\t|\n|\t\t\t\t\t\t\t|\n|\t\tThe process was violated.Kindly repeat.\t\t|\n|\t\t\t\t\t\t\t|\n|\t\t\tPress Enter\t\t\t\t|') print('--------------------------------------------------------') status = input() if status == '1': signup = not signup else: signup = not signup if option =='2': login = False while not login: print('--------------------------------------------------------') print('|\t\t\t\t\t\t\t|\n|\t\t\t\t\t\t\t|\n|Enter your email\t\t\t\t|\n|\t\t\t\t\t\t\t|\n|\t\tEnter\t\t1. Cancel\t\t|') print('--------------------------------------------------------') email = input() if email == '1': login = not login else: print('--------------------------------------------------------') print('|\t\t\t\t\t\t\t|\n|\t\t\t\t\t\t\t|\n|Enter your password\t\t\t\t|\n|\t\t\t\t\t\t\t|\n|\t\tEnter\t\t1. Cancel\t\t|') print('--------------------------------------------------------') password = input() if password == '1': login = not login else: account_status = User.check_account_exist(email, password) if account_status: print('--------------------------------------------------------') print('|\t\t\t\t\t\t\t|\n|\t\t\t\t\t\t\t|\n|\t\tYou are now logged in \t\t\t\t|\n|\t\t\t\t\t\t\t|\n|1. View Password Accounts\t\t\t\t|\n|2. Create a new Password Account\t\t\t\t|\n|3. Delete an existing Account\t\t\t\t|\n\t\t\t\t\t\t\t|') print('--------------------------------------------------------') perform = input() if perform == '1': all_acounts = Credential.display_accounts(email) print('--------------------------------------------------------') print('|\t\t\t\t\t\t\t|\n|\tHolla!!!! See your accounts now.\t\t\t|') if len(all_acounts) > 0: count = 1 for account in all_acounts: print(f'\t\t\t\t\t\t\t|\n|{count} {account["account"]}\t{account["password"]}') count +=1 else: print('|\t\t\t\t\t\t\t|\n|\t!!!!!!!!!!!!!!!!!!!!\t\t\t\t|\n|\t\t\t\t\t\t\t|\n|Sorry! You do not have any accounts set up.\t\t|') print('|\t\t\t\t\t\t\t|\n|\tEnter\t\t\t\t\t\t|') print('--------------------------------------------------------') input() login = not login elif perform == '2': print('--------------------------------------------------------') print('|\t\t\t\t\t\t\t|\n|\t\t\t\t\t\t\t|\n|Which account is this? i.e Instagram/Twitter ...\t|\n|\t\t\t\t\t\t\t|\n|\t\tEnter\t\t\t\t\t|') print('--------------------------------------------------------') account = input() account_exists = Credential.check_an_account_exist(email, account) if len(account) > 0 and not account_exists : print('--------------------------------------------------------') print('|\t\t\t\t\t\t\t|\n|\t\t\t\t\t\t\t|\n|\t\tYou are now logged in\t\t\t\t|\n|\t\t\t\t\t\t\t|\n|1. Get a system generated password\t\t\t\t|\n|2. Generate your own password\t\t\t\t|\n|\t\t\t\t\t\t\t|') print('--------------------------------------------------------') selected_account = input() if selected_account == '1': generated_password = Credential.randomizer() user_created_account = Credential(email, account, generated_password) if user_created_account.create_credential(): print('--------------------------------------------------------') print('|\t\t\t\t\t\t\t|\n|\t\t\t\t\t\t\t|\n|Account created successfully.\t\t\t|\n|\t\t\t\t\t\t\t|\n|\t\tEnter\t\t\t\t\t|') print('--------------------------------------------------------') input() else: print('--------------------------------------------------------') print('|\t\t\t\t\t\t\t|\n|\t\t\t\t\t\t\t|\n|Sorry! Please try again.\t|\n|\t\t\t\t\t\t\t|\n|\t\tEnter\t\t\t\t|') print('--------------------------------------------------------') login = not login else: print('--------------------------------------------------------') print('|\t\t\t\t\t\t\t|\n|\t\t\t\t\t\t\t|\n|Enter a password to use.(At least more than 8 characters long) \t|\n|\t\t\t\t\t\t\t|\n|\t\tEnter\t\t\t\t\t|') print('--------------------------------------------------------') account_password = input() ok_create = True while ok_create: if len(account_password) > 8: user_created_account = Credential(email, account, account_password) if user_created_account.create_credential(): print('--------------------------------------------------------') print('|\t\t\t\t\t\t\t|\n|\t\t\t\t\t\t\t|\n|Account Successfully created .\t\t\t\t|\n|\t\t\t\t\t\t\t|\n|\t\tEnter\t\t\t\t\t|') print('--------------------------------------------------------') input() else: print('--------------------------------------------------------') print('|\t\t\t\t\t\t\t|\n|\t\t\t\t\t\t\t|\n|Sorry! Please try again.\t|\n|\t\t\t\t\t\t\t|\n|\t\tEnter\t\t\t\t|') print('--------------------------------------------------------') ok_create = not ok_create login = not login else: print('--------------------------------------------------------') print('|\t\t\t\t\t\t\t|\n|\t\t\t\t\t\t\t|\n|Sorry the password is too short-Pleaset try again.\t|\n|\t\t\t\t\t\t\t|\n|\t\tEnter\t\t\t\t|') print('--------------------------------------------------------') ok_create = not ok_create else: print('--------------------------------------------------------') print('|\t\t\t\t\t\t\t|\n|\t\t\t\t\t\t\t|\n|This Account already exists.\t|\n|\t\t\t\t\t\t\t|\n|\t\tEnter\t\t\t\t|') print('--------------------------------------------------------') input() login = not login elif perform == '3': all_acounts = Credential.display_accounts(email) print('--------------------------------------------------------') print('|\t\t\t\t\t\t\t|\n|\tSelect the account you want to delete.\t\t\t|') if len(all_acounts) > 0: count = 1 for account in all_acounts: print(f'\t\t\t\t\t\t\t|\n|{count} {account["account"]}\t{account["password"]}') count +=1 to_delete = int(input()) account_to_delete = all_acounts[to_delete - 1] print(account_to_delete) print(account_to_delete['account']) is_deleted = Credential.delete_account(account_to_delete['email'], account_to_delete['account']) if is_deleted: print('--------------------------------------------------------') print('|\t\t\t\t\t\t\t|\n|\t\t\t\t|\n|\t\t\t\t\t\t\t|\n|Account deleted successfully\t\t\t|\n|\t\t\t\t\t\t\t|\n|\t\t\tEnter\t\t\t\t|') print('--------------------------------------------------------') input() else: print('--------------------------------------------------------') print('|\t\t\t\t\t\t\t|\n|\!!!!!!!!!!!!!!!!!!!!!!!!!!t\t\t|\n|\t\t\t\t\t\t\t|\n|Sorry Something went wrong!\t\t\t|\n|\t\t\t\t\t\t\t|\n|\t\t\tEnter\t\t\t\t|') print('--------------------------------------------------------') else: login = not login else: print('--------------------------------------------------------') print('|\t\t\t\t\t\t\t|\n|\t\t\t\t\t\t\t|\n|Account does not exist in the system. Please Sign Up\t\t\t|\n|\t\t\t\t\t\t\t|\n|\t\t\tEnter\t\t\t\t|') print('--------------------------------------------------------') error = input() login = not login elif option == '3': home = not home
def display_credentials(): ''' Function that returns all the saved credentials ''' return Credential.display_credentials()
def add_credential(account_type, user_name, password): ''' Function to add credential ''' new_credential = Credential(account_type, user_name, password) return new_credential
def display_credentials(): """ Function that returns the credentials list """ return Credential.display_credentials()
class TestCredential(unittest.TestCase): def setUp(self): '''Setting up credentials that will be used in the tests.''' self.test_user_credential = Credential('*****@*****.**', 'Twitter', '123@Iiht') self.test_other_user_credential = Credential( '*****@*****.**', 'Instagram', '123@Iiht') def tearDown(self): '''Clean up. Delete the credentials db after every test.''' if os.path.isfile(Credential.database): os.remove(Credential.database) def test_intialize_credential(self): '''Test that Credential instance is created successfully.''' self.assertEqual('*****@*****.**', self.test_user_credential.get_email()) self.assertEqual('Twitter', self.test_user_credential.get_account()) self.assertEqual('123@Iiht', self.test_user_credential.get_password()) def test_create_credentials_file(self): '''Test that the db is created successfully.''' with open(Credential.database, 'w+') as test_file: file_exists = os.path.isfile(Credential.database) self.assertTrue(file_exists) def test_record_a_credential(self): '''Test that a credential is always created and stored in the db successfully''' self.test_user_credential.create_credential() self.test_other_user_credential.create_credential() with open(Credential.database, 'r') as read_file: fields = ['email', 'account', 'password'] data_read = csv.DictReader(read_file, fields, lineterminator='\n') self.add_success = False counter = 0 for line in data_read: counter += 1 if line['email'] == '*****@*****.**' and line[ 'account'] == 'Twitter' and line[ 'password'] == '123@Iiht': self.add_success = True self.assertTrue(self.add_success) def test_check_account_exist(self): '''From the instance method. Search the DB and ensures the account exists''' self.test_user_credential.create_credential() account_exist = self.test_user_credential.check_account_exist() self.assertTrue(account_exist) def test_check_account_exist(self): '''From the class method. Search the DB and ensure an account exists''' self.test_user_credential.create_credential() account_exist = Credential.check_an_account_exist( self.test_user_credential.get_email(), self.test_user_credential.get_account()) self.assertTrue(account_exist) def test_check_account_exist_without_db(self): '''Tests and ensures check_an_account_exist() does not return True if the DB is non-Existent.''' account_exist = Credential.check_an_account_exist( self.test_user_credential.get_email(), self.test_user_credential.get_account()) self.assertFalse(account_exist) def test_randomizer(self): '''Tests and ensures the radomizer() generates the passwords''' random_password = Credential.randomizer() self.assertGreater(len(random_password), 7) self.assertLess(len(random_password), 9) def test_display_accounts(self): self.test_other_user_credential.create_credential() self.test_user_credential.create_credential() list_of_credentials = Credential.display_accounts( self.test_user_credential.get_email()) for a_credential in list_of_credentials: a_credential_exist = Credential.check_an_account_exist( a_credential['email'], a_credential['account']) if not a_credential_exist: return False self.assertTrue(a_credential_exist) def test_delete_account(self): '''Tests and ensures deletes successfully.''' self.test_user_credential.create_credential() account_created = Credential.check_an_account_exist( self.test_user_credential.get_email(), self.test_user_credential.get_account()) is_deleted = Credential.delete_account( self.test_other_user_credential.get_email(), self.test_other_user_credential.get_account()) list_of_credentials = Credential.display_accounts( self.test_user_credential.get_email()) account_exist = False for account in list_of_credentials: if account['account'] == self.test_user_credential.get_account(): account_exist = False else: account_exist = True self.assertTrue(account_created) self.assertTrue(is_deleted) self.assertFalse(account_exist)
def display_credentials(): ''' function that dispalys all credentials ''' return Credential.display_credentials()
def test_check_account_exist_without_db(self): '''Tests and ensures check_an_account_exist() does not return True if the DB is non-Existent.''' account_exist = Credential.check_an_account_exist( self.test_user_credential.get_email(), self.test_user_credential.get_account()) self.assertFalse(account_exist)
def setUp(self): ''' Set up method to run before each test cases. ''' self.new_credential = Credential("IG", "Dema", 'd30')
def setUp(self): '''Setting up credentials that will be used in the tests.''' self.test_user_credential = Credential('*****@*****.**', 'Twitter', '123@Iiht') self.test_other_user_credential = Credential( '*****@*****.**', 'Instagram', '123@Iiht')
def create_credential(user_name, site_name, password): ''' Function to create a new credential ''' new_credential = Credential(user_name, site_name, password) return new_credential
def test_randomizer(self): '''Tests and ensures the radomizer() generates the passwords''' random_password = Credential.randomizer() self.assertGreater(len(random_password), 7) self.assertLess(len(random_password), 9)
def display_credentials(): ''' Function to display credentials saved by a user ''' return Credential.display_credentials()
def create_credentials(view_password, account, login_name, pass_word): """ Function to create a new credential """ new_credential = Credential(view_password, account, login_name, pass_word) return new_credential
def save_credential(credential): ''' function that saves a newly created credential ''' Credential.save_credentials(credential)
def check_existing_credentials(account): ''' Function that check if a credential exists with that acc_name and return a Boolean ''' return Credential.credential_exist(account)
def copy_credential(media_site): ''' function to copy a credential on the clipboard ''' return Credential.copy_credential(media_site)
def find_credential(account): ''' Function that finds a credential by acc_name and returns the credential ''' return Credential.find_by_account(account)
def save_credential(credential): ''' Function to save a newly created credential ''' Credential.save_credentials(credential)
def test_display_all_credentials(self): ''' method that returns all contacts saved ''' self.assertEqual(Credential.display_credentials(), Credential.credentials_list)