Skip to content

Commit

Permalink
Raise TypeErr when bad CF attr type is supplied
Browse files Browse the repository at this point in the history
  • Loading branch information
thobbs committed Dec 8, 2011
1 parent 103866a commit 0806c62
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
11 changes: 10 additions & 1 deletion pycassa/system_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,16 @@ def _system_add_column_family(self, cfdef):

def _qualify_type_class(self, classname):
if classname:
s = str(classname)
if isinstance(classname, types.CassandraType):
s = str(classname)
elif isinstance(classname, basestring):
s = classname
else:
raise TypeError(
"Column family validators and comparators " \
"must be specified as instances of " \
"pycassa.types.CassandraType subclasses or strings.")

if s.find('.') == -1:
return 'org.apache.cassandra.db.marshal.%s' % s
else:
Expand Down
10 changes: 9 additions & 1 deletion tests/test_system_manager.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import unittest

from nose.tools import assert_equal
from nose.tools import assert_equal, assert_raises

from pycassa.pool import ConnectionPool
from pycassa.columnfamily import ColumnFamily
from pycassa.system_manager import *
from pycassa.cassandra.ttypes import InvalidRequestException
from pycassa.types import LongType

TEST_KS = 'PycassaTestKeyspace'

Expand Down Expand Up @@ -40,6 +41,13 @@ def test_system_calls(self):

sys.drop_keyspace('TestKeyspace')

def test_bad_comparator(self):
sys.create_keyspace('TestKeyspace', SIMPLE_STRATEGY, {'replication_factor': '3'})
for comparator in [types.LongType, 123]:
assert_raises(TypeError, sys.create_column_family,
'TestKeyspace', 'TestBadCF', comparator_type=comparator)
sys.drop_keyspace('TestKeyspace')

def test_alter_column_non_bytes_type(self):
sys.create_column_family(TEST_KS, 'LongCF', comparator_type=LONG_TYPE)
sys.create_index(TEST_KS, 'LongCF', 3, LONG_TYPE)
Expand Down

0 comments on commit 0806c62

Please sign in to comment.