def test_save_multiple_credential(self):
     '''
     Functions checks if the save can add several credentials 
     to the list of credentials
     '''
     self.new_credential.save_credentials()
     test_credential = Credentials("Felix", "twitter", "Felback24")
     test_credential.save_credentials()
     self.assertEqual(len(Credentials.list_of_credentials), 2)
    def test_credential_exists(self):
        '''
        Function that determine whether a credential exists
        '''
        self.new_credential.save_credentials()
        test_credential = Credentials("Felix", "twitter", "Felback24")
        test_credential.save_credentials()

        credential_exist = Credentials.credential_exists("Felix")
        self.assertTrue(credential_exist)
    def test_delete_credential(self):
        '''
        Function that tests if a user can delete a credential
        '''
        self.new_credential.save_credentials()
        test_credential = Credentials("Felix", "twitter", "Felback24")
        test_credential.save_credentials()

        self.new_credential.delete_credentials()
        self.assertEqual(len(Credentials.list_of_credentials), 1)
    def test_find_credential_by_name(self):
        '''
        Function that tests whether a credential can be searched with a
        name and credial returned
        '''
        self.new_credential.save_credentials()
        test_credential = Credentials("Felix", "twitter", "Felback24")
        test_credential.save_credentials()

        found_credential = Credentials.find_credentials_by_name("Felix")
        self.assertEqual(found_credential.credential_name,
                         test_credential.credential_name)
Beispiel #5
0
def create_credential(user_name,credential_name,credential_password):
    '''
    This is a function that generates a new credential 
    by instatiating a new object of the class Credentials
    '''
    new_run_credential = Credentials(user_name,credential_name,credential_password)
    return new_run_credential
 def test_display_credentials(self):
     '''
     Function that tests if the application can display all credentials
     '''
     self.assertEqual(Credentials.display_all_credentials(),
                      Credentials.list_of_credentials)
class TestCredentials(unittest.TestCase):
    '''
    Class test defines the test for all the behaviours of credentials
    Args:
        unnitest.TestCase: TestCase class that helps in creating test cases
    '''
    def setUp(self):
        '''
        A method that should be run before each test case
        '''
        self.new_credential = Credentials("Vincent", "facebook", "poheri333")

    def tearDown(self):
        '''
        A method that clears the class properties each time  test has been completed
        specifically in this case the method clears the list_of_credentials
        '''
        Credentials.list_of_credentials = []

    def test_init(self):
        '''
        A method that checks whether each  credential 
        is properly instanciated
        '''
        self.assertEqual(self.new_credential.user_name, "Vincent")
        self.assertEqual(self.new_credential.credential_name, "facebook")
        self.assertEqual(self.new_credential.credential_password, "poheri333")

    def test_save_credentials(self):
        '''
        A method that determines whether the save function adds
        credentials to the list of credentials
        '''
        self.new_credential.save_credentials()
        self.assertEqual(len(Credentials.list_of_credentials), 1)

    def test_save_multiple_credential(self):
        '''
        Functions checks if the save can add several credentials 
        to the list of credentials
        '''
        self.new_credential.save_credentials()
        test_credential = Credentials("Felix", "twitter", "Felback24")
        test_credential.save_credentials()
        self.assertEqual(len(Credentials.list_of_credentials), 2)

    def test_delete_credential(self):
        '''
        Function that tests if a user can delete a credential
        '''
        self.new_credential.save_credentials()
        test_credential = Credentials("Felix", "twitter", "Felback24")
        test_credential.save_credentials()

        self.new_credential.delete_credentials()
        self.assertEqual(len(Credentials.list_of_credentials), 1)

    def test_find_credential_by_name(self):
        '''
        Function that tests whether a credential can be searched with a
        name and credial returned
        '''
        self.new_credential.save_credentials()
        test_credential = Credentials("Felix", "twitter", "Felback24")
        test_credential.save_credentials()

        found_credential = Credentials.find_credentials_by_name("Felix")
        self.assertEqual(found_credential.credential_name,
                         test_credential.credential_name)

    def test_credential_exists(self):
        '''
        Function that determine whether a credential exists
        '''
        self.new_credential.save_credentials()
        test_credential = Credentials("Felix", "twitter", "Felback24")
        test_credential.save_credentials()

        credential_exist = Credentials.credential_exists("Felix")
        self.assertTrue(credential_exist)

    def test_display_credentials(self):
        '''
        Function that tests if the application can display all credentials
        '''
        self.assertEqual(Credentials.display_all_credentials(),
                         Credentials.list_of_credentials)
 def setUp(self):
     '''
     A method that should be run before each test case
     '''
     self.new_credential = Credentials("Vincent", "facebook", "poheri333")
