diff options
author | Sascha Silbe <sascha@silbe.org> | 2009-11-26 17:26:40 (GMT) |
---|---|---|
committer | Sascha Silbe <sascha@silbe.org> | 2009-11-26 17:26:40 (GMT) |
commit | c6ca2a7453552f86c97ff07d4b33293c9caf9800 (patch) | |
tree | f082ac1b2118336a53e1a4a89517ce2047d041d6 | |
parent | f842530f2410a496e403dbe3880d675afca0636f (diff) | |
parent | 18953df63e0b01a95987398e5138ccf761abfa6d (diff) |
Merge commit 'refs/top-bases/t/bug-1550-minimal' into t/bug-1550-minimalt/bug-1550-minimal
-rw-r--r-- | tests/test_massops.py | 87 |
1 files changed, 74 insertions, 13 deletions
diff --git a/tests/test_massops.py b/tests/test_massops.py index c3c87a5..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 @@ -12,6 +13,12 @@ DS_DBUS_SERVICE = "org.laptop.sugar.DataStore" DS_DBUS_INTERFACE = "org.laptop.sugar.DataStore" DS_DBUS_PATH = "/org/laptop/sugar/DataStore" NUM_RUNS = int(os.environ.get('MASSOPS_RUNS', '100')) +IGNORE_PROPERTIES = [ + 'checksum', + 'number', + 'timestamp', + 'uid', +] @decorator.decorator @@ -37,28 +44,76 @@ 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.""" for entry in self._datastore.find({}, ['uid'], byte_arrays=True)[0]: properties = self._datastore.get_properties(entry['uid'], byte_arrays=True) - del properties['uid'], properties['timestamp'] - properties.pop('checksum', None) + self._filter_properties(properties) self.assertEquals(properties, self._create_properties) def test_get_filename(self): @@ -89,14 +144,20 @@ class MassOpsTestCase(unittest.TestCase): def test_update_verify(self): """Verify test_update() has changed the content of all entries.""" - for entry in self._datastore.find({}, ['uid'], byte_arrays=True)[0]: + for entry in self._datastore.find({}, [], byte_arrays=True)[0]: filename = self._datastore.get_filename(entry['uid'], byte_arrays=True) + self._filter_properties(entry) + self.assertEquals(entry, self._update_properties) try: self.assertEquals(file(filename).read(), self._update_content) finally: os.remove(filename) + def _filter_properties(self, properties): + for key in IGNORE_PROPERTIES: + properties.pop(key, None) + def suite(): test_suite = unittest.TestLoader().loadTestsFromTestCase(MassOpsTestCase) |