コード例 #1
0
 def test_isGameOver(self):
     userPiecesRepository = Repository()
     userPiecesRepository.add(Piece(0, 0))
     userPiecesRepository.add(Piece(1, 1))
     userPiecesRepository.add(Piece(2, 2))
     userPiecesRepository.add(Piece(3, 3))
     userPiecesRepository.add(Piece(4, 4))
     aiPiecesRepository = Repository()
     validator = Validator(userPiecesRepository, aiPiecesRepository)
     userPiecesService = UserService(userPiecesRepository, validator)
     aiPiecesService = AIService(aiPiecesRepository, userPiecesRepository,
                                 validator)
     gameService = GameService(userPiecesService, aiPiecesService)
     self.assertEqual(gameService.isGameOver(), True)
     userPiecesRepository = Repository()
     userPiecesRepository.add(Piece(0, 0))
     userPiecesRepository.add(Piece(1, 1))
     userPiecesRepository.add(Piece(3, 3))
     userPiecesRepository.add(Piece(4, 4))
     aiPiecesRepository = Repository()
     validator = Validator(userPiecesRepository, aiPiecesRepository)
     userPiecesService = UserService(userPiecesRepository, validator)
     aiPiecesService = AIService(aiPiecesRepository, userPiecesRepository,
                                 validator)
     gameService = GameService(userPiecesService, aiPiecesService)
     self.assertEqual(gameService.isGameOver(), False)
