Skip to content

Commit ecdbdb3

Browse files
GregBestlandaholmberg
authored andcommitted
tuple test updates
PYTHON-306
1 parent e1170bf commit ecdbdb3

File tree

1 file changed

+102
-89
lines changed

1 file changed

+102
-89
lines changed

tests/integration/cqlengine/columns/test_container_columns.py

Lines changed: 102 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -559,41 +559,65 @@ def tearDownClass(cls):
559559
drop_table(TestTupleModel)
560560

561561
def test_initial(self):
562+
"""
563+
Tests creation and insertion of tuple types with models
564+
565+
@since 3.2
566+
@jira_ticket PYTHON-306
567+
@expected_result Model is successfully crated
568+
569+
@test_category object_mapper
570+
"""
562571
tmp = TestTupleModel.create()
563572
tmp.int_tuple = (1, 2, 3)
564573

565574
def test_initial_retrieve(self):
575+
"""
576+
Tests creation and insertion of tuple types with models,
577+
and their retrieval.
578+
579+
@since 3.2
580+
@jira_ticket PYTHON-306
581+
@expected_result Model is successfully crated
582+
583+
@test_category object_mapper
584+
"""
585+
566586
tmp = TestTupleModel.create()
567587
tmp2 = tmp.get(partition=tmp.partition)
568588
tmp2.int_tuple = (1, 2, 3)
569589

570590
def test_io_success(self):
571-
""" Tests that a basic usage works as expected """
591+
"""
592+
Tests creation and insertion of various types with models,
593+
and their retrieval.
594+
595+
@since 3.2
596+
@jira_ticket PYTHON-306
597+
@expected_result Model is successfully created and fetched correctly
598+
599+
@test_category object_mapper
600+
"""
572601
m1 = TestTupleModel.create(int_tuple=(1, 2, 3, 5, 6), text_tuple=('kai', 'andreas'), mixed_tuple=('first', 2, 'Third'))
573602
m2 = TestTupleModel.get(partition=m1.partition)
574603

575604
self.assertIsInstance(m2.int_tuple, tuple)
576605
self.assertIsInstance(m2.text_tuple, tuple)
577606
self.assertIsInstance(m2.mixed_tuple, tuple)
578607

579-
self.assertEqual(len(m2.int_tuple), 3)
580-
self.assertEqual(len(m2.text_tuple), 2)
581-
self.assertEqual(len(m2.mixed_tuple), 3)
582-
583-
self.assertEqual(m2.int_tuple[0], 1)
584-
self.assertEqual(m2.int_tuple[1], 2)
585-
self.assertEqual(m2.int_tuple[2], 3)
586-
587-
self.assertEqual(m2.text_tuple[0], 'kai')
588-
self.assertEqual(m2.text_tuple[1], 'andreas')
589-
590-
self.assertEqual(m2.mixed_tuple[0], 'first')
591-
self.assertEqual(m2.mixed_tuple[1], 2)
592-
self.assertEqual(m2.mixed_tuple[2], 'Third')
608+
self.assertEqual((1, 2, 3), m2.int_tuple)
609+
self.assertEqual(('kai', 'andreas'), m2.text_tuple)
610+
self.assertEqual(('first', 2, 'Third'), m2.mixed_tuple)
593611

594612
def test_type_validation(self):
595613
"""
596-
Tests that attempting to use the wrong types will raise an exception
614+
Tests to make sure tuple type validation occurs
615+
616+
@since 3.2
617+
@jira_ticket PYTHON-306
618+
@expected_result validation errors are raised
619+
620+
@test_category object_mapper
597621
"""
598622
self.assertRaises(ValidationError, TestTupleModel.create, **{'int_tuple': ('string', True), 'text_tuple': ('test', 'test'), 'mixed_tuple': ('one', 2, 'three')})
599623
self.assertRaises(ValidationError, TestTupleModel.create, **{'int_tuple': ('string', 'string'), 'text_tuple': (1, 3.0), 'mixed_tuple': ('one', 2, 'three')})
@@ -603,6 +627,12 @@ def test_instantiation_with_column_class(self):
603627
"""
604628
Tests that columns instantiated with a column class work properly
605629
and that the class is instantiated in the constructor
630+
631+
@since 3.2
632+
@jira_ticket PYTHON-306
633+
@expected_result types are instantiated correctly
634+
635+
@test_category object_mapper
606636
"""
607637
mixed_tuple = columns.Tuple(columns.Text, columns.Integer, columns.Text, required=False)
608638
self.assertIsInstance(mixed_tuple.types[0], columns.Text)
@@ -611,7 +641,15 @@ def test_instantiation_with_column_class(self):
611641
self.assertEqual(len(mixed_tuple.types), 3)
612642

613643
def test_default_empty_container_saving(self):
614-
""" tests that the default empty container is not saved if it hasn't been updated """
644+
"""
645+
Tests that the default empty container is not saved if it hasn't been updated
646+
647+
@since 3.2
648+
@jira_ticket PYTHON-306
649+
@expected_result empty tuple is not upserted
650+
651+
@test_category object_mapper
652+
"""
615653
pkey = uuid4()
616654
# create a row with tuple data
617655
TestTupleModel.create(partition=pkey, int_tuple=(1, 2, 3))
@@ -621,49 +659,69 @@ def test_default_empty_container_saving(self):
621659
m = TestTupleModel.get(partition=pkey)
622660
self.assertEqual(m.int_tuple, (1, 2, 3))
623661

