Mercurial > hg > ltpdarepo
changeset 110:e2338b374af4
Small improvements to the Objs class and to its tests.
author | Daniele Nicolodi <daniele@grinta.net> |
---|---|
date | Tue, 23 Aug 2011 21:04:09 +0200 |
parents | 598f84f0db4e |
children | 442dac399008 |
files | src/ltpdarepo/tests/test_objs.py src/ltpdarepo/views/browse.py |
diffstat | 2 files changed, 10 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ltpdarepo/tests/test_objs.py Tue Aug 23 21:03:50 2011 +0200 +++ b/src/ltpdarepo/tests/test_objs.py Tue Aug 23 21:04:09 2011 +0200 @@ -12,14 +12,16 @@ def test_simple(self): objs = Objs(database='db1') + self.assertEqual(len(objs), objs.count()) self.assertEqual(len(objs.all()), objs.count()) def test_limit(self): objs = Objs(database='db1').limit(20) + self.assertEqual(objs[0]['id'], 1) self.assertEqual(len(objs.all()), 20) objs = Objs(database='db1').limit(20, 2) - self.assertEqual(objs.all()[0]['id'], 21) + self.assertEqual(objs[0]['id'], 21) self.assertEqual(len(objs.all()), 2) def test_orderby(self):
--- a/src/ltpdarepo/views/browse.py Tue Aug 23 21:03:50 2011 +0200 +++ b/src/ltpdarepo/views/browse.py Tue Aug 23 21:04:09 2011 +0200 @@ -74,8 +74,6 @@ query = "SELECT COUNT(*) FROM `%s`.objmeta" % self._database if self._where: query += " WHERE %s" % self._where - if self._limit: - query += " LIMIT %d,%d" % self._limit return query def filter(self, where, values): @@ -108,10 +106,15 @@ return self.count() def __getitem__(self, item): - self._limit = (item, 1) + obj = None + limit = self._limit + start = limit and limit[0] or 0 + self._limit = start, 1 objs = self.all() if objs is not None: - return objs[0] + obj = objs[0] + self._limit = limit + return obj class Timeseries(Objs): @@ -215,9 +218,6 @@ values = [v.strip("'") for v in values] return column, kind, values - def column(self, name): - return self[name].column - class datetimefield(datetime): """Timezone aware subclass of `datetime.datetime` with a new