Skip to content
This repository was archived by the owner on Aug 5, 2020. It is now read-only.

Commit 8412d86

Browse files
committed
Merge pull request apache#333 from kishkaru/python-245_tests
[PYTHON-245] Tests for Date, Time, SmallInt, TinyInt in cqlengine
2 parents 57849ca + dca25da commit 8412d86

2 files changed

Lines changed: 37 additions & 25 deletions

File tree

tests/integration/cqlengine/model/test_model_io.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from uuid import uuid4, UUID
1616
import random
17-
from datetime import date, datetime
17+
from datetime import datetime, date, time
1818
from decimal import Decimal
1919
from operator import itemgetter
2020

@@ -23,7 +23,7 @@
2323
from cassandra.cqlengine.management import sync_table
2424
from cassandra.cqlengine.management import drop_table
2525
from cassandra.cqlengine.models import Model
26-
from cassandra.util import Date
26+
from cassandra.util import Date, Time
2727

2828
from tests.integration.cqlengine.base import BaseCassEngTestCase
2929

@@ -155,24 +155,28 @@ class AllDatatypesModel(Model):
155155
i = columns.Float(double_precision=False)
156156
j = columns.Inet()
157157
k = columns.Integer()
158-
l = columns.Text()
159-
m = columns.TimeUUID()
160-
n = columns.UUID()
161-
o = columns.VarInt()
158+
l = columns.SmallInt()
159+
m = columns.Text()
160+
n = columns.Time()
161+
o = columns.TimeUUID()
162+
p = columns.TinyInt()
163+
q = columns.UUID()
164+
r = columns.VarInt()
162165

163166
sync_table(AllDatatypesModel)
164167

165168
input = ['ascii', 2 ** 63 - 1, bytearray(b'hello world'), True, Date(date(1970, 1, 1)),
166169
datetime.utcfromtimestamp(872835240), Decimal('12.3E+7'), 2.39,
167-
3.4028234663852886e+38, '123.123.123.123', 2147483647, 'text',
168-
UUID('FE2B4360-28C6-11E2-81C1-0800200C9A66'), UUID('067e6162-3b6f-4ae2-a171-2470b63dff00'),
170+
3.4028234663852886e+38, '123.123.123.123', 2147483647, 32523, 'text', Time(time(16, 47, 25, 7)),
171+
UUID('FE2B4360-28C6-11E2-81C1-0800200C9A66'), 123, UUID('067e6162-3b6f-4ae2-a171-2470b63dff00'),
169172
int(str(2147483647) + '000')]
170173

171174
AllDatatypesModel.create(id=0, a='ascii', b=2 ** 63 - 1, c=bytearray(b'hello world'), d=True, e=date(1970, 1, 1),
172175
f=datetime.utcfromtimestamp(872835240), g=Decimal('12.3E+7'), h=2.39,
173-
i=3.4028234663852886e+38, j='123.123.123.123', k=2147483647, l='text',
174-
m=UUID('FE2B4360-28C6-11E2-81C1-0800200C9A66'), n=UUID('067e6162-3b6f-4ae2-a171-2470b63dff00'),
175-
o=int(str(2147483647) + '000'))
176+
i=3.4028234663852886e+38, j='123.123.123.123', k=2147483647, l=32523, m='text',
177+
n=time(16, 47, 25, 7), o=UUID('FE2B4360-28C6-11E2-81C1-0800200C9A66'),
178+
p=123, q=UUID('067e6162-3b6f-4ae2-a171-2470b63dff00'),
179+
r=int(str(2147483647) + '000'))
176180

177181
self.assertEqual(1, AllDatatypesModel.objects.count())
178182
output = AllDatatypesModel.objects().first()

tests/integration/cqlengine/model/test_udts.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from datetime import date, datetime
15+
from datetime import datetime, date, time
1616
from decimal import Decimal
1717
import unittest
1818
from uuid import UUID, uuid4
@@ -21,7 +21,7 @@
2121
from cassandra.cqlengine.usertype import UserType
2222
from cassandra.cqlengine import columns
2323
from cassandra.cqlengine.management import sync_table, sync_type, create_keyspace_simple, drop_keyspace
24-
from cassandra.util import Date
24+
from cassandra.util import Date, Time
2525

2626
from tests.integration import get_server_versions
2727
from tests.integration.cqlengine.base import BaseCassEngTestCase
@@ -216,18 +216,22 @@ class AllDatatypes(UserType):
216216
i = columns.Float(double_precision=False)
217217
j = columns.Inet()
218218
k = columns.Integer()
219-
l = columns.Text()
220-
m = columns.TimeUUID()
221-
n = columns.UUID()
222-
o = columns.VarInt()
219+
l = columns.SmallInt()
220+
m = columns.Text()
221+
n = columns.Time()
222+
o = columns.TimeUUID()
223+
p = columns.TinyInt()
224+
q = columns.UUID()
225+
r = columns.VarInt()
223226

224227
class AllDatatypesModel(Model):
225228
id = columns.Integer(primary_key=True)
226229
data = columns.UserDefinedType(AllDatatypes)
227230

228231
sync_table(AllDatatypesModel)
229232

230-
input = AllDatatypes(a=None, b=None, c=None, d=None, e=None, f=None, g=None, h=None, i=None, j=None, k=None, l=None, m=None, n=None)
233+
input = AllDatatypes(a=None, b=None, c=None, d=None, e=None, f=None, g=None, h=None, i=None, j=None, k=None,
234+
l=None, m=None, n=None, o=None, p=None, q=None, r=None)
231235
AllDatatypesModel.create(id=0, data=input)
232236

233237
self.assertEqual(1, AllDatatypesModel.objects.count())
@@ -263,10 +267,13 @@ class AllDatatypes(UserType):
263267
i = columns.Float(double_precision=False)
264268
j = columns.Inet()
265269
k = columns.Integer()
266-
l = columns.Text()
267-
m = columns.TimeUUID()
268-
n = columns.UUID()
269-
o = columns.VarInt()
270+
l = columns.SmallInt()
271+
m = columns.Text()
272+
n = columns.Time()
273+
o = columns.TimeUUID()
274+
p = columns.TinyInt()
275+
q = columns.UUID()
276+
r = columns.VarInt()
270277

271278
class AllDatatypesModel(Model):
272279
id = columns.Integer(primary_key=True)
@@ -276,9 +283,10 @@ class AllDatatypesModel(Model):
276283

277284
input = AllDatatypes(a='ascii', b=2 ** 63 - 1, c=bytearray(b'hello world'), d=True, e=Date(date(1970, 1, 1)),
278285
f=datetime.utcfromtimestamp(872835240), g=Decimal('12.3E+7'), h=2.39,
279-
i=3.4028234663852886e+38, j='123.123.123.123', k=2147483647, l='text',
280-
m=UUID('FE2B4360-28C6-11E2-81C1-0800200C9A66'), n=UUID('067e6162-3b6f-4ae2-a171-2470b63dff00'),
281-
o=int(str(2147483647) + '000'))
286+
i=3.4028234663852886e+38, j='123.123.123.123', k=2147483647, l=32523, m='text',
287+
n=Time(time(16, 47, 25, 7)), o=UUID('FE2B4360-28C6-11E2-81C1-0800200C9A66'),
288+
p=123, q=UUID('067e6162-3b6f-4ae2-a171-2470b63dff00'),
289+
r=int(str(2147483647) + '000'))
282290
AllDatatypesModel.create(id=0, data=input)
283291

284292
self.assertEqual(1, AllDatatypesModel.objects.count())

0 commit comments

Comments
 (0)