Ejemplo n.º 1
0
def main():
    """
    this method is used to call main menu for login
    """
    conn = ConnectDb()
    try:
        os.system('clear')
        # select role for login
        print("login as:\n")
        menu = Menu()
        roles = [x.name for x in Role]
        roles.extend([str(BackButton.EXIT.name)])
        role = menu.draw_menu(roles)
        role_id = Role[role].value
        input()

        # get user name and password for login
        user_name = input("enter user name: ")
        password = getpass()

        # check user authentication
        result = conn.get_user_with_role(user_name, role_id)
        flag = True
        if result is not None:
            os.system('clear')
            actual_pass = decrypt_pass(result[1])
            if str(actual_pass.decode("utf-8")) == password:
                flag = False
                if role_id == int(Role.BDO.value):
                    bdo = BDO()
                    bdo.bdo_id = result[0]
                    bdo.bdo_features()
                elif role_id == int(Role.GPM.value):
                    gpm = GPM()
                    gpm.gpm_id = result[0]
                    gpm.gpm_features()
                elif role_id == int(Role.Member.value):
                    member = Member()
                    member.member_id = result[0]
                    member.member_features()
        if result is None or flag:
            print(Color.F_Red + 'wrong credentials' + Base.END)
            input()
            main()

    except Exception as e:
        print(e)
        sys.exit()
    finally:
        conn.close_conn()
Ejemplo n.º 2
0
 def test_bdo_features_exception(self, mock_print, mock_menu, mock_input,
                                 mock_getattr, mock_sys):
     gpm = GPM()
     gpm.gpm_features()
     mock_sys.exit.assert_called_once()
     self.assertEqual(mock_print.call_count, 2)