with open(args.config) as file: file_config = yaml.safe_load(file) config.update(file_config or {}) host = args.host if args.host else config.get('host') port = args.port if args.port else config.get('port') buffersize = config.get('buffersize') try: sock = socket.socket() sock.bind((host, port)) sock.listen(5) print(f'Server started with {host}:{port}') action_mapping = find_server_action() while True: client, (client_host, client_port) = sock.accept() print(f'Client {client_host}:{client_port} was connected') bytes_request = client.recv(buffersize) request = json.loads(bytes_request) if validate_request(request): action = request.get('action') controller = action_mapping.get(action) if controller: try: response = controller(request)
def test_find_controllers(initial_request, expected_action): action_mapping = find_server_action() controllers = action_mapping.get(expected_action) controller = controllers(initial_request).get('action') assert expected_action == controller
def test_find_server_action(): server_actions = find_server_action() assert type(server_actions) is dict
def test_find_controllers(): action_mapping = find_server_action() controllers = action_mapping.get(ACTION) controller = controllers(REQUEST).get('action') assert ACTION == controller