[Sugar-devel] [PATCH sugar-datastore 1/3] Add regression test for SL#2668
Sascha Silbe
silbe at activitycentral.com
Sat Mar 5 15:26:34 EST 2011
Signed-off-by: Sascha Silbe <silbe at activitycentral.com>
---
tests/test_sl2668.py | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 71 insertions(+), 0 deletions(-)
create mode 100755 tests/test_sl2668.py
diff --git a/tests/test_sl2668.py b/tests/test_sl2668.py
new file mode 100755
index 0000000..7c88b5d
--- /dev/null
+++ b/tests/test_sl2668.py
@@ -0,0 +1,71 @@
+#!/usr/bin/env python
+"""
+Regression test for SL#2668:
+
+If we call datastore.get() and pass the file name back into datastore.update()
+for the same entry with transfer_ownership set to False, the data file will
+get destroyed.
+"""
+
+import dbus
+import os
+import tempfile
+import unittest
+
+
+DS_DBUS_SERVICE = 'org.laptop.sugar.DataStore'
+DS_DBUS_INTERFACE = 'org.laptop.sugar.DataStore'
+DS_DBUS_PATH = '/org/laptop/sugar/DataStore'
+
+
+class SL2668TestCase(unittest.TestCase):
+ """Regression test for SL#2668"""
+
+ _create_content = 'Foo bar\n'
+
+ def setUp(self):
+ # pylint: disable=C0103
+ self._bus = dbus.SessionBus()
+ self._datastore = dbus.Interface(self._bus.get_object(DS_DBUS_SERVICE,
+ DS_DBUS_PATH), DS_DBUS_INTERFACE)
+
+ def test_sl2668(self):
+ """Check for SL#2668."""
+ object_id = self._create_entry()
+ data_path = self._datastore.get_filename(object_id)
+ self.assertEquals(os.path.getsize(data_path),
+ len(self._create_content))
+
+ self._datastore.update(object_id, self._test_properties, data_path,
+ False)
+
+ self.assertEquals(os.path.getsize(data_path),
+ len(self._create_content))
+ os.remove(data_path)
+
+ data_path = self._datastore.get_filename(object_id)
+ self.assertEquals(os.path.getsize(data_path),
+ len(self._create_content))
+ os.remove(data_path)
+
+ def _create_entry(self):
+ """Create data store entry."""
+ content_file = tempfile.NamedTemporaryFile()
+ content_file.write(self._create_content)
+ content_file.flush()
+ self.assertEquals(os.path.getsize(content_file.name),
+ len(self._create_content))
+ self._test_properties = {
+ 'title': 'DS test object',
+ 'mime_type': 'text/plain',
+ }
+ object_id = self._datastore.create(self._test_properties,
+ content_file.name, False)
+ content_file.close()
+ return object_id
+
+
+def suite():
+ test_suite = unittest.TestLoader().loadTestsFromTestCase(SL2668TestCase)
+ test_suite.__doc__ = SL2668TestCase.__doc__
+ return test_suite
--
1.7.2.3
More information about the Sugar-devel
mailing list