2222import sqlalchemy as sa
2323from sqlalchemy .ext .declarative import declarative_base
2424
25- from crate .client .sqlalchemy .types import Object , ObjectArray
25+ from crate .client .sqlalchemy .types import Object , ObjectArray , Geopoint
2626from crate .client .cursor import Cursor
2727
2828from unittest import TestCase
@@ -41,7 +41,7 @@ def setUp(self):
4141 self .engine = sa .create_engine ('crate://' )
4242 self .Base = declarative_base (bind = self .engine )
4343
44- def test_create_table_with_basic_types (self ):
44+ def test_table_basic_types (self ):
4545 class User (self .Base ):
4646 __tablename__ = 'users'
4747 string_col = sa .Column (sa .String , primary_key = True )
@@ -69,7 +69,7 @@ class User(self.Base):
6969 '\n \t PRIMARY KEY (string_col)\n )\n \n ' ),
7070 ())
7171
72- def test_with_obj_column (self ):
72+ def test_column_obj (self ):
7373 class DummyTable (self .Base ):
7474 __tablename__ = 'dummy'
7575 pk = sa .Column (sa .String , primary_key = True )
@@ -80,7 +80,7 @@ class DummyTable(self.Base):
8080 '\n \t PRIMARY KEY (pk)\n )\n \n ' ),
8181 ())
8282
83- def test_with_clustered_by (self ):
83+ def test_table_clustered_by (self ):
8484 class DummyTable (self .Base ):
8585 __tablename__ = 't'
8686 __table_args__ = {
@@ -97,7 +97,7 @@ class DummyTable(self.Base):
9797 ') CLUSTERED BY (p)\n \n ' ),
9898 ())
9999
100- def test_with_computed_column (self ):
100+ def test_column_computed (self ):
101101 class DummyTable (self .Base ):
102102 __tablename__ = 't'
103103 ts = sa .Column (sa .BigInteger , primary_key = True )
@@ -111,15 +111,15 @@ class DummyTable(self.Base):
111111 ')\n \n ' ),
112112 ())
113113
114- def test_with_virtual_computed_column (self ):
114+ def test_column_computed_virtual (self ):
115115 class DummyTable (self .Base ):
116116 __tablename__ = 't'
117117 ts = sa .Column (sa .BigInteger , primary_key = True )
118118 p = sa .Column (sa .BigInteger , sa .Computed ("date_trunc('day', ts)" , persisted = False ))
119119 with self .assertRaises (sa .exc .CompileError ):
120120 self .Base .metadata .create_all ()
121121
122- def test_with_partitioned_by (self ):
122+ def test_table_partitioned_by (self ):
123123 class DummyTable (self .Base ):
124124 __tablename__ = 't'
125125 __table_args__ = {
@@ -137,7 +137,7 @@ class DummyTable(self.Base):
137137 ') PARTITIONED BY (p)\n \n ' ),
138138 ())
139139
140- def test_with_number_of_shards_and_replicas (self ):
140+ def test_table_number_of_shards_and_replicas (self ):
141141 class DummyTable (self .Base ):
142142 __tablename__ = 't'
143143 __table_args__ = {
@@ -154,7 +154,7 @@ class DummyTable(self.Base):
154154 ') CLUSTERED INTO 3 SHARDS WITH (NUMBER_OF_REPLICAS = 2)\n \n ' ),
155155 ())
156156
157- def test_with_clustered_by_and_number_of_shards (self ):
157+ def test_table_clustered_by_and_number_of_shards (self ):
158158 class DummyTable (self .Base ):
159159 __tablename__ = 't'
160160 __table_args__ = {
@@ -172,7 +172,7 @@ class DummyTable(self.Base):
172172 ') CLUSTERED BY (p) INTO 3 SHARDS\n \n ' ),
173173 ())
174174
175- def test_table_with_object_array (self ):
175+ def test_column_object_array (self ):
176176 class DummyTable (self .Base ):
177177 __tablename__ = 't'
178178 pk = sa .Column (sa .String , primary_key = True )
@@ -185,7 +185,7 @@ class DummyTable(self.Base):
185185 'tags ARRAY(OBJECT), \n \t '
186186 'PRIMARY KEY (pk)\n )\n \n ' ), ())
187187
188- def test_table_with_nullable (self ):
188+ def test_column_nullable (self ):
189189 class DummyTable (self .Base ):
190190 __tablename__ = 't'
191191 pk = sa .Column (sa .String , primary_key = True )
@@ -200,9 +200,32 @@ class DummyTable(self.Base):
200200 'b INT NOT NULL, \n \t '
201201 'PRIMARY KEY (pk)\n )\n \n ' ), ())
202202
203- def test_with_pk_nullable (self ):
203+ def test_column_pk_nullable (self ):
204204 class DummyTable (self .Base ):
205205 __tablename__ = 't'
206206 pk = sa .Column (sa .String , primary_key = True , nullable = True )
207207 with self .assertRaises (sa .exc .CompileError ):
208208 self .Base .metadata .create_all ()
209+
210+ def test_column_crate_index (self ):
211+ class DummyTable (self .Base ):
212+ __tablename__ = 't'
213+ pk = sa .Column (sa .String , primary_key = True )
214+ a = sa .Column (sa .Integer , crate_index = False )
215+ b = sa .Column (sa .Integer , crate_index = True )
216+
217+ self .Base .metadata .create_all ()
218+ fake_cursor .execute .assert_called_with (
219+ ('\n CREATE TABLE t (\n \t '
220+ 'pk STRING NOT NULL, \n \t '
221+ 'a INT INDEX OFF, \n \t '
222+ 'b INT, \n \t '
223+ 'PRIMARY KEY (pk)\n )\n \n ' ), ())
224+
225+ def test_column_geopoint_without_index (self ):
226+ class DummyTable (self .Base ):
227+ __tablename__ = 't'
228+ pk = sa .Column (sa .String , primary_key = True )
229+ a = sa .Column (Geopoint , crate_index = False )
230+ with self .assertRaises (sa .exc .CompileError ):
231+ self .Base .metadata .create_all ()
0 commit comments