[bfss storage] Improve fspath() error message. stable
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Thu, 06 Jan 2011 17:49:19 +0100
branchstable
changeset 6788 0f31ed3fff79
parent 6787 aede8c85207f
child 6789 f38963f7c91d
[bfss storage] Improve fspath() error message. This changeset improve the error message of fspath when the argument is not managed by a BytesFileSystem storage.
cwconfig.py
server/test/unittest_storage.py
--- a/cwconfig.py	Thu Jan 06 17:47:50 2011 +0100
+++ b/cwconfig.py	Thu Jan 06 17:49:19 2011 +0100
@@ -1278,7 +1278,9 @@
             stack[0] = self.source_execute
 
         def as_sql(self, backend, args):
-            raise NotImplementedError('source only callback')
+            raise NotImplementedError(
+                'This callback is only available for BytesFileSystemStorage '
+                'managed attribute. Is FSPATH() argument BFSS managed?')
 
         def source_execute(self, source, session, value):
             fpath = source.binary_to_str(value)
--- a/server/test/unittest_storage.py	Thu Jan 06 17:47:50 2011 +0100
+++ b/server/test/unittest_storage.py	Thu Jan 06 17:49:19 2011 +0100
@@ -75,6 +75,15 @@
                               {'f': entity.eid})[0][0]
         return fspath.getvalue()
 
+    def test_bfss_wrong_fspath_usage(self):
+        f1 = self.create_file()
+        self.execute('Any fspath(D) WHERE F eid %(f)s, F data D', {'f': f1.eid})
+        with self.assertRaises(NotImplementedError) as cm:
+            self.execute('Any fspath(F) WHERE F eid %(f)s', {'f': f1.eid})
+        self.assertEqual(str(cm.exception),
+                         'This callback is only available for BytesFileSystemStorage '
+                         'managed attribute. Is FSPATH() argument BFSS managed?')
+
     def test_bfss_storage(self):
         f1 = self.create_file()
         expected_filepath = osp.join(self.tempdir, '%s_data_%s' %