コード例 #1
0
 def test_user_delete_account(self):
     """
     test user_delete_account to test if a user can be able to delete their account
     """
     self.test_user = User("username", "password1")
     self.test_user.save_user()
     self.test_user.user_delete_account()
     self.assertEqual(len(User.user_list), 0)
コード例 #2
0
 def test_user_change_pass(self):
     """
     test user change password test case to test if a user can be able to change their password test_create_new_account
     """
     test_u = User("username", "password1")
     test_u.save_user()
     change_pass = test_u.change_userpass("username", "password")
     self.assertEqual(change_pass.password, "password")
コード例 #3
0
 def test_username_match_password(self):
     """
     test usename match password to test if an entered username matches the password
     """
     self.test_user = User("username", "password1")
     self.test_user.save_user()
     confirm_user_exist = User.confirm_user("username", "password1")
     self.assertTrue(confirm_user_exist)
コード例 #4
0
 def test_check_user_exists(self):
     """
     test check user exists to test if a user exists or not
     """
     self.test_user = User("username", "password1")
     self.test_user.save_user()
     found_user = User.find_user("username")
     self.assertTrue(found_user)
コード例 #5
0
def user_change_password(usern, newpass):
    return User.change_userpass(usern, newpass)
コード例 #6
0
def main():
    try:
        cprint(figlet_format('cipher', font='starwars'),
               'blue',
               attrs=['bold'])
        cprint("\033[1m" + "Hello, Welcome to cipher".center(terminal_width),
               "white",
               attrs=['bold', 'blink'])
        while True:
            print("Already have an account? Y/N")
            account_prompt = input().upper().strip()
            if account_prompt == "Y":
                print("Enter your username:"******"You have not entered a username !", "red")
                    print("Enter your username:"******"Enter your password:"******"You have not entered a password!", "red")
                    print("Enter your password:"******"\n")
                    cprint("Incorrect username / password combination", "red")
                    print("\n")
                else:
                    while True:
                        print(
                            "\033[1m PROFILE CONTROLS:- " + '\033[0m' +
                            "Use these short codes : np - Add a new profile, dp-Display all profiles, gp - generate new password for a profile, search - find a profile, copy - copy password to clipboard, del - delete a profile, logout- logout of session, ex - exit the application"
                        )
                        print(
                            "\033[1m ACCOUNT CONTROLS:- " + '\033[0m' +
                            "Use these short codes : acp - Change your account password, delete - Delete your account"
                        )
                        short_code = input()
                        handle_short_codes(short_code)
                        if short_code == "logout" or short_code == "delete":
                            break

            elif account_prompt == "N":
                print("Enter your details to create a new account".center(
                    terminal_width))
                print("Please enter your preffered username")
                new_user_username = input()
                if not new_user_username:
                    cprint("You have not entered any username!", "red")
                    new_user_username = input()
                print("Please enter your password")
                new_user_password = input()
                if not new_user_password:
                    cprint("You have not entered any password!", "red")
                    new_user_password = input()
                user_already_exist = check_username_exists(new_user_username)
                if not user_already_exist:
                    user_new = User(new_user_username, new_user_password)
                    if not save_account(user_new):
                        print("\n")
                        cprint(
                            "\033[1m Account created successfully \033[0m".
                            center(terminal_width), "green")
                        print("\n")
                        while True:
                            print(
                                "\033[1m PROFILE CONTROLS:- " + '\033[0m' +
                                "Use these short codes : np - Add a new profile, dp-Display all profiles, gp - generate new password for a profile, search - find a profile, copy - copy password to clipboard, del - delete a profile, logout- logout of session,  ex - exit the application"
                            )
                            print(
                                "\033[1m ACCOUNT CONTROLS:- " + '\033[0m' +
                                "Use these short codes : acp - Change your account password, delete - Delete your account"
                            )
                            short_code = input()
                            handle_short_codes(short_code)
                            if short_code == "logout" or short_code == "delete":
                                break
                else:
                    print("\n")
                    cprint("The username is already in use", "magenta")
                    cprint("Please try another username", "magenta")
                    print("\n")

            else:
                print("\n")
                cprint(
                    "You have entered unrecognised command...Please enter Y/N!",
                    "red")
                print("\n")
    except KeyboardInterrupt:
        print("\n")
        cprint("An interrupt detected...Exiting..", "yellow", attrs=["bold"])
        sys.exit()
コード例 #7
0
def login_user(usern, passw):
    return User.confirm_user(usern, passw)
コード例 #8
0
def check_username_exists(usern):
    return User.find_user(usern)
コード例 #9
0
def create_new_account(username, password):
    new_account = User(username, password)
    return new_account
コード例 #10
0
class user_test(unittest.TestCase):
    """
    Test class that defines test cases for the userData class behaviors
    Args:
    unittest.TestCase:TestCase class that helps in creating test cases
    """
    def test_init(self):
        """
        test init test case to test if the object is initialised properly
        """
        self.assertEqual(self.new_user.username, "username")
        self.assertEqual(self.new_user.password, "password")

    def setUp(self):
        """
		set up method to run each test case
		"""
        self.new_user = User("username", "password")

    def test_create_new_account(self):
        """
		test create new account test case to test if the new user object is saved into the user list
		"""
        self.new_user.save_user()
        self.assertEqual(len(User.user_list), 1)

    def tearDown(self):
        """
    	tearDown() method that does clean up after each test case has run
		"""
        User.user_list = []

    def test_check_user_exists(self):
        """
        test check user exists to test if a user exists or not
        """
        self.test_user = User("username", "password1")
        self.test_user.save_user()
        found_user = User.find_user("username")
        self.assertTrue(found_user)

    def test_username_match_password(self):
        """
        test usename match password to test if an entered username matches the password
        """
        self.test_user = User("username", "password1")
        self.test_user.save_user()
        confirm_user_exist = User.confirm_user("username", "password1")
        self.assertTrue(confirm_user_exist)

    def test_user_change_pass(self):
        """
        test user change password test case to test if a user can be able to change their password test_create_new_account
        """
        test_u = User("username", "password1")
        test_u.save_user()
        change_pass = test_u.change_userpass("username", "password")
        self.assertEqual(change_pass.password, "password")

    def test_user_delete_account(self):
        """
        test user_delete_account to test if a user can be able to delete their account
        """
        self.test_user = User("username", "password1")
        self.test_user.save_user()
        self.test_user.user_delete_account()
        self.assertEqual(len(User.user_list), 0)
コード例 #11
0
    def setUp(self):
        """
		set up method to run each test case
		"""
        self.new_user = User("username", "password")