Skip to content

Commit

Permalink
PYTHON-606 Adding integation tests for udt default values
Browse files Browse the repository at this point in the history
  • Loading branch information
GregBestland committed Aug 17, 2016
1 parent ab33518 commit e345bec
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/integration/cqlengine/model/test_udts.py
Expand Up @@ -527,3 +527,38 @@ class User(UserType):
u = User()
u.age = 20
self.assertEqual(20, u.age)

def test_default_values(self):
"""
Test that default types are set on object creation for UDTs
@since 3.7.0
@jira_ticket PYTHON-606
@expected_result Default values should be set.
@test_category data_types:udt
"""

class NestedUdt(UserType):

test_id = columns.UUID(default=uuid4)
something = columns.Text()
default_text = columns.Text(default="default text")

class OuterModel(Model):

name = columns.Text(primary_key=True)
first_name = columns.Text()
nested = columns.List(columns.UserDefinedType(NestedUdt))
simple = columns.UserDefinedType(NestedUdt)

sync_table(OuterModel)

t = OuterModel.create(name='test1')

This comment has been minimized.

Copy link
@rebornwwp

rebornwwp Jul 26, 2017

this is about create, how about updating a record?

t.nested = [NestedUdt(something='test')]

This comment has been minimized.

Copy link
@rebornwwp

rebornwwp Jul 26, 2017

I use this way to update a record, but the class name in the list is <class 'NesteUdt'>, but is not the <class 'cassandra.io.asyncoreactor.nesteUdt> . how I solve this problem, make all items in the list have the same class name?

This comment has been minimized.

Copy link
@beltran

beltran Jul 26, 2017

Contributor

@rebornwwp I don't understand the problem you're talking about class cassandra.io.asyncoreactor.nesteUdt shouldn't exit. You can get more information about how to update values in https://cqlengine.readthedocs.io/en/latest/.

I think it'd be better if you used the mailing list for this kind of queries: https://groups.google.com/a/lists.datastax.com/forum/#!forum/python-driver-user for this kind of queries since it would be visible to more people and you'd probably get a quicker response.

This comment has been minimized.

Copy link
@mambocab

mambocab Jul 26, 2017

Contributor

Please address your questions to the mailing list or DataStax Academy Slack, which are linked in the readme.

t.simple = NestedUdt(something="")
t.save()
self.assertIsNotNone(t.nested[0].test_id)
self.assertEqual(t.nested[0].default_text, "default text")
self.assertIsNotNone(t.simple.test_id)
self.assertEqual(t.simple.default_text, "default text")

0 comments on commit e345bec

Please sign in to comment.