[web] Fix the path to the `static directory` (closes #5355965)
authorKatia Saurfelt <katia.saurfelt@logilab.fr>
Fri, 19 Jun 2015 17:54:04 +0200
changeset 10398 bd00b58b00d9
parent 10397 1ce4594f9cf4
child 10399 5234525560ac
[web] Fix the path to the `static directory` (closes #5355965)
web/test/unittest_views_staticcontrollers.py
web/views/staticcontrollers.py
--- a/web/test/unittest_views_staticcontrollers.py	Thu Jun 18 18:22:55 2015 +0200
+++ b/web/test/unittest_views_staticcontrollers.py	Fri Jun 19 17:54:04 2015 +0200
@@ -51,7 +51,17 @@
         with self._publish_static_files('data/cubicweb.css', next_headers) as req:
             self.assertEqual(304, req.status_out)
 
+class StaticDirectoryControllerTC(staticfilespublishermixin, CubicWebTC):
 
+    def test_check_static_dir_access(self):
+        """write a file in the static directory and test the access"""
+        staticdir = osp.join(self.session.vreg.config.static_directory)
+        if not os.path.exists(staticdir):
+            os.makedirs(staticdir)
+        filename = osp.join(staticdir, 'test')
+        with open(filename, 'a') as f:
+            with self._publish_static_files('static/test') as req:
+                self.assertEqual(200, req.status_out)
 
 class DataControllerTC(staticfilespublishermixin, CubicWebTC):
     tags = CubicWebTC.tags | Tags('static_controller', 'data', 'http')
--- a/web/views/staticcontrollers.py	Thu Jun 18 18:22:55 2015 +0200
+++ b/web/views/staticcontrollers.py	Fri Jun 19 17:54:04 2015 +0200
@@ -243,7 +243,7 @@
 
     def publish(self, rset=None):
         staticdir = self._cw.vreg.config.static_directory
-        relpath = self.relpath
+        relpath = self.relpath[len(self.__regid__) + 1:]
         return self.static_file(osp.join(staticdir, relpath))
 
 STATIC_CONTROLLERS = [DataController, FCKEditorController,