changeset 3621:fe012b7df29d beta

missing files or bad files revisions should return 404s not redirects - ref #808
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 27 Mar 2013 21:05:59 +0100
parents a2afaf84330c
children 91ff741c4de5
files rhodecode/controllers/files.py rhodecode/tests/functional/test_files.py
diffstat 2 files changed, 44 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/controllers/files.py	Wed Mar 27 20:54:12 2013 +0100
+++ b/rhodecode/controllers/files.py	Wed Mar 27 21:05:59 2013 +0100
@@ -56,6 +56,7 @@
 
 from rhodecode.controllers.changeset import anchor_url, _ignorews_url,\
     _context_url, get_line_ctx, get_ignore_ws
+from webob.exc import HTTPNotFound
 
 
 log = logging.getLogger(__name__)
@@ -89,9 +90,9 @@
                     category='warning')
             redirect(h.url('summary_home', repo_name=repo_name))
 
-        except RepositoryError, e: # including ChangesetDoesNotExistError
+        except RepositoryError, e:  # including ChangesetDoesNotExistError
             h.flash(str(e), category='error')
-            redirect(h.url('files_home', repo_name=repo_name, revision='tip'))
+            raise HTTPNotFound()
 
     def __get_filenode_or_redirect(self, repo_name, cs, path):
         """
@@ -109,8 +110,7 @@
                 raise RepositoryError('given path is a directory')
         except RepositoryError, e:
             h.flash(str(e), category='error')
-            redirect(h.url('files_home', repo_name=repo_name,
-                           revision=cs.raw_id))
+            raise HTTPNotFound()
 
         return file_node
 
@@ -122,8 +122,6 @@
         post_revision = request.POST.get('at_rev', None)
         if post_revision:
             cs = self.__get_cs_or_redirect(post_revision, repo_name)
-            redirect(url('files_home', repo_name=c.repo_name,
-                         revision=cs.raw_id, f_path=f_path))
 
         c.changeset = self.__get_cs_or_redirect(revision, repo_name)
         c.branch = request.GET.get('branch', None)
@@ -176,9 +174,8 @@
             else:
                 c.authors = c.file_history = []
         except RepositoryError, e:
-            h.flash(str(e), category='warning')
-            redirect(h.url('files_home', repo_name=repo_name,
-                           revision='tip'))
+            h.flash(str(e), category='error')
+            raise HTTPNotFound()
 
         if request.environ.get('HTTP_X_PARTIAL_XHR'):
             return render('files/files_ypjax.html')
@@ -309,8 +306,7 @@
             author = self.rhodecode_user.full_contact
 
             if content == old_content:
-                h.flash(_('No changes'),
-                    category='warning')
+                h.flash(_('No changes'), category='warning')
                 return redirect(url('changeset_home', repo_name=c.repo_name,
                                     revision='tip'))
             try:
--- a/rhodecode/tests/functional/test_files.py	Wed Mar 27 20:54:12 2013 +0100
+++ b/rhodecode/tests/functional/test_files.py	Wed Mar 27 21:05:59 2013 +0100
@@ -289,12 +289,10 @@
         response = self.app.get(url(controller='files', action='rawfile',
                                     repo_name=HG_REPO,
                                     revision=rev,
-                                    f_path=f_path))
+                                    f_path=f_path), status=404)
 
         msg = """Revision %s does not exist for this repository""" % (rev)
-        self.checkSessionFlash(response, msg)
-
-        self.assertEqual('http://localhost/%s/files/tip/' % HG_REPO, response.headers['location'])
+        response.mustcontain(msg)
 
     def test_raw_file_wrong_f_path(self):
         self.log_user()
@@ -303,10 +301,10 @@
         response = self.app.get(url(controller='files', action='rawfile',
                                     repo_name=HG_REPO,
                                     revision=rev,
-                                    f_path=f_path))
+                                    f_path=f_path), status=404)
 
-        msg = "There is no file nor directory at the given path: '%s' at revision %s" % (f_path, rev[:12])
-        self.checkSessionFlash(response, msg)
+        msg = "There is no file nor directory at the given path: &#39;%s&#39; at revision %s" % (f_path, rev[:12])
+        response.mustcontain(msg)
 
     #==========================================================================
     # RAW RESPONSE - PLAIN
@@ -328,11 +326,10 @@
         response = self.app.get(url(controller='files', action='raw',
                                     repo_name=HG_REPO,
                                     revision=rev,
-                                    f_path=f_path))
+                                    f_path=f_path), status=404)
+
         msg = """Revision %s does not exist for this repository""" % (rev)
-        self.checkSessionFlash(response, msg)
-
-        self.assertEqual('http://localhost/%s/files/tip/' % HG_REPO, response.headers['location'])
+        response.mustcontain(msg)
 
     def test_raw_wrong_f_path(self):
         self.log_user()
@@ -341,15 +338,40 @@
         response = self.app.get(url(controller='files', action='raw',
                                     repo_name=HG_REPO,
                                     revision=rev,
-                                    f_path=f_path))
-        msg = "There is no file nor directory at the given path: '%s' at revision %s" % (f_path, rev[:12])
-        self.checkSessionFlash(response, msg)
+                                    f_path=f_path), status=404)
+        msg = "There is no file nor directory at the given path: &#39;%s&#39; at revision %s" % (f_path, rev[:12])
+        response.mustcontain(msg)
 
     def test_ajaxed_files_list(self):
         self.log_user()
         rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
         response = self.app.get(
-            url('files_nodelist_home', repo_name=HG_REPO,f_path='/',revision=rev),
+            url('files_nodelist_home', repo_name=HG_REPO, f_path='/',
+                revision=rev),
             extra_environ={'HTTP_X_PARTIAL_XHR': '1'},
         )
         response.mustcontain("vcs/web/simplevcs/views/repository.py")
+
+    def test_add_file_view_hg(self):
+        self.log_user()
+        response = self.app.get(url('files_add_home',
+                                      repo_name=HG_REPO,
+                                      revision='tip', f_path='/'))
+
+    def test_add_file_view_git(self):
+        self.log_user()
+        response = self.app.get(url('files_add_home',
+                                      repo_name=GIT_REPO,
+                                      revision='tip', f_path='/'))
+
+    def test_edit_file_view_hg(self):
+        self.log_user()
+        response = self.app.get(url('files_edit_home',
+                                      repo_name=HG_REPO,
+                                      revision='tip', f_path='vcs/nodes.py'))
+
+    def test_edit_file_view_git(self):
+        self.log_user()
+        response = self.app.get(url('files_edit_home',
+                                      repo_name=GIT_REPO,
+                                      revision='tip', f_path='vcs/nodes.py'))