def test_commands_output(self): """This test deals with testing whether correct description of commands is returned by the server to client. """ commands = [ """register : To register as a new user, command:register <username> <password> \n""", """login : To login, command:login <username> <password>""", """quit : To logout, command:quit\n""", """change_folder : To change the current path, command:change_folder <name>\n""", """list : Lists all files in the current path, command:list\n""", """read_file : To read content from the file, command:read_file <name>\n""", """write_file : To write content into the file, command:write_file <name> <content>\n""", """create_folder : To create new folder, command:create_folder <name>\n""" ] expected = "".join(commands) test_user = CommandHandler() actual = test_user.commands() self.assertEqual(expected, actual)
def main(): """Thread that reads messages from the webapp.""" GoopgLogger() handler = CommandHandler() # a queue to store bundles received before the 'init' command queue = [] while 1: try: bundle = read_bundle() except struct.error as e: logger.error("Error while reading stdin: \"{}\"" " - Exit.".format(e.message)) sys.exit(1) if not handler.initialized and bundle['command'] != 'init': # send init request send_bundle({"command": "request_init"}) queue.append(bundle) else: def parse_and_send_result(b): result = handler.parse(b) if result is not None: b['result'] = result send_bundle(b) parse_and_send_result(bundle) if len(queue) > 0: for bundle in queue: parse_and_send_result(bundle) queue = []
async def handle_client(reader, writer): """This funtion acknowledges the connection from the client, acknowledges the messages from the client Parameters ---------- reader : StreamReader Reads data from the client socket writer : StreamWriter Writes data to the client socket """ client_addr = writer.get_extra_info('peername') message = f"{client_addr} is connected !!!!" print(message) commandhandler = CommandHandler() while True: data = await reader.read(4096) message = data.decode().strip() if message == 'exit': break print(f"Received {message} from {client_addr}") writer.write(str(client_request(commandhandler, message)).encode()) await writer.drain() print("Close the connection") writer.close()
def test_registration(self): """This test deals with testing whether register command is working or not! """ test_user = CommandHandler() expected = "\nSuccess! Registered test1" actual = test_user.register("test1", "17bfdsbgl") self.assertEqual(expected, actual) test_user.quit()
def test_registration_with_weak_password(self): """This test checks the registretion method sends information if the user attempts to register with a weak password """ test_user = CommandHandler() expected = "\n Password length should be more than 8 characters." actual = test_user.register("test2", "hdfgh") self.assertEqual(expected, actual) test_user.quit()
def test_quit(self): """Tests if the user able to safely quit from the system. """ test_user = CommandHandler() test_user.register("test5", "bdghkga") test_user.login("test5", "bdghkga") expected = test_user.quit() actual = "\nLogged Out" self.assertEqual(expected, actual)
def test_create_folder(self): """Tests if the user able to create a folder """ test_user = CommandHandler() test_user.register("test6", "jgldaoghgealg8014") test_user.login("test6", "jgldaoghgealg8014") expected = "\nSuccessfully created folder movies" actual = test_user.create_folder("movies") self.assertEqual(expected, actual) test_user.quit()
def test_login(self): """This test deals with testing whether a user after a proper registeration is able to login into the system or not! """ test_user = CommandHandler() test_user.register("test3", "125354nnn3883") expected = "Success test3 Logged into the system" actual = test_user.login("test3", "125354nnn3883") self.assertEqual(expected, actual) test_user.quit()
def test_login_with_wrong_password(self): """This test deals with testing when a user attempts to login with wrong password the system throws an error 'Wrong Password' """ test_user = CommandHandler() test_user.register("test4", "jsdlghosd") expected = "\nSorry, The password you entered is wrong. Please Try Again" actual = test_user.login("test4", "jsdlgholgegl") self.assertEqual(expected, actual) test_user.quit()
def test_read_non_existing_file(self): """Tests if the user is attempting to read content from non-existent file """ test_user = CommandHandler() test_user.register("test11", "hgrsbbgvngevlohbgvp0") test_user.login("test11", "hgrsbbgvngevlohbgvp0") filename = "abc.txt" test_user.read_file(filename) expected = "\nNo Such file " + filename + " exists!" actual = test_user.read_file(filename)
def __init__(self, *args, **kwargs): super(Portland, self).__init__(*args, **kwargs) self.command_handler = CommandHandler() self.discoLogger, self.discoLogFile = None, None self.init_logger() try: self.run(Config.discord_token) except discord.errors.LoginFailure: sys.exit( 'Token is incorrect. Please use one from a valid bot account on https://discord.com/developers/' )
def test_change_folder(self): """Tests if the user is attempting to move the location of the directory tree. """ test_user = CommandHandler() test_user.register("test8", "rgglherglse9421-4") test_user.login("test8", "rgglherglse9421-4") test_user.create_folder("movies") expected = "\nSuccessfully Moved to folder Root/test8\movies" actual = test_user.change_folder("movies") self.assertEqual(expected, actual) test_user.quit()
def test_create_already_existing_folder(self): """Tests if the user is attempting to create a folder which is already existing. """ test_user = CommandHandler() test_user.register("test7", "lognslb402193570") test_user.login("test7", "lognslb402193570") test_user.create_folder("movies") expected = "\nThe folder already exists!" actual = test_user.create_folder("movies") self.assertEqual(expected, actual) test_user.quit()
def test_read_file(self): """Tests if the user is attempting to read content from already existing file """ test_user = CommandHandler() test_user.register("test10", "brsgvegveiotyq39ty") test_user.login("test10", "brsgvegveiotyq39ty") test_user.write_file("z.txt", "Hello World!n") expected = "\nReading file from 0 bytes to 100 bytes\nHello World!n" actual = test_user.read_file("z.txt") self.assertEqual(expected, actual) test_user.quit()
def main(): parser = argparse.ArgumentParser(description="Audio component for ScreenCrash") parser.add_argument("--enable-ws-debug", action="store_true", help="Enables debug messages from websocket module") parser.add_argument("--no-reconnect", action="store_true", help="Do not reconnect if connection is lost") parser.add_argument("--reconnect-time", type=int, default=3000, help="Time (in ms) between disconnect and reconnection attempt. Cannot be used with --no-reconnect flag. Default 3000ms") args = parser.parse_args() if args.enable_ws_debug: websocket.enableTrace(True) cmd_handler = CommandHandler() core_connection = CoreConnection(cmd_handler.initial_message, cmd_handler.handle_message, not args.no_reconnect, args.reconnect_time) cmd_handler.set_event_handler(core_connection.send) core_connection.run() print("Shutting down audio component...")
def test_write_file(self): """Tests if the user is attempting to create and write content into a file """ test_user = CommandHandler() test_user.register("test9", "nlndgsvns") test_user.login("test9", "nlndgsvns") expected = "\nCreated and written data to file k.txt successfully" actual = test_user.write_file("k.txt", "Hello World") self.assertEqual(expected, actual) # Check also if the user able to append new data to the # existing file expected = "\nSuccess Written data to file k.txt successfully" actual = test_user.write_file("k.txt", "Hello Second World") self.assertEqual(expected, actual) test_user.quit()
import discord import os from dotenv import load_dotenv from commandhandler import CommandHandler, Command load_dotenv() # take environment variables from .env # Setup client, command handler, and get auth token client = discord.Client() token = os.environ.get('TOKEN') c_handler = CommandHandler(client) def help_func(): print('help_func') help_command = Command('help', 0, 'Usage: ;sports help', help_func) c_handler.add_command(help_command) # Called when the bot first starts up @client.event async def on_ready(): print(f'{client.user} has connected to Discord!') # Called everytime there is a new message @client.event async def on_message(message):
from commandhandler import CommandHandler from observequantum import ObserveQuantum # configuring the bot using config.json with open('config.json') as f: data = json.load(f) token = data["token"] command_prefix = data["prefix"] # add this to config.json observe_arguments = ["star", "wang"] client = discord.Client() # assigning external classes to objects ch = CommandHandler(client) oq = ObserveQuantum(observe_arguments) # command functions def test_command(message, client, args): return 'Test' def observe_command(message, client, args): """ Checks if user inputted guess matches the state of a qubit after observation. """ guess = message.content.lower() if (observe_arguments[0] in guess) or (observe_arguments[1] in guess): if oq.observed(guess) == True:
def __init__(self, host, request_handler): self.handler = CommandHandler() self.logger = logging.getLogger('http-main') HTTPServer.__init__(self, host, request_handler)
from __init__ import * from window import Window from player import Player from commandhandler import CommandHandler #(chr(ord(gch()))) p = Player( input(('\n' * 11) + (' ' * 20) + 'Please enter the player character\'s name' + ('\n' * 12) + (' ' * 32) + '> '), 2, 3, 23, 4) os.system('cls') w = Window(p) ch = CommandHandler(p, w.p3.tile_map.m, w.p1.tile_map.m) is_command_being_entered = False while True: w.p2.content[4].set_chars(f"({p.local_x}, {p.local_y})") w.Print() #Output is_command_being_entered = False t_char = chr(ord(gch())) # Input if t_char == '\r': is_command_being_entered = True w.p5.e = True while is_command_being_entered: w.Print() t_char = chr(ord(gch())) # Input returned_text = w.p5.Add_Char(0, t_char + "") if not returned_text == None:
def __init__(self, gGator): self.logger = gGator.logger self.conversionConf = gGator.conversionConf self.commandHandler = CommandHandler(gGator)
from rollhandler import RollHandler if __name__ == '__main__': client = discord.Client() rocks_db_location = os.getenv('ROCKS_DB_LOCATION', 'anathema.db') kv = KV(DB(rocks_db_location, Options(create_if_missing=True))) handlers = [ RollHandler(kv), InspireHandler(), CharacterHandler(kv), ConditionHandler() ] command_handler = CommandHandler(kv, handlers.copy()) handlers.append(command_handler) @client.event async def on_ready(): """Handles bot start""" print('We have logged in as {0.user}'.format(client)) @client.event async def on_message(message): """Entry point for all message handling""" if message.author == client.user: return for handler in handlers: