Index: main/waeup.sirp/trunk/src/waeup/sirp/tests/test_imagestorage.py
===================================================================
--- main/waeup.sirp/trunk/src/waeup/sirp/tests/test_imagestorage.py	(revision 7105)
+++ main/waeup.sirp/trunk/src/waeup/sirp/tests/test_imagestorage.py	(revision 7120)
@@ -104,4 +104,13 @@
         return
 
+    def test_create_file_w_ext(self):
+        # We can store files with filename extension
+        storage = ExtFileStore(root=self.workdir)
+        dummy_file = StringIO('sample file')
+        image_file = storage.createFile('mysample.txt', dummy_file)
+        self.assertTrue('mysample.txt' in os.listdir(storage.root))
+        self.assertEqual('mysample.txt', image_file.data)
+        return
+
     def test_get_file(self):
         # We can get files after having them stored
@@ -111,4 +120,30 @@
         result = storage.getFile(image_file.data)
         self.assertEqual(result.read(), 'sample file')
+        return
+
+    def test_get_file_w_ext(self):
+        # We can get files with filename extension after having them
+        # stored
+        storage = ExtFileStore(root=self.workdir)
+        dummy_file = StringIO('sample file')
+        image_file = storage.createFile('mysample.txt', dummy_file)
+        result = storage.getFile('mysample')
+        self.assertEqual(result.read(), 'sample file')
+        return
+
+    def test_replace_file_w_new_ext(self):
+        # when we store a file with the same file_id but different
+        # filename extension, the old file will be deleted
+        storage = ExtFileStore(root=self.workdir)
+        dummy_file = StringIO('sample_file')
+        image_file = storage.createFile('mysample.jpg', dummy_file)
+        file1_path = storage.getFile('mysample').name
+        new_file = storage.createFile(
+            'mysample.png', StringIO('new file'))
+        file2 = storage.getFile('mysample')
+        self.assertEqual(file2.name[-12:], 'mysample.png')
+        self.assertEqual(file2.read(), 'new file')
+        # the old file was deleted
+        self.assertFalse(os.path.exists(file1_path))
         return
 
@@ -147,7 +182,8 @@
         return os.path.join(root, file_id[12:])
 
-    def createFile(self, store, root, file_id, filename, f):
-        path = self.pathFromFileID(store, root, file_id)
-        return f, path, HurryFile(filename, file_id)
+    def createFile(self, store, root, filename, file_id, f):
+        ext = os.path.splitext(filename)[1]
+        path = self.pathFromFileID(store, root, file_id) + ext
+        return f, path, HurryFile(filename, file_id + ext)
 
 class CustomContext(object):
@@ -162,7 +198,7 @@
         # the `attr` parameter, a simple string.
         if attr=='img':
-            return '__mymarker__mysample.jpg'
+            return '__mymarker__mysample_img.jpg'
         elif attr=='doc':
-            return '__mymarker__mysample.doc'
+            return '__mymarker__mysample_doc.doc'
         return '__mymarker__mysample.txt'
 
@@ -246,4 +282,14 @@
         return
 
+    def test_customized_handler_create_file_w_ext(self):
+        # when we create a file of img type, the filename ext is taken
+        # from input file.
+        fs = ExtFileStore()
+        result = fs.createFile(
+            '__MYMARKER__sample_img.png', StringIO('sample text'))
+        self.assertEqual(result.data, '__MYMARKER__sample_img.png')
+        self.assertTrue('sample_img.png' in os.listdir(fs.root))
+        return
+
     def test_customized_handler_get_file(self):
         # we consider registered filename handlers when asking for
@@ -279,6 +325,6 @@
         # each file has a different file id
         self.assertEqual(file_id1, '__mymarker__mysample.txt')
-        self.assertEqual(file_id2, '__mymarker__mysample.jpg')
-        self.assertEqual(file_id3, '__mymarker__mysample.doc')
+        self.assertEqual(file_id2, '__mymarker__mysample_img.jpg')
+        self.assertEqual(file_id3, '__mymarker__mysample_doc.doc')
         # each file has different content
         self.assertEqual(result1.read(), 'my sample 1')
