Files
deb-python-cassandra-driver/cqlengine/tests/model/test_model.py
Jon Haddad 4bb8b313c0 made create_keyspace more sane, fixed broken tests.
create_keyspace no longer has defaults for SimpleStrategy and
replication factor.  changed tests to use the default keyspace,
cqlengine_test for all tests.  Not sure why other keyspaces were being
used.
2015-01-14 08:35:37 -08:00

59 lines
1.8 KiB
Python

from unittest import TestCase
from cqlengine.models import Model, ModelDefinitionException
from cqlengine import columns
class TestModel(TestCase):
""" Tests the non-io functionality of models """
def test_instance_equality(self):
""" tests the model equality functionality """
class EqualityModel(Model):
pk = columns.Integer(primary_key=True)
m0 = EqualityModel(pk=0)
m1 = EqualityModel(pk=1)
self.assertEqual(m0, m0)
self.assertNotEqual(m0, m1)
def test_model_equality(self):
""" tests the model equality functionality """
class EqualityModel0(Model):
pk = columns.Integer(primary_key=True)
class EqualityModel1(Model):
kk = columns.Integer(primary_key=True)
m0 = EqualityModel0(pk=0)
m1 = EqualityModel1(kk=1)
self.assertEqual(m0, m0)
self.assertNotEqual(m0, m1)
class BuiltInAttributeConflictTest(TestCase):
"""tests Model definitions that conflict with built-in attributes/methods"""
def test_model_with_attribute_name_conflict(self):
"""should raise exception when model defines column that conflicts with built-in attribute"""
with self.assertRaises(ModelDefinitionException):
class IllegalTimestampColumnModel(Model):
my_primary_key = columns.Integer(primary_key=True)
timestamp = columns.BigInt()
def test_model_with_method_name_conflict(self):
"""should raise exception when model defines column that conflicts with built-in method"""
with self.assertRaises(ModelDefinitionException):
class IllegalFilterColumnModel(Model):
my_primary_key = columns.Integer(primary_key=True)
filter = columns.Text()