Beispiel #9
0
def main():
    while True:
        # This is the main menu/ while loop
        print ('-'*10)
        print("PLEASE USE THE FOLLOWING SHORT CODES:")
        print ('-'*10)
        print("lg : to LOGIN") 
        print("cu : to CREATE NEW USER")
        print("fu : to FIND A USER")
        print("du : to DISPLAY ALL USERS")
        print("ex : to EXIT")
        short_code0= input()
        if short_code0 == 'lg':
                print("ENTER USER NAME")
                login_user_name= input()
                print("ENTER PASSWORD")
                login_password = input()

                if check_if_user_exists(login_user_name):
                    print(f"WELCOME {login_user_name}") 
                    logged_in_user = find_users(login_user_name)

                    if logged_in_user.password == login_password:

                        print(f"{logged_in_user.name} ...........{logged_in_user.password}")
                        print ('-'*10)

                        while True:
                            print ('-'*10)
                            print("PLEASE USE THE FOLLOWING SHORTCODES")
                            print ('-'*10)
                            print("cc :to ADD A CREDENTIAL")
                            print("dc :to DISPLAY CREDENTIALS") 
                            print("dl :to DELETE A CREDENTIAL")
                            print("ex :to EXIT")
                            shortcode3 = input()

                            credential_user_name = logged_in_user.name

                            if shortcode3 == 'cc':

                                while True:
                                    print ('-'*10)
                                    print("USE THE FOLLOWING SHORTCODES")
                                    print ('-'*10)
                                    print("1 :to ENTER YOUR OWN PASSWORD")
                                    print("2 : to GET SYSTEM GENERATED PASSWORD")
                                    print("ok : to GO BACK TO THE CREDENTIALS MENU")
                                    short_code5 = input()

                                    if short_code5 == '1':
                                        print(f"WELCOME {credential_user_name}, ADD A CREDENTIAL") 
                                        print ('-'*10)
                                        print("ENTER CREDENTIAL NAME")
                                        name_of_credential =input()
                                        print("ENTER CREDENTIAL'S PASSWORD")
                                        password_of_credential = input()

                                        save_credential_run(create_credential(credential_user_name,name_of_credential,password_of_credential))
                                        
                                        print("YOUR CREDENTIALS")
                                        print ('-'*10)
                                        for credential in Credentials.display_all_credentials():
                                            if credential_user_name == credential.user_name:
                                                print(f"CREDENTIAL:{credential.credential_name}......PASSWORD:{credential.credential_password}")
                                                print ("\n")
                                    

                                    elif short_code5 == '2':
                                        print ('-'*10)
                                        print(f"WELCOME {credential_user_name}, ADD A CREDENTIAL")
                                        print ('-'*10) 
                                        print("ENTER CREDENTIAL NAME")
                                        name_of_credential =input()
                                        print("YOUR PASSWORD HAS BEEN GENERATED")
                                        password_of_credential = random.randint(10000,99000)

                                        save_credential_run(create_credential(credential_user_name,name_of_credential,password_of_credential))
                                        
                                        print("YOUR CREDENTIALS")
                                        print ('-'*10)
                                        for credential in Credentials.display_all_credentials():
                                            if credential_user_name == credential.user_name:
                                                print(f"CREDENTIAL:{credential.credential_name}......PASSWORD:{credential.credential_password}")
                                                print ("\n")

                                    elif short_code5 == 'ok':
                                        break

                                    elif short_code5 == 'ex':
                                        break
                                    else:
                                         print("INVALID INPUT PLEASE USE THE PROVIDED SHORTCODES")
                                         print ("\n")


                            elif shortcode3 == 'dc':
                                print("YOUR CREDENTIALS")
                                print ('-'*10)
                                for credential in Credentials.display_all_credentials():
                                    if credential_user_name == credential.user_name:
                                        print(f"{credential.credential_name}......{credential.credential_password}")
                                        print ("\n")

                            elif shortcode3 == 'dl':
                                if Credentials.credential_exists(credential_user_name):
                                    print("ENTER NAME OF CREDETIAL TO DELETE")
                                    credential_for_delete = input()

                                    for credential in Credentials.display_all_credentials():
                                        if credential.credential_name == credential_for_delete:
                                            credential.delete_credentials()
                                            print(f"DELETED {credential_for_delete}")
                                            print("\n")

                                        else:
                                            print ('-'*10)
                                            print("THE ENTERED CREDENTIAL DOES NOT EXIST")
                                            print ("\n")
        
                                else:
                                    print("YOU HAVE NOT ADDED ANY CREDENTIALS YET")   
                                    print ("\n")     

                            elif shortcode3 == 'ex':
                                print("EXITING CREDENTIALS")
                                print ("\n")
                                break

                            else:
                                print("INVALID CHOICE PLEASE USE THE PROVIDED SHORTCODES")
                                print ("\n")
                            
                else:
                   print ('-'*10)
                   print("WRONG USER/PASSWORD COMBINATION")
                   print ('-'*10)
Beispiel #10
0
 def setUp(self):
     self.new_cred = Credentials()