diff options
author | Sascha Silbe <sascha@silbe.org> | 2009-11-26 17:16:39 (GMT) |
---|---|---|
committer | Sascha Silbe <sascha@silbe.org> | 2009-11-26 17:16:39 (GMT) |
commit | 18953df63e0b01a95987398e5138ccf761abfa6d (patch) | |
tree | 59e7bb5ed3d28d00f382df1ca8bffd4333e6f73a | |
parent | 9a518ee9e6c1882cb63f4c3b8007e425b265fea9 (diff) |
test_massops.py: test ordering of find() results (for all supported orders) and offset/limit (for default order)refs/top-bases/t/bug-1550-minimal
-rw-r--r-- | tests/test_massops.py | 71 |
1 files changed, 61 insertions, 10 deletions
diff --git a/tests/test_massops.py b/tests/test_massops.py index 47e6d7a..576d6b1 100644 --- a/tests/test_massops.py +++ b/tests/test_massops.py @@ -5,6 +5,7 @@ import dbus import decorator import os import tempfile +import time import unittest @@ -14,6 +15,7 @@ DS_DBUS_PATH = "/org/laptop/sugar/DataStore" NUM_RUNS = int(os.environ.get('MASSOPS_RUNS', '100')) IGNORE_PROPERTIES = [ 'checksum', + 'number', 'timestamp', 'uid', ] @@ -42,20 +44,69 @@ class MassOpsTestCase(unittest.TestCase): } _create_content = 'Foo bar\n'*1000 - @repeat def test_create(self): - """Run create() lots of times.""" - content_file = tempfile.NamedTemporaryFile() - content_file.write(self._create_content) - content_file.flush() - self._datastore.create(self._create_properties, content_file.name, - False) - content_file.close() + """Run save() lots of times to create new objects.""" + timestamp = time.time() + for i in range(NUM_RUNS): + content_file = tempfile.NamedTemporaryFile() + content_file.write(self._create_content) + content_file.flush() + properties = self._create_properties.copy() + properties['number'] = str(i) + properties['timestamp'] = timestamp+i + self._datastore.create(properties, content_file.name, False) + content_file.close() @repeat def test_find_all(self): - """Run find() to list all entries lots of times.""" - self._datastore.find({}, ['uid'], byte_arrays=True) + """Run find() to list all entries.""" + entries, total_count = self._datastore.find({}, ['number'], + byte_arrays=True) + self.assertEquals(total_count, NUM_RUNS) + self.assertEquals(total_count, len(entries)) + for position, entry in enumerate(entries): + self.assertEquals(int(entry['number']), NUM_RUNS-position-1) + + @repeat + def test_find_all_reverse_time(self): + """Run find() to list all entries in reverse chronological order.""" + entries, total_count = self._datastore.find({'order_by': + ['-timestamp']}, ['number'], byte_arrays=True) + self.assertEquals(total_count, NUM_RUNS) + self.assertEquals(total_count, len(entries)) + for position, entry in enumerate(entries): + self.assertEquals(int(entry['number']), position) + + @repeat + def test_find_all_title(self): + """Run find() to list all entries ordered by title.""" + entries, total_count = self._datastore.find({'order_by': + ['+title']}, ['tree_id'], byte_arrays=True) + self.assertEquals(total_count, NUM_RUNS) + self.assertEquals(total_count, len(entries)) + + @repeat + def test_find_all_title(self): + """Run find() to list all entries ordered by title (reversed).""" + entries, total_count = self._datastore.find({'order_by': + ['-title']}, ['tree_id'], byte_arrays=True) + self.assertEquals(total_count, NUM_RUNS) + self.assertEquals(total_count, len(entries)) + + @repeat + def test_find_all_chunked(self): + """Run find() to list all entries in small chunks.""" + chunk_size = 30 + for chunk_start in range(0, NUM_RUNS, 30): + entries, total_count = self._datastore.find({ + 'offset': chunk_start, 'limit': chunk_size}, + ['number'], byte_arrays=True) + self.assertEquals(len(entries), + min(chunk_size, NUM_RUNS-chunk_start)) + self.assertEquals(total_count, NUM_RUNS) + for position, entry in enumerate(entries): + self.assertEquals(int(entry['number']), + NUM_RUNS-(chunk_start+position)-1) def test_get_properties(self): """Run get_properties() on all entries and verify result.""" |