def test_execute_command_with_wrong_arguments(self): command_test = "define_new_group(wrong_argument=any_value)" i = interpreter() result = interpreter.execute(i, command_test) assert result == ("PARSER: Wrong arguments in command.")
def __init__(self, console_id, is_active): try: print('Please identify yourself.') username = input('Username: '******'Password: '******'\n') exit(2) db_driver = dataBaseDriver.dataBaseDriver('localhost', username, password, 'accontrol') try: info = db_driver.retrieve_info_from_username(username)[0] except IndexError as iderr: print('ERROR: ' + iderr.args) exit(1) except UnboundLocalError as uberr: print('ERROR: ' + uberr.args) exit(1) else: self.current_user = accessControlUser.acsuser( info.get('name'), info.get('MAC'), username, password) self.is_active = is_active self.id = console_id self.interpreter = interpreter.interpreter() self.interpreter.login(username, password) self.logger = logger.acsLogger() self.logger.set_warning()
def test_execute_nonexistent_command(self): command_test = "unexistent_command(args_dont_matter)" i = interpreter() result = interpreter.execute(i, command_test) assert result == ("PARSER: Command does not exist.")
def test_execute_invalid_command(self): command_test = "Commands cannot be written anyway" i = interpreter() result = interpreter.execute(i, command_test) assert result == ("PARSER: Invalid command.")
def test_parse_argless_command(self): command_test = "check_access()" i = interpreter() result = interpreter.parse_command(i, command_test) assert result == ("check_access", None)
def test_normal_user_cannot_run(self): command_test = "normal user cannot run commands written anyway" user_test = acs_module.acsuser("", "", "normal_user", "") i = interpreter() i.current_user = user_test result = interpreter.user_can_run(i, command_test) assert result == False
def test_normal_user_can_run(self): command_test = "retrieve_description_from_group" user_test = acs_module.acsuser("", "", "normal_user", "") i = interpreter() i.current_user = user_test result = interpreter.user_can_run(i, command_test) assert result == True
def test_user_can_run_as_root(self): command_test = "root can run command written in any way" user_test = acs_module.acsuser("", "", "root", "") i = interpreter() i.current_user = user_test result = interpreter.user_can_run(i, command_test) assert result == True
def test_print_command_table_as_normal_user(self): user_test = acs_module.acsuser("", "", "normal_user", "") i = interpreter() i.current_user = user_test result = interpreter.print_command_table(i) assert result == ("check_access ()\n" + "retrieve_description_from_group (number)\n" + "retrieve_my_info ()\n")
def test_parse_valid_command(self): command_test = "define_new_group(number=1,description=test)" i = interpreter() result = interpreter.parse_command(i, command_test) assert result == ("define_new_group", { "number": "1", "description": "test" })
def test_execute_valid_command(self, exc_mock): exc_inst = mock.MagicMock() exc_inst.execute.return_value = "Mocked output" # pretty print output user_test = acs_module.acsuser("", "", "root", "") command_test = "define_new_group(number=1,description=test)" #just a valid command for parsing to complete i = interpreter() i.current_user = user_test i.command_executer = exc_inst result = interpreter.execute(i, command_test) assert result == ("Mocked output")
def test_print_command_table_as_root(self): user_test = acs_module.acsuser("", "", "root", "") i = interpreter() i.current_user = user_test result = interpreter.print_command_table(i) assert result == ( "add_user_info (name, username, password, MAC)\n" + "change_group_description (description, number)\n" + "check_access ()\n" + "define_new_group (number, description)\n" + "edit_user (name, username, password, group_number, MAC)\n" + "give_access (group_number, facility_name)\n" + "insert_new_facility (name)\n" + "insert_new_user (name, MAC, username, password)\n" + "remove_access (group_number, facility_name)\n" + "remove_facility (name)\n" + "remove_group (number)\n" + "remove_user (MAC, username)\n" + "retrieve_all_users ()\n" + "retrieve_description_from_group (number)\n" + "retrieve_info_from_username (username)\n" + "retrieve_my_info ()\n")
def __init__(self): self.GUI_interpreter = interpreter.interpreter()