Skip to content

Commit 57849ca

Browse files
committed
Merge pull request apache#331 from datastax/PYTHON-311-test
[PYTHON-311] Test for inserting collections of UDTs
2 parents 4bf695b + 05b6007 commit 57849ca

1 file changed

Lines changed: 41 additions & 1 deletion

File tree

tests/integration/cqlengine/model/test_udts.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from datetime import date, datetime
1616
from decimal import Decimal
1717
import unittest
18-
from uuid import UUID
18+
from uuid import UUID, uuid4
1919

2020
from cassandra.cqlengine.models import Model
2121
from cassandra.cqlengine.usertype import UserType
@@ -286,3 +286,43 @@ class AllDatatypesModel(Model):
286286

287287
for i in range(ord('a'), ord('a') + 15):
288288
self.assertEqual(input[chr(i)], output[chr(i)])
289+
290+
def test_nested_udts_inserts(self):
291+
"""
292+
Test for inserting collections of user types using cql engine.
293+
294+
test_nested_udts_inserts Constructs a model that contains a list of usertypes. It will then attempt to insert
295+
them. The expectation is that no exception is thrown during insert. For sanity sake we also validate that our
296+
input and output values match. This combination of model, and UT produces a syntax error in 2.5.1 due to
297+
improper quoting around the names collection.
298+
299+
@since 2.6.0
300+
@jira_ticket PYTHON-311
301+
@expected_result No syntax exception thrown
302+
303+
@test_category data_types:udt
304+
"""
305+
306+
class Name(UserType):
307+
type_name__ = "header"
308+
309+
name = columns.Text()
310+
value = columns.Text()
311+
312+
class Container(Model):
313+
id = columns.UUID(primary_key=True, default=uuid4)
314+
names = columns.List(columns.UserDefinedType(Name()))
315+
316+
# Construct the objects and insert them
317+
names = []
318+
for i in range(0, 10):
319+
names.append(Name(name="name{0}".format(i), value="value{0}".format(i)))
320+
321+
# Create table, insert data
322+
sync_table(Container)
323+
Container.create(id=UUID('FE2B4360-28C6-11E2-81C1-0800200C9A66'), names=names)
324+
325+
# Validate input and output matches
326+
self.assertEqual(1, Container.objects.count())
327+
names_output = Container.objects().first().names
328+
self.assertEqual(names_output, names)

0 commit comments

Comments
 (0)