|
15 | 15 | from datetime import date, datetime |
16 | 16 | from decimal import Decimal |
17 | 17 | import unittest |
18 | | -from uuid import UUID |
| 18 | +from uuid import UUID, uuid4 |
19 | 19 |
|
20 | 20 | from cassandra.cqlengine.models import Model |
21 | 21 | from cassandra.cqlengine.usertype import UserType |
@@ -286,3 +286,43 @@ class AllDatatypesModel(Model): |
286 | 286 |
|
287 | 287 | for i in range(ord('a'), ord('a') + 15): |
288 | 288 | 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