Skip to content

Commit 0e793de

Browse files
matusvaloOmer Katz
authored and
Omer Katz
committed
Prevent failed checks in integration tests caused by table datatype (#216)
1 parent b4c51df commit 0e793de

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

t/integration/test_integration.py

+25-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from case import patch, call, Mock
55
from amqp import spec, Connection, Channel, sasl, Message
66
from amqp.platform import pack
7-
from amqp.serialization import dumps
7+
from amqp.serialization import dumps, loads
88

99

1010
def ret_factory(method, channel=0, args=b'', arg_format=None):
@@ -61,6 +61,19 @@ def ret_factory(method, channel=0, args=b'', arg_format=None):
6161
}
6262

6363

64+
class DataComparator(object):
65+
# Comparator used for asserting serialized data. It can be used
66+
# in cases when direct comparision of bytestream cannot be used
67+
# (mainly cases of Table type where order of items can vary)
68+
def __init__(self, argsig, items):
69+
self.argsig = argsig
70+
self.items = items
71+
72+
def __eq__(self, other):
73+
values, offset = loads(self.argsig, other)
74+
return tuple(values) == tuple(self.items)
75+
76+
6477
def handshake(conn, transport_mock):
6578
# Helper function simulating connection handshake with server
6679
transport_mock().read_frame.side_effect = [
@@ -103,18 +116,25 @@ def test_connect(self):
103116
with patch.object(conn, 'Transport') as transport_mock:
104117
handshake(conn, transport_mock)
105118
on_open_mock.assert_called_once_with(conn)
119+
security_mechanism = sasl.AMQPLAIN(
120+
'guest', 'guest'
121+
).start(conn).decode('utf-8', 'surrogatepass')
122+
106123
# Expected responses from client
107124
frame_writer_mock.assert_has_calls(
108125
[
109126
call(
110-
1, 0, spec.Connection.StartOk, dumps(
127+
1, 0, spec.Connection.StartOk,
128+
# Due Table type, we cannot compare bytestream directly
129+
DataComparator(
111130
'FsSs',
112131
(
113-
CLIENT_CAPABILITIES, b'AMQPLAIN',
114-
sasl.AMQPLAIN('guest', 'guest').start(conn),
132+
CLIENT_CAPABILITIES, 'AMQPLAIN',
133+
security_mechanism,
115134
'en_US'
116135
)
117-
), None
136+
),
137+
None
118138
),
119139
call(
120140
1, 0, spec.Connection.TuneOk,

0 commit comments

Comments
 (0)