Permalink
Browse files

superficial test and uuid.time approach

  • Loading branch information...
1 parent 2d543a0 commit bf5f7cd4a0d28a6e94821a1e4d73ff1a0744cf54 @kurtjx kurtjx committed Feb 4, 2014
Showing with 28 additions and 25 deletions.
  1. +16 −25 pycassa/contrib/stubs.py
  2. +12 −0 tests/contrib/stubs.py
@@ -12,7 +12,7 @@
from collections import MutableMapping
from pycassa import NotFoundException
-from pycassa.util import OrderedDict, convert_uuid_to_time, convert_time_to_uuid
+from pycassa.util import OrderedDict
from pycassa.columnfamily import gm_timestamp
from pycassa.index import EQ, GT, GTE, LT, LTE
@@ -112,27 +112,6 @@ def describe_schema_versions(self):
return {self._schema(): ['1.1.1.1']}
-
-def _uuid_to_datetime(col):
- if isinstance(col, tuple):
- out = []
- for x in col:
- out.append(datetime.datetime.fromtimestamp(convert_uuid_to_time(x)) if isinstance(x, UUID) else x)
- return tuple(out)
- elif isinstance(col, UUID):
- return datetime.datetime.fromtimestamp(convert_uuid_to_time(col))
- return col
-
-def _datetime_to_uuid(col):
- if isinstance(col, tuple):
- out = []
- for x in col:
- out.append(convert_time_to_uuid(int(x.strftime('%s')))
- if isinstance(x, datetime.datetime) else x)
- return tuple(out)
- if isinstance(col, datetime.datetime):
- return convert_time_to_uuid(int(col.strftime('%s')))
-
class ColumnFamilyStub(object):
"""Functional ColumnFamily stub object.
@@ -171,13 +150,25 @@ def get(self, key, columns=None, column_start=None, column_finish=None,
if not my_columns:
raise NotFoundException()
- items = [_uuid_to_datetime(x) for x in my_columns.items()]
- items.sort()
+ items = my_columns.items()
+ if isinstance(items[0], UUID) and items[0].version==1:
+ items.sort(key=lambda uuid: uuid.time)
+ elif isinstance(items[0], tuple) and any([isinstance(x, UUID) for x in items[0]]):
+ isuid = [isinstance(x, UUID) and x.version==1 for x in items[0]]
+ def sortuuid(tup):
+ return [x.time if y else x for x, y in zip(tup, isuid)]
+ items.sort(key=sortuuid)
+ else:
+ items.sort()
+
+
+
+
if column_reversed:
items.reverse()
- sliced_items = [(_datetime_to_uuid(k), get_value(v)) for (k, v) in items
+ sliced_items = [(k, get_value(v)) for (k, v) in items
if self._is_column_in_range(k, columns,
column_start, column_finish, column_reversed)][:column_count]
@@ -1,4 +1,5 @@
import unittest
+import datetime
from nose.tools import assert_raises, assert_equal, assert_true
@@ -227,3 +228,14 @@ def test_remove(self):
test_cf.remove(key)
assert_raises(NotFoundException, test_cf.get, key)
+
+ def test_insert_get_tuuids(self):
+ key = 'TestColumnFamily.test_insert_get'
+ columns = ( (convert_time_to_uuid(time.time()-1000, randomize=True), 'val1'),
+ (convert_time_to_uuid(time.time(), randomize=True), 'val2') )
+ for test_cf in (cf, cf_stub):
+ assert_raises(NotFoundException, test_cf.get, key)
+ ts = test_cf.insert(key, dict(columns))
+ assert_true(isinstance(ts, (int, long)))
+ assert_equal(test_cf.get(key).keys(), [x[0] for x in columns])
+

0 comments on commit bf5f7cd

Please sign in to comment.