Skip to content

Commit 41d9394

Browse files
committed
Don't change blob params for assertion in C* 1.2
1 parent 8772e75 commit 41d9394

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

tests/integration/standard/test_types.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def tearDown(self):
5757

5858
def test_can_insert_blob_type_as_string(self):
5959
"""
60-
Tests that blob type in Cassandra does not map to string in Python
60+
Tests that byte strings in Python maps to blob type in Cassandra
6161
"""
6262

6363
c = Cluster(protocol_version=PROTOCOL_VERSION)
@@ -68,9 +68,7 @@ def test_can_insert_blob_type_as_string(self):
6868
params = ['key1', b'blobyblob']
6969
query = "INSERT INTO blobstring (a, b) VALUES (%s, %s)"
7070

71-
# In python 3, the 'bytes' type is treated as a blob, so we can
72-
# correctly encode it with hex notation.
73-
# In python2, we don't treat the 'str' type as a blob, so we'll encode it
71+
# In python2, with Cassandra > 2.0, we don't treat the 'byte str' type as a blob, so we'll encode it
7472
# as a string literal and have the following failure.
7573
if six.PY2 and self._cql_version >= (3, 1, 0):
7674
# Blob values can't be specified using string notation in CQL 3.1.0 and
@@ -81,10 +79,14 @@ def test_can_insert_blob_type_as_string(self):
8179
msg = r'.*Invalid STRING constant \(.*?\) for b of type blob.*'
8280
self.assertRaisesRegexp(InvalidRequest, msg, s.execute, query, params)
8381
return
84-
elif six.PY2:
85-
params[1] = params[1].encode('hex')
8682

87-
s.execute(query, params)
83+
# In python2, with Cassandra < 2.0, we can manually encode the 'byte str' type as hex for insertion in a blob.
84+
if six.PY2:
85+
cass_params = [params[0], params[1].encode('hex')]
86+
s.execute(query, cass_params)
87+
# In python 3, the 'bytes' type is treated as a blob, so we can correctly encode it with hex notation.
88+
else:
89+
s.execute(query, params)
8890

8991
results = s.execute("SELECT * FROM blobstring")[0]
9092
for expected, actual in zip(params, results):

0 commit comments

Comments
 (0)