Пример #1
0
def test_handle_default_request_valid_response(
        valid_request,
        assert_valid_response
):
    request = zlib.compress(json.dumps(valid_request).encode(ENCODING))
    z_response = handle_default_request(request)
    response = json.loads(zlib.decompress(z_response).decode(ENCODING))

    for name, value in response.items():
        if name != 'time':
            assert assert_valid_response.get('name') == response.get('name')
            client, address = sock.accept()
            logging.info(f'Client was detected {address[0]}:{address[1]}')
            connections.append(client)
        except:
            pass

        rlist, wlist, xlist = select.select(connections, connections,
                                            connections, 0)

        for read_client in rlist:
            read_thread = threading.Thread(target=read,
                                           args=(read_client, connections,
                                                 requests,
                                                 config.get('buffersize')))

            read_thread.start()

        if requests:
            bytes_request = requests.pop()
            bytes_response = handle_default_request(bytes_request)

            for write_client in wlist:
                write_thread = threading.Thread(target=write,
                                                args=(write_client,
                                                      connections,
                                                      bytes_response))

                write_thread.start()

except KeyboardInterrupt:
    print('Server shutdown.')
Пример #3
0
def test_handle_default_request(request):
    response = handle_default_request(zlib.compress(json.dumps(data).encode()))
    '''Test existing compressed object in result of function'''
    assert zlib.decompress(response)