Ejemplo n.º 1
0
    def change_password_su3(sap_session, old_pwd):
        SAPTransaction.call(sap_session, CHANGE_PASSWORD_TRANSACTION)
        new_pwd = SAPLogonPwd.gen_password()

        SAPGuiElements.press_button(sap_session, CHNAGE_PWD_BUTTON_SU3)
        msg = SAPGuiElements.get_status_message(sap_session)
        if msg:
            if msg[1] in ('190', '180'):
                raise RuntimeError("Password could not be changed. {0}".format(
                    msg[2]))

        try:
            SAPGuiElements.set_text(sap_session, OLD_PWD_FIELD, old_pwd)
            SAPGuiElements.set_text(sap_session, NEW_PWD_FIELD1, new_pwd)
            SAPGuiElements.set_text(sap_session, NEW_PWD_FIELD2, new_pwd)
            SAPGuiElements.press_keyboard_keys(
                sap_session, "Enter", pysapgui.sapgui.GUI_CHILD_WINDOW1)
        except AttributeError as error:
            raise AttributeError(
                "Could not find GUI elements to change password. {0}".format(
                    str(error)))

        try:
            SAPGuiElements.get_element(sap_session,
                                       pysapgui.sapgui.GUI_CHILD_WINDOW2)
            SAPGuiElements.press_keyboard_keys(
                sap_session, "Enter", pysapgui.sapgui.GUI_CHILD_WINDOW2)
            SAPGuiElements.press_keyboard_keys(
                sap_session, "F12", pysapgui.sapgui.GUI_CHILD_WINDOW1)
        except AttributeError:
            # All is Ok. Password changed successfully
            return new_pwd
        else:
            raise AttributeError(
                "Couldn't set new password. Reconfigure password policy")
Ejemplo n.º 2
0
    def create_new_session(sid, user, pwd, client=None, langu=None, close_conn=False, change_pwd=True):
        conn_descr = SAPLogonINI.get_connect_name_by_sid(sid)
        if not conn_descr:
            raise ValueError("Connection to '{0}' not found".format(sid))

        sap_session = SAPNewSession.get_new_session_by_name(conn_descr)
        if sap_session:
            if user:
                SAPGuiElements.set_text(sap_session, USERNAME_FIELD, user)
            if pwd:
                SAPGuiElements.set_text(sap_session, PASSWORD_FIELD, pwd)
            if client:
                SAPGuiElements.set_text(sap_session, CLIENT_FIELD, client)
            if langu:
                SAPGuiElements.set_text(sap_session, LANGUAGE_FIELD, langu)

            SAPGuiElements.press_keyboard_keys(sap_session, "Enter")

            msg = SAPGuiElements.get_status_message(sap_session)
            if msg and msg[0] == "E":
                SAPGuiElements.press_keyboard_keys(sap_session, "Shift+F3")
                raise RuntimeError("Could not log to the SAP server. {0}".format(msg[2]))

            SAPNewSession.is_already_logon_window(sap_session)
            return_pwd = SAPLogonPwd.is_change_password_window_while_connect(sap_session, change_pwd=change_pwd)
            SAPNewSession.close_new_windows_while_connect(sap_session)
            if close_conn:
                SAPExistedSession.close_session(sap_session)

            return return_pwd
Ejemplo n.º 3
0
    def __set_table_name(self, session):
        SAPGuiElements.set_text(session, TABLENAME_FIELD, self.table_name)
        SAPGuiElements.press_keyboard_keys(session, "Enter")
        gui_msg = SAPGuiElements.get_status_message(session)

        if gui_msg:
            if gui_msg[1] == "402":
                msg = "Table '{0}' not found. GUI Message: {1}".format(self.table_name, gui_msg)
                raise ValueError(msg)
            elif gui_msg[1] == "419":
                msg = "Not authorized to view the '{0}' table. GUI Message: {1}".format(self.table_name, gui_msg[2])
                raise PermissionError(msg)
Ejemplo n.º 4
0
    def __set_report_and_execute(self, sap_session):
        SAPGuiElements.set_text(sap_session, PROGRAM_FIELD, self.report_name)
        SAPGuiElements.press_keyboard_keys(sap_session, "F8")
        gui_msg = SAPGuiElements.get_status_message(sap_session)

        if gui_msg:
            if gui_msg[1] == "017":
                msg = "Wrong report name '{0}'. GUI Message: {1}".format(self.report_name, gui_msg[2])
                raise ValueError(msg)

            elif gui_msg[1] == "322":
                msg = "Not authorized to execute '{0}' report. GUI Message: {1}".format(self.report_name, gui_msg[2])
                raise PermissionError(msg)
Ejemplo n.º 5
0
    def __execute_and_return_entries_number(self, session):
        SAPGuiElements.press_keyboard_keys(session, "F8")
        gui_msg = SAPGuiElements.get_status_message(session)

        if gui_msg and gui_msg[1] == "485":
            msg = "Not authorized to analyze privileges. GUI Message: {0}".format(
                gui_msg[2])
            raise PermissionError(msg)
        elif gui_msg and gui_msg[1] == "265":
            return 0
        elif hasattr(self, "save_to_file") and self.save_to_file:
            filename = self.save(session)
            self.comment = '=HYPERLINK("{0}", "more details")'.format(filename)

        grid = SAPAlvGrid(session, REPORT_GRID)
        grid_num = grid.get_row_count()
        return grid_num
Ejemplo n.º 6
0
    def __call_transaction(sap_session, transaction, window_id=pysapgui.sapgui.GUI_MAIN_WINDOW, check_error=True):
        tcode = TRANSACTION_PREFIX + transaction
        SAPGuiElements.set_text(sap_session, TRANSACTION_TEXT_FIELD.format(window=window_id), tcode)
        SAPGuiElements.press_keyboard_keys(sap_session, "Enter")

        if not check_error:
            return
        gui_msg = SAPGuiElements.get_status_message(sap_session)

        if gui_msg:
            if gui_msg[1] == "343":
                msg = "Wrong transaction name '{0}'. GUI Message: {1}".format(transaction, gui_msg[2])
                raise ValueError(msg)

            elif gui_msg[1] == "077":
                msg = "Not authorized to execute '{0}' transaction. GUI Message: {1}".format(transaction, gui_msg[2])
                raise PermissionError(msg)

            elif gui_msg[1] == "410":
                msg = "Blocked action in '{0}' transaction. GUI Message: {1}".format(transaction, gui_msg[2])
                raise PermissionError(msg)