def test_message_use_received_packet_count(self, get_next_packet_count): connection = Connection("localhost", 30015, "Fuu", "Bar") connection.packet_count = 12345 msg = ReplyMessage(connection.session_id, connection.packet_count) assert msg.packet_count == 12345 assert not get_next_packet_count.called
def test_message_use_received_session_id(self): connection = Connection("localhost", 30015, "Fuu", "Bar") connection.session_id = 12345 msg = ReplyMessage(connection.session_id, connection.get_next_packet_count()) assert msg.session_id == 12345
def test_request_message_use_last_session_id(): connection = Connection("localhost", 30015, "Fuu", "Bar") connection.session_id = 1 msg = RequestMessage.new(connection) assert msg.session_id == connection.session_id connection.session_id = 5 assert msg.session_id == connection.session_id
def test_request_message_use_last_session_id(self): connection = Connection("localhost", 30015, "Fuu", "Bar") connection.session_id = 3 msg1 = RequestMessage.new(connection) assert msg1.session_id == connection.session_id connection.session_id = 5 msg2 = RequestMessage.new(connection) assert msg2.session_id == connection.session_id
def test_isconnected(hana_system): connection = Connection(*hana_system) assert not connection.isconnected() connection.connect() assert connection.isconnected() connection.close() assert not connection.isconnected()
def test_pack(self): connection = Connection("localhost", 30015, "Fuu", "Bar") msg = RequestMessage.new(connection, [DummySegment(None)]) payload = msg.pack() packed = payload.getvalue() assert isinstance(packed, bytes) # Session id assert packed[0:8] == b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" # Packet count assert packed[8:12] == b"\x00\x00\x00\x00" # var part length assert packed[12:16] == b"\x0A\x00\x00\x00" # var part size assert packed[16:20] == b"\xE0\xFF\x01\x00" # no of segments assert packed[20:22] == b"\x01\x00" # reserved assert packed[22:32] == b"\x00" * 10 # payload assert packed[32:42] == b"\x00" * 10
def test_request_message_init_with_multiple_segments_as_tuple(self): connection = Connection("localhost", 30015, "Fuu", "Bar") request_seg_1 = RequestSegment(0) request_seg_2 = RequestSegment(1) msg = RequestMessage.new(connection, (request_seg_1, request_seg_2)) assert msg.segments == (request_seg_1, request_seg_2)
def test_request_message_keep_packet_count(self, get_next_packet_count): connection = Connection("localhost", 30015, "Fuu", "Bar") msg = RequestMessage.new(connection) assert msg.packet_count == 0 # Check two time packet count of the message # but the get_next_packet_count method of connection # should only called once. assert msg.packet_count == 0 get_next_packet_count.assert_called_once_with()
def test_payload_pack(self, autocommit): connection = Connection("localhost", 30015, "Fuu", "Bar", autocommit=autocommit) msg = RequestMessage.new(connection, [DummySegment(None)]) payload = BytesIO() msg.build_payload(payload) assert payload.getvalue() == b"\x00" * 10
def test_setautocommit(): connection = Connection("localhost", 30015, "Fuu", "Bar") connection.setautocommit(False) assert not connection.autocommit connection.setautocommit(True) assert connection.autocommit
def connect(host, port, user, password, database=None, autocommit=False): conn = Connection(host, port, user, password, autocommit) conn.connect() if database: cur = conn.cursor() cur.execute('SET SCHEMA "{0}"'.format(schema)) if not autocommit: conn.commit() return conn
def test_reconnect_execute(hana_system): connection = Connection(*hana_system, reconnect=True) connection.connect() cursor = connection.cursor() # break connection connection_mock_timeout(connection) # try dummy query cursor.execute('''SELECT 1 FROM DUMMY''') assert connection.isconnected()
def test_message_use_received_session_id(): connection = Connection("localhost", 30015, "Fuu", "Bar") connection.session_id = 12345 msg = ReplyMessage(connection.session_id, connection.get_next_packet_count()) assert msg.session_id == 12345
def test_getautocommit(): connection = Connection("localhost", 30015, "Fuu", "Bar") assert not connection.getautocommit() connection.autocommit = True assert connection.getautocommit()
def test_request_message_init_without_segment(self): connection = Connection("localhost", 30015, "Fuu", "Bar") msg = RequestMessage.new(connection) assert msg.segments == ()
def test_set_timeout_without_socket(): connection = Connection("localhost", 30015, "Fuu", "Bar") connection.timeout = 10 assert connection.timeout == 10
def connect(host, port, user, password, autocommit=False): conn = Connection(host, port, user, password, autocommit) conn.connect() return conn
def test_socket_use_init_timeout(hana_system): connection = Connection(*hana_system, timeout=10) connection.connect() assert connection._socket.gettimeout() == 10 connection.close()
def test_set_timeout_in_init(hana_system): connection = Connection(*hana_system, timeout=10) assert connection.timeout == 10 assert connection._timeout == 10
def test_request_message_init_with_single_segment(self): connection = Connection("localhost", 30015, "Fuu", "Bar") request_seg = RequestSegment(0) msg = RequestMessage.new(connection, request_seg) assert msg.segments == (request_seg, )
def connect(*args, **kwargs): conn = Connection(*args, **kwargs) conn.connect() return conn