624-
def test_partial_updates(self):
625-
"""Truncates on create but not on save"""
626-
""" broken"""
627-
full = tuple(range(10))
628-
initial = full[3:7]
662+
def test_updates(self):
663+
"""
664+
Tests that updates can be preformed on tuple containers
665+
666+
@since 3.2
667+
@jira_ticket PYTHON-306
668+
@expected_result tuple is replaced
669+
670+
@test_category object_mapper
671+
"""
672+
initial = (1, 2)
673+
replacement = (1, 2, 3)
629674

630675
m1 = TestTupleModel.create(int_tuple=initial)
631-
m1.int_tuple = (1, 2, 3)
676+
m1.int_tuple = replacement
632677
m1.save()
633678

634-
if is_prepend_reversed():
635-
expected = full[2::-1] + full[3:]
636-
else:
637-
expected = full
638-
639679
m2 = TestTupleModel.get(partition=m1.partition)
640-
self.assertEqual(tuple(m2.int_tuple), expected)
641-
642-
def test_to_python(self):
643-
""" Tests that to_python of value column is called """
644-
column = columns.Tuple(JsonTestColumn)
645-
val = (1, 2, 3)
646-
db_val = column.to_database(val)
647-
self.assertEqual(db_val, tuple(json.dumps(v) for v in val))
648-
py_val = column.to_python(db_val)
649-
self.assertEqual(py_val, val)
680+
self.assertEqual(tuple(m2.int_tuple), replacement)
650681

651682
def test_update_from_non_empty_to_empty(self):
652-
# Can up date a touple raises a Runtime Error
683+
"""
684+
Tests that explcit none updates are processed correctly on tuples
685+
686+
@since 3.2
687+
@jira_ticket PYTHON-306
688+
@expected_result tuple is replaced with none
689+
690+
@test_category object_mapper
691+
"""
653692
pkey = uuid4()
654-
tmp = TestTupleModel.create(partition=pkey, int_tuple=(1, 2))
655-
tmp.int_tuple = (1, 3)
693+
tmp = TestTupleModel.create(partition=pkey, int_tuple=(1, 2, 3))
694+
tmp.int_tuple = (None)
656695
tmp.update()
657696

658697
tmp = TestTupleModel.get(partition=pkey)
659-
self.assertEqual(tmp.int_tuple, (1, 3, None))
698+
self.assertEqual(tmp.int_tuple, (None))
660699

661700
def test_insert_none(self):
701+
"""
702+
Tests that Tuples can be created as none
703+
704+
@since 3.2
705+
@jira_ticket PYTHON-306
706+
@expected_result tuple is created as none
707+
708+
@test_category object_mapper
709+
"""
662710
pkey = uuid4()
663-
self.assertRaises(ValidationError, TestTupleModel.create, **{'partition': pkey, 'int_tuple': (None)})
711+
tmp = TestTupleModel.create(partition=pkey, int_tuple=(None))
712+
self.assertEqual((None), tmp.int_tuple)
664713

665714
def test_blind_tuple_updates_from_none(self):
666-
""" Tests that updates from None work as expected """
715+
"""
716+
Tests that Tuples can be updated from none
717+
718+
@since 3.2
719+
@jira_ticket PYTHON-306
720+
@expected_result tuple is created as none, but upserted to contain values
721+
722+
@test_category object_mapper
723+
"""
724+
667725
m = TestTupleModel.create(int_tuple=None)
668726
expected = (1, 2, 3)
669727
m.int_tuple = expected
@@ -677,48 +735,3 @@ def test_blind_tuple_updates_from_none(self):
677735
m3 = TestTupleModel.get(partition=m.partition)
678736
self.assertEqual(m3.int_tuple, None)
679737

680-
681-
class TestTupleModelVeryLarge(Model):
682-
683-
partition = columns.UUID(primary_key=True, default=uuid4)
684-
args = []
685-
for i in range(32767):
686-
args.append(columns.Integer)
687-
int_tuple = columns.Tuple(*args, required=False)
688-
689-
690-
class TestTupleModelOverLarge(Model):
691-
692-
partition = columns.UUID(primary_key=True, default=uuid4)
693-
args = []
694-
for i in range(32769):
695-
args.append(columns.Integer)
696-
int_tuple = columns.Tuple(*args, required=False)
697-
698-
699-
class TestTupleColumnLarge(BaseCassEngTestCase):
700-
701-
def test_element_count_validation(self):
702-
drop_table(TestTupleModelVeryLarge)
703-
sync_table(TestTupleModelVeryLarge)
704-
"""
705-
Tests that big collections are supported
706-
"""
707-
test_tuple = (i for i in range(32767))
708-
m1 = TestTupleModelVeryLarge.create(int_tuple=test_tuple)
709-
m2 = TestTupleModelVeryLarge.get(partition=m1.partition)
710-
print(len(m2.int_tuple))
711-
drop_table(TestTupleModelVeryLarge)
712-
713-
def test_element_count_validation_too_big(self):
714-
drop_table(TestTupleModelOverLarge)
715-
sync_table(TestTupleModelOverLarge)
716-
"""
717-
Tests that big collections are detected and raise an exception.
718-
"""
719-
test_tuple = (i for i in range(32769))
720-
m1 = TestTupleModelOverLarge.create(int_tuple=test_tuple)
721-
m2 = TestTupleModelOverLarge.get(partition=m1.partition)
722-
print(len(m2.int_tuple))
723-
# this will need to be wrapped in an assertion
724-
drop_table(TestTupleModelOverLarge)

0 commit comments

Comments
 (0)