def test_save_multiple_passwords(self): ''' test_save_multiple_contact to check whether we can save multiple contacts in the contact_list ''' self.new_credential.save_password() test_password = Credentials("Test", "user", "bvgtfy65") test_password.save_password() self.assertEqual(len(Credentials.locker), 2)
def test_delete_credentials(self): ''' Tests if we can remove credential from Credentials list ''' self.new_credentials.save_credentials() test_credential = Credentials("peter", "petero", "*****@*****.**", "abcdef") test_credential.save_credentials() self.assertEqual(len(Credentials.credentials_list), 2)
def test_save_multiple_credentials(self): ''' This checks if we can save multiple credentials objects into the credentials list. ''' self.new_credentials.save_credentials() test_credentials = Credentials("peter", "petero", "*****@*****.**", "abcdef") test_credentials.save_credentials() self.assertEqual(len(Credentials.credentials_list), 2)
def test_delete_password(self): ''' test method that tests whether passwords get deleted from the password locker ''' self.new_credential.save_password() test_password = Credentials("Test", "user", "1234") test_password.save_password() self.new_credential.delete_password() self.assertEqual(len(Credentials.locker), 1)
def test_credentials_exist(self): ''' this checks if a credentials exist and return a boolean ''' self.new_credentials.save_credentials() test_credentials = Credentials("omondi", "omosh", "omosh@gmail", "omosh12") test_credentials.save_credentials() credentials_exist = Credentials.credentials_exist self.assertTrue(credentials_exist)
def test_find_credentials_by_user_name(self): ''' This will check if we can find a credentila by user name and display information ''' self.new_credentials.save_credentials() test_credentials = Credentials("omondi", "omosh", "omosh@gmail", "mosh12") test_credentials.save_credentials() found_credentials = Credentials.find_by_user_name("omosh") self.assertEqual(found_credentials.email, test_credentials.email)
def test_display_all_credentials(self): ''' test method that returns a list of all the credentials saved. ''' self.assertEqual(Credentials.display_credentials(), Credentials.credentials_list)
def find_credentials(name): ''' this finds the credentials using account name and returns details ''' return Credentials.find_by_account_name(name)
def create_credentials(account, username, email, password): ''' This creates new credentials ''' new_credentials = Credentials(account, username, email, password) return new_credentials
def setUp(self): ''' Set up method to run before each test cases. ''' self.new_credentials = Credentials("Evoh", "Evohmike", "*****@*****.**", "1234")
def display_credentials(): ''' Function that returns all the saved credentials ''' return Credentials.display_credentials()
def main (): new_login_name = input("Create your password manager username:\n") new_login_password = input("Create a password for your locker:\n") new_user = User(new_login_name, new_login_password) new_user.save_manager() print(f"Welcome {new_login_name}") print("- " * 50) print("\n") login_name = input("Enter you login name:\n") password = input("Enter your password:\n") def login(): return login_name in User.users and User.users[login_name] == password while True: if login(): choice = input("Enter 'create' to create new credentials, 'display' to view your saved credentials, 'delete' to delete credentials, or 'copy' to copy an account's password and 'none' to exit:\n") if choice == 'none': break if choice == "create": # if account exists or not exists = input("Does the account exist already? Enter 'yes' or 'no': ") # create credentials for an existing account new_platform = input("Enter platform: ") new_username = input("Enter the username: "******"Enter password: "******"Enter 'generate' to autogenerate a password or 'create' to create your own\n") if pswd_option == 'create': new_password = input("Enter password: "******"generate": # generate a password using random pswd_string = '' for i in range(3): pswd_string = pswd_string + random.choice(string.ascii_letters) + str(random.randint(1, 10)) + random.choice('!$%&(*>?@^_') new_password = pswd_string else: print("Incorrect input. Please try again") continue #test these continues else: print("Incorrect input. Please try again") continue # create the account and print a message new_account = Credentials(new_platform, new_username, new_password) print(f"Successfully saved credentials for {new_account.platform}!\nUsername - {new_account.username}\nPassword - {new_account.password}") new_account.save_password() elif choice == "display": # Credentials.display_password() for item in Credentials.locker: print(item,'.....') item = Credentials.locker[item] for key in item: print(f"Username: {key}; Password: {item[key]}\n") elif choice == "delete": to_delete = input("Enter the account to delete from locker\n") # check if it's in locker if to_delete in Credentials.locker: inp = input(f"Are you sure you would like to delete {to_delete} details from locker? y/n: ") if inp == 'y': new_account.delete_password() elif inp == 'n': continue else: print("Sorry. You don't seem to have such an account in locker") elif choice == "copy": copy = input("Enter account you would like to copy password:"******"Sorry. You don't seem to have such an account in locker. Please check your spelling or save it first") else: print("Incorrect input. Please try again") else: print("Incorrect username or password!") break
def test_displays_passwords(self): ''' method that returns a list of all passwords in the locker ''' self.assertEqual(Credentials.display_password(), Credentials.locker)
class TestUser(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 tearDown(self): ''' test method that clears the password locker after each test ''' Credentials.locker = {} def setUp(self): ''' Set up method to run before each test cases. ''' self.new_credential = Credentials("Twitter", "JM", "Password2021") def test_init(self): ''' test case to test if the object is initialized properly ''' self.assertEqual(self.new_credential.platform, "Twitter") self.assertEqual(self.new_credential.username, "JM") self.assertEqual(self.new_credential.password, "Password2021") def test_save_password(self): ''' test to check whether the password details are saved ''' self.new_credential.save_password() self.assertEqual(len(Credentials.locker), 1) def test_save_multiple_passwords(self): ''' test_save_multiple_contact to check whether we can save multiple contacts in the contact_list ''' self.new_credential.save_password() test_password = Credentials("Test", "user", "bvgtfy65") test_password.save_password() self.assertEqual(len(Credentials.locker), 2) def test_delete_password(self): ''' test method that tests whether passwords get deleted from the password locker ''' self.new_credential.save_password() test_password = Credentials("Test", "user", "1234") test_password.save_password() self.new_credential.delete_password() self.assertEqual(len(Credentials.locker), 1) # print("The length is stll", len(Credentials.locker), Credentials.locker) def test_displays_passwords(self): ''' method that returns a list of all passwords in the locker ''' self.assertEqual(Credentials.display_password(), Credentials.locker) def test_copy_password(self): ''' test to check whether we can copy passwords ''' self.new_credential.save_password() self.new_credential.copy_password() self.assertEqual(self.new_credential.password, pyperclip.paste())
def copy_username(name): return Credentials.copy_username(name)
def check_credentials_exist(name): ''' This function to check if a credentials exists ''' return Credentials.credentials_exist(name)
class TestCredentials(unittest.TestCase): def setUp(self): ''' Set up method to run before each test cases. ''' self.new_credentials = Credentials("Evoh", "Evohmike", "*****@*****.**", "1234") def tearDown(self): ''' This method cleans up after each test case has run ''' Credentials.credentials_list = [] def test_credentials_init(self): ''' This tests if the object has been initialized properly ''' self.assertEqual(self.new_credentials.account_name, "Evoh") self.assertEqual(self.new_credentials.user_name, "Evohmike") self.assertEqual(self.new_credentials.email, "*****@*****.**") self.assertEqual(self.new_credentials.password, "1234") def test_save_credentials(self): ''' Test if the credentials objects are saved into the credentials list ''' self.new_credentials.save_credentials() self.assertEqual(len(Credentials.credentials_list), 1) def test_save_multiple_credentials(self): ''' This checks if we can save multiple credentials objects into the credentials list. ''' self.new_credentials.save_credentials() test_credentials = Credentials("peter", "petero", "*****@*****.**", "abcdef") test_credentials.save_credentials() self.assertEqual(len(Credentials.credentials_list), 2) def test_delete_credentials(self): ''' Tests if we can remove credential from Credentials list ''' self.new_credentials.save_credentials() test_credential = Credentials("peter", "petero", "*****@*****.**", "abcdef") test_credential.save_credentials() self.assertEqual(len(Credentials.credentials_list), 2) def test_find_credentials_by_user_name(self): ''' This will check if we can find a credentila by user name and display information ''' self.new_credentials.save_credentials() test_credentials = Credentials("omondi", "omosh", "omosh@gmail", "mosh12") test_credentials.save_credentials() found_credentials = Credentials.find_by_user_name("omosh") self.assertEqual(found_credentials.email, test_credentials.email) def test_credentials_exist(self): ''' this checks if a credentials exist and return a boolean ''' self.new_credentials.save_credentials() test_credentials = Credentials("omondi", "omosh", "omosh@gmail", "omosh12") test_credentials.save_credentials() credentials_exist = Credentials.credentials_exist self.assertTrue(credentials_exist) def test_display_all_credentials(self): ''' test method that returns a list of all the credentials saved. ''' self.assertEqual(Credentials.display_credentials(), Credentials.credentials_list)
def generate_password(password_length): return Credentials.generate_password(password_length)
def setUp(self): ''' Set up method to run before each test cases. ''' self.new_credential = Credentials("Twitter", "JM", "Password2021")