Esempio n. 1
0
    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)
Esempio n. 2
0
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
Esempio n. 3
0
def test_find_server_action():
    server_actions = find_server_action()
    assert type(server_actions) is dict
Esempio n. 4
0
def test_find_controllers():
    action_mapping = find_server_action()
    controllers = action_mapping.get(ACTION)
    controller = controllers(REQUEST).get('action')
    assert ACTION == controller