Skip to content
Browse files

Fixed all tests

  • Loading branch information...
1 parent ef01b37 commit 49c372688126a0e97ebd4e3fef6dbdbbd14d4ef4 @Lispython Lispython committed Apr 7, 2013
Showing with 46 additions and 23 deletions.
  1. +17 −5 gottwall/storages/redis.py
  2. +9 −9 tests/__init__.py
  3. +20 −9 tests/storages.py
View
22 gottwall/storages/redis.py
@@ -12,6 +12,7 @@
"""
import uuid
from logging import getLogger
+from types import NoneType
import tornado.gen
from tornado.escape import json_decode, json_encode
@@ -187,7 +188,7 @@ def incr(self, project, name, timestamp, value=1, filters=None, callback=None, *
"""
pipe = self.client.pipeline(transactional=True)
- pipe.select(self.client.selected_db)
+ pipe.select(self.selected_db)
for period in self._application.config['PERIODS']:
if filters:
@@ -226,7 +227,7 @@ def make_key(self, project, name, period, filters=None):
if isinstance(filters, dict):
filters_part = u"/".join(
- [u"{0}|{1}".format(f, to_unicode(filters[f]))
+ [u"{0}|{1}".format(f, to_unicode(self.clean_filter_value(filters[f])))
for f in sorted(filters.keys(), key=lambda x: x) if f])
if filters_part:
@@ -247,8 +248,6 @@ def query(self, project, name, period, from_date=None, to_date=None,
data_range = self.filter_by_period(map(lambda x: (x[0], int(x[1])), items.iteritems()),
period, from_date, to_date)
- filtered_range_values = map(lambda x: int(x[1]), data_range)
-
if callback:
callback(self.get_range_info(data_range))
@@ -290,7 +289,7 @@ def metrics(self, project, callback=None):
"""
client = self.client
- self.client.select(self.client.selected_db)
+ self.client.select(self.selected_db)
metrics = {}
@@ -307,3 +306,16 @@ def metrics(self, project, callback=None):
if callback:
callback(metrics)
+
+
+ def clean_filter_value(self, filter_value):
+ """Convert filter value to string object
+
+ :param filter_value:
+ :return: string object
+ """
+ if isinstance(filter_value, bool) or isinstance(filter_value, NoneType):
+ return str(bool)
+ return filter_value
+
+
View
18 tests/__init__.py
@@ -25,16 +25,16 @@
def suite():
suite = unittest.TestSuite()
- # suite.addTest(unittest.makeSuite(ConfigTestCase))
- # suite.addTest(unittest.makeSuite(TCPBackendTestCase))
- # suite.addTest(unittest.makeSuite(HTTPBackendTestCase))
- # suite.addTest(unittest.makeSuite(RedisBackendTestCase))
- # suite.addTest(unittest.makeSuite(APITestCase))
- # suite.addTest(unittest.makeSuite(StorageTestCase))
- # suite.addTest(unittest.makeSuite(RedisStorageTestCase))
+ suite.addTest(unittest.makeSuite(ConfigTestCase))
+ suite.addTest(unittest.makeSuite(TCPBackendTestCase))
+ suite.addTest(unittest.makeSuite(HTTPBackendTestCase))
+ suite.addTest(unittest.makeSuite(RedisBackendTestCase))
+ suite.addTest(unittest.makeSuite(APITestCase))
+ suite.addTest(unittest.makeSuite(StorageTestCase))
+ suite.addTest(unittest.makeSuite(RedisStorageTestCase))
suite.addTest(unittest.makeSuite(MemoryStorageTestCase))
- # suite.addTest(unittest.makeSuite(UtilsTestCase))
- # suite.addTest(unittest.makeSuite(ProcessorTestCase))
+ suite.addTest(unittest.makeSuite(UtilsTestCase))
+ suite.addTest(unittest.makeSuite(ProcessorTestCase))
return suite
if __name__ == '__main__':
View
29 tests/storages.py
@@ -308,26 +308,37 @@ def test_redis_storage(self):
("filter2", "web"),
("filter2", "iphone"),
(None, None)):
- d = list((yield Task(storage.query, "test_redis_project",
+ d = (yield Task(storage.query, "test_redis_project",
"redis_metric_name", period,
from_date=from_date,
to_date=to_date,
filter_name=filter_name,
- filter_value=filter_value)))
- self.assertTrue(10 in [x[1] for x in d])
+ filter_value=filter_value))
+
+ self.assertEquals(max([x[1] for x in list(d['range'])]), d['max'])
+ self.assertEquals(min([x[1] for x in list(d['range'])]), d['min'])
+ self.assertEquals(sum([x[1] for x in list(d['range'])]) / len(d['range']), d['min'])
+ self.assertTrue(10 in [x[1] for x in list(d['range'])])
for period in ["year"]:
for filter_name, filter_value in (("filter1", True),
("filter2", "web"),
("filter2", "iphone"),
(None, None)):
- for x in list((yield Task(storage.query, "test_redis_project",
- "redis_metric_name", period,
- from_date=from_date,
- to_date=to_date,
- filter_name=filter_name,
- filter_value=filter_value))):
+
+ d = (yield Task(storage.query, "test_redis_project",
+ "redis_metric_name", period,
+ from_date=from_date,
+ to_date=to_date,
+ filter_name=filter_name,
+ filter_value=filter_value))
+
+ for x in list(d['range']):
self.assertEquals(int(x[1]), 20)
+ self.assertEquals(max([x[1] for x in list(d['range'])]), d['max'])
+ self.assertEquals(min([x[1] for x in list(d['range'])]), d['min'])
+ self.assertEquals(sum([x[1] for x in list(d['range'])]) / len(d['range']), d['min'])
+
self.stop()

0 comments on commit 49c3726

Please sign in to comment.
Something went wrong with that request. Please try again.