コード例 #2
0
ファイル: test_validate.py プロジェクト: ysp0606/widdler
class ValidatorUnitTestsBad(unittest.TestCase):
    """
    This test class tests good inputs only. A separate one for bad inputs is below.
    """
    @classmethod
    def setUpClass(self):
        resources = c.resource_dir
        self.logger = logging.getLogger('test_validator')
        hdlr = logging.FileHandler(
            os.path.join(c.log_dir, 'test_validator.log'))
        formatter = logging.Formatter(
            '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        hdlr.setFormatter(formatter)
        self.logger.addHandler(hdlr)
        self.logger.setLevel(logging.INFO)
        self.wdl = os.path.join(resources, 'test.wdl')
        self.json = os.path.join(resources, 'bad.json')
        self.validator = Validator(wdl=self.wdl, json=self.json)
        self.logger.info('Starting Validator tests...')
        self.wdl_args = self.validator.get_wdl_args()
        self.json_args = self.validator.get_json()

    def test_validate_param_json(self):
        self.logger.info("Testing validate_param_json...")
        ref_dict = {
            "gatk.samples_file":
            "/cil/shed/sandboxes/amr/dev/gatk_pipeline/data/pfal_5.tsv"
        }
        for k, v in self.json_args.items():
            self.assertIs(self.validator.validate_param(k, ref_dict), False)

    @classmethod
    def tearDownClass(self):
        self.logger.info("Test done!")
コード例 #3
0
 def getDataset(self):
     QApplication.instance().processEvents()
     Validator.validateFilePath(self.inputFilePath)
     dataset = Dataset(self.inputFilePath, self.responseVariable, self.predictors, self.categoricalVariables)   
     dataset.validateVariableLists()
     dataset.preprocessDataset(self.standardize)
     return dataset
コード例 #4
0
 def execute_script(self):
     script_path = self.script_name.replace('.py', '')
     self.stop_button.setEnabled(True)
     self.run_button.setEnabled(False)
     self.validator = Validator(self.script_timeout.value(), script_path,
                                self.progress_terminal)
     self.validator.validate()
     self.stop_script()
コード例 #5
0
 def __init__(self, clientController, movieController, rentalController, undoStack, commandsStack, redoStack, undoRunner) -> None:
     self.printer = Printer()
     self.validator = Validator()
     self.constants = Constants()
     self.clientController = clientController
     self.movieController = movieController
     self.rentalController = rentalController
     self.undoStack = undoStack
     self.commandsStack = commandsStack
     self.redoStack = redoStack
     self.undoRunner = undoRunner
コード例 #6
0
    def save_payment_data(self, holder_name: str, card_number: str,
                          security_code: str) -> Response:
        """ Validate the user's payment data as a PaymentData object

        If the required fields are validated then process the information as a
        PaymentData object and store it in the Reservation

        :param holder_name: the name of the Card Holder, it doesn't need to be the same as the user's full name
        :param card_number: the card identification number << VALIDATED >>
        :param security_code: the card CVV << VALIDATED >>
        :return: Response code to notify the UI of the status of the Reservation object
        """

        response = Response.INVALID_PAYMENT_DATA
        if Validator.validate_payment_data(holder_name, card_number,
                                           security_code):
            self._payment_data = self._process_payment_data(
                user_name=holder_name,
                card_number=card_number,
                security_code=security_code,
                credit_card_type=self._payment_method)

            response = Response.RESERVATION_DATA_UPDATED

        return response
コード例 #7
0
ファイル: test_validate.py プロジェクト: ysp0606/widdler
 def setUpClass(self):
     resources = c.resource_dir
     self.logger = logging.getLogger('test_validator')
     hdlr = logging.FileHandler(
         os.path.join(c.log_dir, 'test_validator.log'))
     formatter = logging.Formatter(
         '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
     hdlr.setFormatter(formatter)
     self.logger.addHandler(hdlr)
     self.logger.setLevel(logging.INFO)
     self.wdl = os.path.join(resources, 'test.wdl')
     self.json = os.path.join(resources, 'test.json')
     self.validator = Validator(wdl=self.wdl, json=self.json)
     self.logger.info('Starting Validator tests...')
     self.wdl_args = self.validator.get_wdl_args()
     self.json_args = self.validator.get_json()
コード例 #8
0
def test_validate_billing_data_correct(default_user: User):
    """ Test case to check the validate_billing_data function with correct conditions


    EXPECTED BEHAVIOUR:
        Variables in given User instance match the checked regular expressions and return True
    """
    assert Validator.validate_billing_data(default_user) is True
コード例 #9
0
def validate(allOpt: bool, install: bool, dialog: bool, talk: bool,
             verbose: int):
    """
	This is the Command Line Interface of the JsonValidator for all Modules
	of Project Alice. Currently the following commands are supported.
	"""
    if allOpt:
        install = dialog = talk = True
    if True in {install, dialog, talk}:
        valid = Validator(installer=install,
                          dialog=dialog,
                          talk=talk,
                          verbosity=verbose)
        error = valid.validate()
        valid.printResult()
        sys.exit(error)
    else:
        click.echo(click.get_current_context().get_help())
コード例 #10
0
def test_validate_billing_data_error(default_user: User):
    """ Test case to check the validate_billing_data function with error conditions


    EXPECTED BEHAVIOUR:
        Variables in given User instance don't match the checked regular expressions and return False
    """

    default_user.dni = '123A'
    assert Validator.validate_billing_data(default_user) is False
コード例 #11
0
 def __init__(self) -> None:
     super().__init__()
     userPiecesRepository = Repository()
     aiPiecesRepository = Repository()
     validator = Validator(userPiecesRepository, aiPiecesRepository)
     userPiecesService = UserService(userPiecesRepository, validator)
     aiPiecesService = AIService(aiPiecesRepository, userPiecesRepository,
                                 validator)
     gameService = GameService(userPiecesService, aiPiecesService)
     self.console = Console(userPiecesService, aiPiecesService, gameService)
コード例 #12
0
ファイル: widdler.py プロジェクト: ysp0606/widdler
def call_validate(args):
    """
    Calls the Validator to validate input json. Exits with feedback to user regarding errors in json or reports no
    errors found.
    :param args: validation subparser arguments.
    :return:
    """
    logger.info("Validation requested.")
    validator = Validator(wdl=args.wdl, json=args.json)
    result = validator.validate_json()
    if len(result) != 0:
        e = "{} input file contains the following errors:\n{}".format(args.json, "\n".join(result))
        # This will also print to stdout so no need for a print statement
        logger.critical(e)
        sys.exit(1)
    else:
        s = 'No errors found in {}'.format(args.wdl)
        print(s)
        logger.info(s)
コード例 #13
0
def test_validate_payment_data(default_payment_data):
    """ Test case to check the validate_payment_data function


    EXPECTED BEHAVIOUR:
        Variables in given PaymentData instance match the checked regular expressions and return False
    """

    assert Validator.validate_payment_data(
        default_payment_data.user_name, default_payment_data.card_number,
        default_payment_data.security_code) is True
コード例 #14
0
 def test_addPieceToBlock(self):
     userPiecesRepository = Repository()
     userPiecesRepository.add(Piece(0, 0))
     userPiecesRepository.add(Piece(1, 1))
     userPiecesRepository.add(Piece(2, 2))
     userPiecesRepository.add(Piece(3, 3))
     aiPiecesRepository = Repository()
     validator = Validator(userPiecesRepository, aiPiecesRepository)
     aiPiecesService = AIService(aiPiecesRepository, userPiecesRepository,
                                 validator)
     aiPiecesService.addPiece()
     self.assertEqual(aiPiecesService.getList(), [Piece(4, 4)])
コード例 #15
0
 def test_addBestPlayPiece(self):
     userPiecesRepository = Repository()
     aiPiecesRepository = Repository()
     aiPiecesRepository.add(Piece(0, 0))
     aiPiecesRepository.add(Piece(1, 1))
     validator = Validator(userPiecesRepository, aiPiecesRepository)
     aiPiecesService = AIService(aiPiecesRepository, userPiecesRepository,
                                 validator)
     aiPiecesService.addPiece()
     self.assertEqual(
         aiPiecesService.getList(),
         [Piece(0, 0), Piece(1, 1), Piece(2, 2)])
コード例 #16
0
 def test_isValid(self):
     repository1 = Repository()
     repository1.add(Piece(0, 0))
     repository1.add(Piece(1, 1))
     repository2 = Repository()
     repository2.add(Piece(13, 13))
     repository2.add(Piece(14, 14))
     validator = Validator(repository1, repository2)
     self.assertTrue(validator.isValid(Piece(3, 3)))
     self.assertTrue(validator.isValid(Piece(3, 8)))
     self.assertFalse(validator.isValid(Piece(-1, 5)))
     self.assertFalse(validator.isValid(Piece(-1, -9)))
     self.assertFalse(validator.isValid(Piece(21, 5)))
     self.assertFalse(validator.isValid(Piece(1, 55)))
     self.assertFalse(validator.isValid(Piece(0, 0)))
     self.assertFalse(validator.isValid(Piece(14, 14)))
コード例 #17
0
    def save_payment_method(self, payment_method: str) -> Response:
        """ Validate and save the user's preferred payment method

        If the payment method selected by the user is valid then store it in the Reservation

        :param payment_method: a string containing the user's payment method, can be VISA or MASTERCARD << VALIDATED >>
        :return: Response code to notify the UI of the status of the Reservation object
        """

        response = Response.INVALID_PAYMENT_METHOD
        if Validator.validate_credit_card_type(payment_method):
            self._payment_method = payment_method
            response = Response.RESERVATION_DATA_UPDATED

        return response
コード例 #18
0
 def test_addPiece(self):
     repository1 = Repository()
     repository1.add(Piece(0, 0))
     repository1.add(Piece(1, 1))
     repository2 = Repository()
     repository2.add(Piece(13, 13))
     repository2.add(Piece(14, 14))
     validator = Validator(repository1, repository2)
     userService = UserService(repository1, validator)
     userService.addPiece(5, 5)
     self.assertEqual(
         userService.getList(),
         [Piece(0, 0), Piece(1, 1), Piece(5, 5)])
     with self.assertRaises(ValidException):
         userService.addPiece(0, 0)
     with self.assertRaises(ValidException):
         userService.addPiece(13, 13)
     with self.assertRaises(ValidException):
         userService.addPiece(-1, 0)
     with self.assertRaises(ValidException):
         userService.addPiece(0, 199)
コード例 #19
0
    def save_billing_data(self, full_name: str, dni: str, address: str,
                          mobile_number: str, email: str) -> Response:
        """ Validate the user's billing data and store the data as a User object

        Creates a User object and validates it's data through Validator, if the required
        fields are valid then the user object is stored in the Reservation

        :param full_name: the full name of the user
        :param dni: the DNI (Spanish national identity document) number << VALIDATED >>
        :param address: the address of the user
        :param mobile_number: the user's mobile number << VALIDATED >>
        :param email: the user's email << VALIDATED >>
        :return: Response code to notify the UI of the status of the Reservation object
        """

        response = Response.INVALID_BILLING_DATA
        usr = User(full_name, dni, address, mobile_number, email)
        if Validator.validate_billing_data(usr):
            self._user = copy.deepcopy(usr)
            response = Response.RESERVATION_DATA_UPDATED

        return response
コード例 #20
0
def test_validate_payment_info():
    """ Test case to check all the private functions of Validator with correct conditions


    EXPECTED BEHAVIOUR:
        The given variables match the checked regular expressions and return True
    """

    name = 'This Is a Good Test'
    dni = '12345678A'
    email = '*****@*****.**'
    mobile_number = '123456789'
    card_number = '1234 3456 5678 7890'
    security_code = '123'
    credit_card_type = ['VISA', 'MASTERCARD']

    assert Validator._validate_full_name(name) is not None
    assert Validator._validate_full_name(name) is True
    assert Validator._validate_dni(dni) is not None
    assert Validator._validate_dni(dni) is True
    assert Validator._validate_email(email) is not None
    assert Validator._validate_email(email) is True
    assert Validator._validate_mobile_number(mobile_number) is not None
    assert Validator._validate_mobile_number(mobile_number) is True
    assert Validator._validate_credit_card_number(card_number) is not None
    assert Validator._validate_credit_card_number(card_number) is True
    assert Validator._validate_credit_security_code(security_code) is not None
    assert Validator._validate_credit_security_code(security_code) is True
    assert Validator.validate_credit_card_type(credit_card_type[0]) is True
    assert Validator.validate_credit_card_type(credit_card_type[1]) is True
コード例 #21
0
def test_validate_payment_info_error():
    """ Test case to check all the private functions of Validator with error conditions


    EXPECTED BEHAVIOUR:
        The given variables don't match the checked regular expressions and return False
    """

    name = "7his_1s-a Bad 7est"
    dni = '2EFC678A9'
    email = 'bad@e/mail@test uab'
    mobile_number = '123a56aa'
    card_number = '4568 98761 234 5698'
    security_code = 'a56'
    credit_card_type = 'EXPRESS'

    assert Validator._validate_full_name(name) is not None
    assert Validator._validate_full_name(name) is False
    assert Validator._validate_dni(dni) is not None
    assert Validator._validate_dni(dni) is False
    assert Validator._validate_email(email) is not None
    assert Validator._validate_email(email) is False
    assert Validator._validate_mobile_number(mobile_number) is not None
    assert Validator._validate_mobile_number(mobile_number) is False
    assert Validator._validate_credit_card_number(card_number) is not None
    assert Validator._validate_credit_card_number(card_number) is False
    assert Validator._validate_credit_security_code(security_code) is not None
    assert Validator._validate_credit_security_code(security_code) is False
    assert Validator.validate_credit_card_type(credit_card_type[0]) is False
コード例 #22
0
ファイル: test_validate.py プロジェクト: ysp0606/widdler
class ValidatorUnitTests(unittest.TestCase):
    """
    This test class tests good inputs only. A separate one for bad inputs is below.
    """
    @classmethod
    def setUpClass(self):
        resources = c.resource_dir
        self.logger = logging.getLogger('test_validator')
        hdlr = logging.FileHandler(
            os.path.join(c.log_dir, 'test_validator.log'))
        formatter = logging.Formatter(
            '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        hdlr.setFormatter(formatter)
        self.logger.addHandler(hdlr)
        self.logger.setLevel(logging.INFO)
        self.wdl = os.path.join(resources, 'test.wdl')
        self.json = os.path.join(resources, 'test.json')
        self.validator = Validator(wdl=self.wdl, json=self.json)
        self.logger.info('Starting Validator tests...')
        self.wdl_args = self.validator.get_wdl_args()
        self.json_args = self.validator.get_json()

    def test_validate_gs_url(self):
        sb = SingleBucket("broad-cil-devel-bucket")
        foo = open("validation_test.txt", "w")
        foo.write("test")
        foo.close()
        sb.upload_file("validation_test.txt", "validation_test.txt")
        result = self.validator.validate_gs_url(
            "gs://broad-cil-devel-bucket/broad-file-inputs/validation_test.txt"
        )
        self.assertTrue(result)

    def test_get_wdl_args(self):
        self.assertIsInstance(self.wdl_args, dict)

    def test_get_json(self):
        self.logger.info("Testing get_json...")
        self.assertIsInstance(self.json_args, dict)

    def test_validate_param_json(self):
        self.logger.info("Testing validate_param_json...")
        for k, v in self.json_args.items():
            if not self.validator.validate_param(k, self.wdl_args):
                print(k, v)

            self.assertIs(self.validator.validate_param(k, self.wdl_args),
                          True)

    def test_validate_string(self):
        self.logger.info("Testing validate_string...")
        self.assertIs(self.validator.validate_string('foo'), True)
        self.assertIs(self.validator.validate_string(0), False)
        self.assertIs(self.validator.validate_string(1.0), False)
        self.assertIs(self.validator.validate_string(True), False)

    def test_validate_boolean(self):
        self.logger.info("Testing validate_boolean...")
        self.assertIs(self.validator.validate_boolean('foo'), False)
        self.assertIs(self.validator.validate_boolean(0), False)
        self.assertIs(self.validator.validate_boolean(1.0), False)
        self.assertIs(self.validator.validate_boolean(True), True)

    def test_validate_int(self):
        self.logger.info("Testing validate_int...")
        self.assertIs(self.validator.validate_int('foo'), False)
        self.assertIs(self.validator.validate_int(0), True)
        self.assertIs(self.validator.validate_int(1.0), False)
        self.assertIs(self.validator.validate_int(True), True)

    def test_validate_float(self):
        self.logger.info("Testing validate_float...")
        self.assertIs(self.validator.validate_float('foo'), False)
        self.assertIs(self.validator.validate_float(0), False)
        self.assertIs(self.validator.validate_float(1.0), True)
        self.assertIs(self.validator.validate_float(True), False)

    def test_validate_file(self):
        self.assertIs(self.validator.validate_file(self.wdl), True)
        self.assertIs(self.validator.validate_file('notexists.txt'), False)

    def test_validate_samples_array(self):
        samples_array = [['S1', self.wdl], ['S2', self.json],
                         ['S3', 'not_exists.txt']]
        result = self.validator.validate_samples_array(samples_array)
        self.assertEqual(1, len(result))

    def test_validate_json(self):
        self.validator.validate_json()

    @classmethod
    def tearDownClass(self):
        self.logger.info("Test done!")
コード例 #23
0
class RunnerWidget(QWidget):
    def __init__(self, project=None):
        super().__init__()
        self.setWindowTitle("Runner")
        self.setGeometry(50, 50, 482, 432)
        self.UI()
        self.show()
        self.script_name = None

    def UI(self):
        # Grid layout
        self.gridLayout = QGridLayout(self)
        self.gridLayout.setObjectName(u"gridLayout")

        # Script display window
        self.script_display = QPlainTextEdit()
        self.script_display.setGeometry(QtCore.QRect(10, 40, 381, 471))
        self.script_display.setReadOnly(True)

        # Load Script onto display window button/action
        self.load_script_button = QtWidgets.QPushButton(self)
        self.load_script_button.setGeometry(QtCore.QRect(370, 480, 151, 41))
        self.load_script_button.setObjectName("load_script_button")
        self.load_script_button.clicked.connect(self.display_script)

        # Script run button/script execution
        self.run_button = QtWidgets.QPushButton(self)
        self.run_button.setGeometry(QtCore.QRect(700, 520, 75, 23))
        self.run_button.setObjectName("run_button")
        self.run_button.clicked.connect(self.execute_script)
        self.run_button.setEnabled(False)

        # Script stop button/stop script execution
        self.stop_button = QtWidgets.QPushButton(self)
        self.stop_button.setGeometry(QtCore.QRect(620, 520, 75, 23))
        self.stop_button.setObjectName("stop_button")
        self.stop_button.clicked.connect(self.stop_script)
        self.stop_button.setEnabled(False)

        # Progress terminal
        self.progress_terminal = QtWidgets.QTextEdit()
        self.progress_terminal.setGeometry(QtCore.QRect(400, 40, 381, 471))
        self.progress_terminal.setObjectName("progress_terminal")

        # Timeout
        self.script_timeout = QtWidgets.QSpinBox(self)
        self.script_timeout.setGeometry(QtCore.QRect(370, 450, 151, 22))
        self.script_timeout.setMinimum(1)
        self.script_timeout.setObjectName("script_timeout")

        # Widget layout
        self.gridLayout.addWidget(self.progress_terminal, 1, 3)
        self.gridLayout.addWidget(self.script_timeout, 2, 3)
        self.gridLayout.addWidget(self.run_button, 0, 3)
        self.gridLayout.addWidget(self.stop_button, 3, 3)
        self.gridLayout.addWidget(self.load_script_button, 0, 0)
        self.gridLayout.addWidget(self.script_display, 1, 0)
        self.setLayout(self.gridLayout)
        self.retranslateUi()

    def retranslateUi(self):
        _translate = QtCore.QCoreApplication.translate
        self.setWindowTitle(_translate("RunnerTab", "Runner"))
        self.load_script_button.setText(_translate("RunnerTab", "Load Script"))
        self.run_button.setText(_translate("RunnerTab", "Run"))
        self.stop_button.setText(_translate("RunnerTab", "Stop"))

    # Creates an instance of the validator that executes the scripts along with ECELd for verification
    def execute_script(self):
        script_path = self.script_name.replace('.py', '')
        self.stop_button.setEnabled(True)
        self.run_button.setEnabled(False)
        self.validator = Validator(self.script_timeout.value(), script_path,
                                   self.progress_terminal)
        self.validator.validate()
        self.stop_script()

    # Displays string text on right window
    def print_progress(self, text):
        cursor = self.progress_terminal.textCursor()
        cursor.movePosition(cursor.End)
        cursor.insertText(text)

    # Prints to the program that the process has stopped
    def stop_script(self):
        self.validator.stop()
        self.validator = None
        self.print_progress("Program stopped\n")
        self.stop_button.setEnabled(False)
        self.run_button.setEnabled(True)

    # Loads python file contents onto the left window
    def display_script(self):
        try:
            options = QFileDialog.Options()
            options |= QFileDialog.DontUseNativeDialog
            self.script_name, _ = QFileDialog.getOpenFileName(
                self,
                "Open Script",
                "",
                "Python Files (*.py)",
                options=options)
            # Check if it's a valid script
            validator_check = Path(
                self.script_name.replace(".py", "Validator.json"))
            if validator_check.exists():
                with open(self.script_name, 'r') as f:
                    self.script_display.setPlainText(f.read())
                self.run_button.setEnabled(True)
                self.progress_terminal.clear()
            else:
                self.script_name = None
                self.invalid_script_message()
        except Exception as e:
            pass

    # Notifies user if they try to load an invalid script
    def invalid_script_message(self):
        messageBox = QMessageBox()
        messageBox.setWindowTitle("Error")
        messageBox.setText(
            "Invalid script selected. Please select a script generated by the Builder."
        )
        messageBox.exec()
コード例 #24
0
class Console:

    def __init__(self, clientController, movieController, rentalController, undoStack, commandsStack, redoStack, undoRunner) -> None:
        self.printer = Printer()
        self.validator = Validator()
        self.constants = Constants()
        self.clientController = clientController
        self.movieController = movieController
        self.rentalController = rentalController
        self.undoStack = undoStack
        self.commandsStack = commandsStack
        self.redoStack = redoStack
        self.undoRunner = undoRunner

    def run(self):
        while True:
            self.printer.printMenu("mainMenu")
            menuChosen = input(">")
            if menuChosen == "manager":
                self.__showManagerMenu()
            elif menuChosen == "rental":
                self.__showRentalMenu()
            elif menuChosen == "search":
                self.__showSearchMenu()
            elif menuChosen == "stats":
                self.__showStatsMenu()
            elif menuChosen == "exit":
                return
            else:
                print("Wrong input!")

    def __undo(self):
        try:
            lastElement = self.commandsStack.lastElement()
            self.undoRunner.undo(self.clientController, self.movieController, self.rentalController, self.undoStack)
        except EmptyStackException:
            print("nothing to undo")
        else:
            self.redoStack.push(lastElement)
            self.commandsStack.deleteLastElement()

    def __redo(self):
        try:
            commandToRedo = self.redoStack.pop()
        except EmptyStackException:
            print("nothing to redo")
        else:
            self.undoRunner.redo(commandToRedo, self.clientController, self.movieController, self.rentalController)

    def __showManagerMenu(self):
        while True:
            self.printer.printMenu("managerMenu")
            menuChosen = input(">")
            if menuChosen == "client":
                self.__showClientManager()
            elif menuChosen == "movie":
                self.__showMovieManager()
            elif menuChosen == "back":
                break
            else:
                print("Wrong input!")

    def __showStatsMenu(self):
        while True:
            self.printer.printSubmenu("statsMenu")
            optionInput = input(">")
            optionInputWordList = optionInput.split()
            if self.validator.isValidStatsQuery(optionInputWordList):
                self.__stats(optionInputWordList)
            elif optionInputWordList[0] == "back":
                break
            else:
                print("wrong input")

    def __showSearchMenu(self):
        while True:
            self.printer.printSubmenu("searchMenu")
            optionInput = input(">")
            optionInputWordList = optionInput.split()
            if self.validator.isValidSearchQuery(optionInputWordList):
                self.__search(optionInputWordList)
            elif optionInputWordList[0] == "back":
                break
            else:
                print("wrong input")

    def __showRentalMenu(self):
        while True:
            self.printer.printSubmenu("rentalMenu")
            optionInput = input(">")
            optionInputWordList = optionInput.split()
            if optionInputWordList:
                if optionInputWordList[0] == "rent":
                    self.__rentMovie(optionInputWordList)
                elif optionInputWordList[0] == "return":
                    self.__returnMovie(optionInputWordList)
                elif optionInputWordList[0] == "list":
                    self.printer.printList(self.rentalController.getRentalList())
                elif optionInputWordList[0] == "back":
                    break
                elif optionInputWordList[0] == "undo":
                    self.__undo()
                elif optionInputWordList[0] == "redo":
                    self.__redo()
                else:
                    print("wrong input")
            else:
                print("wrong input")

    def __showMovieManager(self):
        while True:
            self.printer.printSubmenu("movieMenu")
            optionInput = input(">")
            optionInputWordList = optionInput.split()
            if optionInputWordList[0] == "list":
                self.__listMovie(optionInputWordList)
            elif optionInputWordList[0] == "remove":
                self.__removeMovie(optionInputWordList)
            elif optionInputWordList[0] == "update":
                self.__updateMovie(optionInputWordList)
            elif optionInputWordList[0] == "add":
                self.__addMovie(optionInputWordList)
            elif optionInputWordList[0] == "back":
                break
            elif optionInputWordList[0] == "undo":
                self.__undo()
            elif optionInputWordList[0] == "redo":
                self.__redo()
            else:
                print("wrong input")

    def __showClientManager(self):
        while True:
            self.printer.printSubmenu("clientMenu")
            optionInput = input(">")
            optionInputWordList = optionInput.split()
            if optionInputWordList[0] == "list":
                self.__listClient(optionInputWordList)
            elif optionInputWordList[0] == "remove":
                self.__removeClient(optionInputWordList)
            elif optionInputWordList[0] == "update":
                self.__updateClient(optionInputWordList)
            elif optionInputWordList[0] == "add":
                self.__addClient(optionInputWordList)
            elif optionInputWordList[0] == "back":
                break
            elif optionInputWordList[0] == "undo":
                self.__undo()
            elif optionInputWordList[0] == "redo":
                self.__redo()
            else:
                print("wrong input")

    def __stats(self, optionInputWordList):
        if optionInputWordList[0] == "active":
            print("Most active clients:")
            self.printer.printList(
                self.rentalController.mostActiveClients(self.clientController.getRepo()))
        elif optionInputWordList[0] == "now":
            print("Movies now rented:")
            self.printer.printList(
                self.rentalController.moviesCurrentlyRented(self.movieController.getRepo()))
        elif optionInputWordList[0] == "late":
            print("Movies most passed due date:")
            self.printer.printList(self.rentalController.moviesPastDueDate(self.movieController.getRepo()))
        elif optionInputWordList[0] == "most" and optionInputWordList[2] == "times":
            print("Most rented movies by times rented:")
            self.printer.printList(self.rentalController.moviesMostRentedByTimesRented(self.movieController.getRepo()))
        elif optionInputWordList[0] == "most" and optionInputWordList[2] == "days":
            print("Most rented movies by times rented:")
            self.printer.printList(self.rentalController.moviesMostRentedByDays(self.movieController.getRepo()))

    def __search(self, optionInputWordList):
        if optionInputWordList[2] == "name":
            self.printer.printList(self.clientController.listOfClientsWithName(optionInputWordList[3]))
        elif optionInputWordList[2] == "title":
            self.printer.printList(self.movieController.listOfMoviesWithTitle(optionInputWordList[3]))
        elif optionInputWordList[2] == "description":
            self.printer.printList(self.movieController.listOfMoviesWithDescription(optionInputWordList[3]))
        elif optionInputWordList[2] == "genre":
            self.printer.printList(self.movieController.listOfMoviesWithGenre(optionInputWordList[3]))

    def __returnMovie(self, optionInputWordList):
        if optionInputWordList[1].isdigit():
            if self.clientController.hasClientWithId(int(optionInputWordList[1])):
                if optionInputWordList[2].isdigit():
                    if self.movieController.hasMovieWithId(int(optionInputWordList[2])):
                        try:
                            self.undoRunner.addCommandToUndo(optionInputWordList, self.rentalController, self.undoStack, "rental", self.commandsStack)
                            self.__doReturn(optionInputWordList)
                        except MovieNotCurrentlyRentedByClientException:
                            print("movie with id #", optionInputWordList[2], "not rented by client with #",
                                  optionInputWordList[1])
                            self.__popUndoStacks()
                        else:
                            print("Movie with id #", optionInputWordList[2],
                                  "successfully returned by client with id #", optionInputWordList[1])
                    else:
                        print("movie with id #", optionInputWordList[2], "not found")
                else:
                    print("wrong input")
            else:
                print("client with id #", optionInputWordList[1], "not found")
        else:
            print("wrong input")

    def __popUndoStacks(self):
        self.undoStack.pop()
        self.commandsStack.pop()

    def __doReturn(self, optionInputWordList):
        self.rentalController.returnMovieByClient(int(optionInputWordList[1]),
                                                  int(optionInputWordList[2]))

    def __rentMovie(self, optionInputWordList):
        if len(optionInputWordList) == 6:
            if optionInputWordList[1].isdigit():
                if self.clientController.hasClientWithId(int(optionInputWordList[1])):
                    if optionInputWordList[2].isdigit():
                        if self.movieController.hasMovieWithId(int(optionInputWordList[2])):
                            if optionInputWordList[3].isdigit() and optionInputWordList[4].isdigit() and \
                                    optionInputWordList[5].isdigit():
                                try:
                                    dueDate = Date(int(optionInputWordList[3]),
                                                   int(optionInputWordList[4]),
                                                   int(optionInputWordList[5]))
                                except InvalidDateFormatException:
                                    print("Invalid date format")
                                else:
                                    try:
                                        self.undoRunner.addCommandToUndo(optionInputWordList, self.rentalController,
                                                                         self.undoStack, "rental", self.commandsStack)
                                        self.__doRent(dueDate, optionInputWordList)
                                    except DatesNotOrderedException:
                                        print("The due date cannot be before the rental date")
                                        self.__popUndoStacks()
                                    except ClientHasMoviesNotReturnedException:
                                        print("Client #", optionInputWordList[1], "has passed due date for movies")
                                        self.__popUndoStacks()
                                    except MovieNotAvailableException:
                                        print("Movie #", optionInputWordList[2], "is not available")
                                        self.__popUndoStacks()
                                    else:

                                        print("Movie #", optionInputWordList[2], "successfully rented by client #",
                                              optionInputWordList[1], "until", str(dueDate))
                            else:
                                print("wrong input")
                        else:
                            print("Movie with id", optionInputWordList[2], "not found")
                    else:
                        print("wrong input")
                else:
                    print("Client with id", optionInputWordList[1], "not found")
            else:
                print("wrong input")
        else:
            print("wrong input")

    def __doRent(self, dueDate, optionInputWordList):
        self.rentalController.rentMovieByClientUntilDate(int(optionInputWordList[1]),
                                                         int(optionInputWordList[2]),
                                                         dueDate,
                                                         self.movieController.getRepo(),
                                                         self.clientController.getRepo())

    def __addMovie(self, optionInputWordList):
        if len(optionInputWordList) == 4:
            self.undoRunner.addCommandToUndo(optionInputWordList, self.movieController, self.undoStack, "movie", self.commandsStack)
            self.__doAddMovie(optionInputWordList)
            print("Successfully added movie", optionInputWordList[1])
        else:
            print("wrong input")

    def __doAddMovie(self, optionInputWordList):
        self.movieController.addMovie(MovieDAO(optionInputWordList[1], optionInputWordList[2], optionInputWordList[3]))

    def __updateMovie(self, optionInputWordList):
        if self.validator.isValidUpdateQueryWithNumberOfElements(optionInputWordList, 5):
            try:
                self.undoRunner.addCommandToUndo(optionInputWordList, self.movieController, self.undoStack, "movie", self.commandsStack)
                self.__doUpdateMovie(optionInputWordList)
            except ObjectNotInCollectionException:
                print("Movie with id", optionInputWordList[1], "not found")
                self.__popUndoStacks()
            else:
                print("Successfully updated movie #", optionInputWordList[1])
        else:
            print("wrong input")

    def __doUpdateMovie(self, optionInputWordList):
        self.movieController.updateMovieWithId(int(optionInputWordList[1]),
                                               MovieDAO(optionInputWordList[2], optionInputWordList[3],
                                                        optionInputWordList[4]))

    def __removeMovie(self, optionInputWordList):
        if self.validator.isValidRemoveQuery(optionInputWordList):
            try:
                optionInputWordList.append("movie")  # caution use
                self.undoRunner.addCommandToUndo(optionInputWordList, self.movieController, self.undoStack, "movie", self.commandsStack)
                self.__doRemoveMovie(optionInputWordList)
            except ObjectNotInCollectionException:
                print("Movie with id", optionInputWordList[1], "not found")
                self.__popUndoStacks()
            except MovieCurrentlyRentedException:
                print("Movie with id #", optionInputWordList[1], "is currently rented. Couldn't delete")
                self.__popUndoStacks()
            else:
                print("Successfully removed movie #", optionInputWordList[1])
        else:
            print("wrong input")

    def __doRemoveMovie(self, optionInputWordList):
        self.movieController.removeMovieWithId(int(optionInputWordList[1]), self.rentalController.getRepo())

    def __listMovie(self, optionInputWordList):
        if len(optionInputWordList) == 1:
            self.printer.printList(self.movieController.getMovieList())
        elif len(optionInputWordList) == 2:
            try:
                if optionInputWordList[1].isdigit():
                    self.printer.printObject(self.movieController.getMovieWithId(int(optionInputWordList[1])))
                else:
                    print("wrong input")
            except ObjectNotInCollectionException:
                print("Movie with id", optionInputWordList[1], "not found")
        else:
            print("Wrong input")

    def __addClient(self, optionInputWordList):
        if len(optionInputWordList) == 2:
            self.undoRunner.addCommandToUndo(optionInputWordList, self.clientController, self.undoStack, "client", self.commandsStack)
            self.__doAddClient(optionInputWordList)
            print("Successfully added client", optionInputWordList[1])
        else:
            print("wrong input")

    def __doAddClient(self, optionInputWordList):
        self.clientController.addClient(ClientDAO(optionInputWordList[1]))

    def __updateClient(self, optionInputWordList):
        if self.validator.isValidUpdateQueryWithNumberOfElements(optionInputWordList, 3):
            try:
                self.undoRunner.addCommandToUndo(optionInputWordList, self.clientController, self.undoStack, "client", self.commandsStack)
                self.__doUpdateClient(optionInputWordList)
            except ObjectNotInCollectionException:
                print("Client with id", optionInputWordList[1], "not found")
                self.__popUndoStacks()
            else:
                print("Successfully updated client #", optionInputWordList[1])
        else:
            print("wrong input")

    def __doUpdateClient(self, optionInputWordList):
        self.clientController.updateClientWithId(int(optionInputWordList[1]),
                                                 ClientDAO(optionInputWordList[2]))

    def __removeClient(self, optionInputWordList):
        if self.validator.isValidRemoveQuery(optionInputWordList):
            try:
                optionInputWordList.append("client")  # caution use
                self.undoRunner.addCommandToUndo(optionInputWordList, self.clientController, self.undoStack, "client", self.commandsStack)
                self.__doRemoveClient(optionInputWordList)
            except ClientHasMoviesNotReturnedException:
                print("Client with id #", optionInputWordList[1], "has movies not returned. Couldn't delete")
                self.__popUndoStacks()
            except ObjectNotInCollectionException:
                print("Client with id", optionInputWordList[1], "not found")
                self.__popUndoStacks()
            else:
                print("Successfully removed client #", optionInputWordList[1])
        else:
            print("wrong input")

    def __doRemoveClient(self, optionInputWordList):
        self.clientController.removeClientWithId(int(optionInputWordList[1]), self.rentalController.getRepo())

    def __listClient(self, optionInputWordList):
        if len(optionInputWordList) == 1:
            self.printer.printList(self.clientController.getClientList())
        elif len(optionInputWordList) == 2:
            try:
                if optionInputWordList[1].isdigit():
                    self.printer.printObject(self.clientController.getClientWithId(int(optionInputWordList[1])))
                else:
                    print("wrong input")
            except ObjectNotInCollectionException:
                print("Client with id #", optionInputWordList[1], "not found")
        else:
            print("Wrong input")