Esempio n. 1
0
def sh_server_controller(request):
    """
    Отсанавливает сервер, требудется ввод пароля
    :param request: dict
    :return: dict
    """
    if request.get('data') == '12345':
        return make_200(request, 'Server has been shutdown', key='shd')
    else:
        raise Exception(401)
Esempio n. 2
0
def timestamp_controller(request):
    return make_200(request, datetime.now().timestamp())
Esempio n. 3
0
def echo_controller(request):
    return make_200(request, request.get('data'))
Esempio n. 4
0
def test_make_response_200(initial_request, expected_data, expected_time, code_200):
    response = make_200(initial_request, expected_data, expected_time)
    code = response.get('code')
    assert code == code_200
Esempio n. 5
0
            sock.bind((host, port))
    sock.listen(5)
    print(f'Server started with {host}:{port}')

    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 vilidate_request(request):
            action = request.get('action')
            if action == 'echo':
                try:
                    response = make_200(request, request.get('data'))
                    print(f'Request: {bytes_request.decode()}')
                except Exception as er:
                    response = make_500(request)
                    print(er)

            try:
                print(f'Request: {bytes_request.decode()}')
                # client.send(bytes_request)
                response = make_200(request, 200, request.get('data'))
                # client.send({'action': request.get("action"), 'code': 200, 'data': request.get('data')})
            except Exception as err:
                request = make_500(request)
                print(err)
        else:
            response = make_400(request, 400, 'Request is not valide')
Esempio n. 6
0
def test_make_200(initial_request, code_200, expected_data, expected_time):
    response = make_200(initial_request, expected_data, date=expected_time)
    assert response.get('code') == code_200
Esempio n. 7
0
def test_code_make_200():
    response = make_200(REQUEST, DATA, date=TIME)
    action = response.get('code')
    assert action == CODE
Esempio n. 8
0
def test_time_make_200():
    response = make_200(REQUEST, DATA, date=TIME)
    action = response.get('time')
    assert action == TIME
Esempio n. 9
0
def test_data_make_200():
    response = make_200(REQUEST, DATA, date=TIME)
    action = response.get('data')
    assert action == DATA