Merge lp:~jstpierre/loggerhead/fix-569358 into lp:loggerhead

Proposed by Jasper St. Pierre
Status: Merged
Approved by: John A Meinel
Approved revision: 435
Merged at revision: 434
Proposed branch: lp:~jstpierre/loggerhead/fix-569358
Merge into: lp:loggerhead
Diff against target: 123 lines (+39/-6)
4 files modified
loggerhead/controllers/inventory_ui.py (+6/-3)
loggerhead/controllers/view_ui.py (+4/-1)
loggerhead/tests/test_controllers.py (+1/-1)
loggerhead/tests/test_simple.py (+28/-1)
To merge this branch: bzr merge lp:~jstpierre/loggerhead/fix-569358
Reviewer Review Type Date Requested Status
John A Meinel Approve
Review via email: mp+53137@code.launchpad.net

Description of the change

Fix bug 569358 - "Cannot view directory by editing URLs"

Helping lvh out one by one.

To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 3/12/2011 6:29 PM, Jasper St. Pierre wrote:
> Jasper St. Pierre has proposed merging lp:~jstpierre/loggerhead/fix-569358 into lp:loggerhead.
>
> Requested reviews:
> Loggerhead Reviewers (loggerhead-reviewers)
> Related bugs:
> Bug #569358 in loggerhead: "Cannot view a directory by editing urls"
> https://bugs.launchpad.net/loggerhead/+bug/569358
>
> For more details, see:
> https://code.launchpad.net/~jstpierre/loggerhead/fix-569358/+merge/53137
>
> Fix bug 569358 - "Cannot view directory by editing URLs"
>
> Helping lvh out one by one.

Would it be possible to add some tests here? If you need help, you can
ask. A simple test that builds a tree with both a file and a directory,
and ensures that asking for /view of the directory triggers a redirect
exception, and /files of the file triggers the appropriate redirect?

 review: needsfixing

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk19+dAACgkQJdeBCYSNAANjYQCgr1+wNnKKpV7bYrr7eqtvDOqW
cgMAoJSurns7LZCvwGwHihMJJlrijsm1
=iq2S
-----END PGP SIGNATURE-----

review: Needs Fixing
lp:~jstpierre/loggerhead/fix-569358 updated
434. By Jasper St. Pierre

Add tests

435. By Jasper St. Pierre

Fix tests

Revision history for this message
John A Meinel (jameinel) wrote :

Tested manually, and the new tests look just right for what we want. Thanks for working on this, and thanks for responding to requests for tests. Looks great.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'loggerhead/controllers/inventory_ui.py'
--- loggerhead/controllers/inventory_ui.py 2009-03-19 00:44:05 +0000
+++ loggerhead/controllers/inventory_ui.py 2011-03-15 06:23:53 +0000
@@ -22,7 +22,7 @@
22import posixpath22import posixpath
23import urllib23import urllib
2424
25from paste.httpexceptions import HTTPNotFound25from paste.httpexceptions import HTTPNotFound, HTTPMovedPermanently
2626
27from bzrlib import errors27from bzrlib import errors
28from bzrlib.revision import is_null as is_null_rev28from bzrlib.revision import is_null as is_null_rev
@@ -45,7 +45,7 @@
4545
46 template_path = 'loggerhead.templates.inventory'46 template_path = 'loggerhead.templates.inventory'
4747
48 def get_filelist(self, inv, path, sort_type):48 def get_filelist(self, inv, path, sort_type, revno_url):
49 """49 """
50 return the list of all files (and their attributes) within a given50 return the list of all files (and their attributes) within a given
51 path subtree.51 path subtree.
@@ -58,6 +58,9 @@
58 dir_ie = inv[file_id]58 dir_ie = inv[file_id]
59 file_list = []59 file_list = []
6060
61 if dir_ie.kind != 'directory':
62 raise HTTPMovedPermanently(self._branch.context_url(['/view', revno_url, path]))
63
61 revid_set = set()64 revid_set = set()
6265
63 for filename, entry in dir_ie.children.iteritems():66 for filename, entry in dir_ie.children.iteritems():
@@ -150,7 +153,7 @@
150153
151 # Create breadcrumb trail for the path within the branch154 # Create breadcrumb trail for the path within the branch
152 branch_breadcrumbs = util.branch_breadcrumbs(path, rev_tree, 'files')155 branch_breadcrumbs = util.branch_breadcrumbs(path, rev_tree, 'files')
153 filelist = self.get_filelist(rev_tree.inventory, path, sort_type)156 filelist = self.get_filelist(rev_tree.inventory, path, sort_type, revno_url)
154 else:157 else:
155 start_revid = None158 start_revid = None
156 change = None159 change = None
157160
=== modified file 'loggerhead/controllers/view_ui.py'
--- loggerhead/controllers/view_ui.py 2010-12-01 08:30:02 +0000
+++ loggerhead/controllers/view_ui.py 2011-03-15 06:23:53 +0000
@@ -25,7 +25,7 @@
25import bzrlib.textfile25import bzrlib.textfile
26import bzrlib.osutils26import bzrlib.osutils
2727
28from paste.httpexceptions import HTTPBadRequest, HTTPServerError28from paste.httpexceptions import HTTPBadRequest, HTTPServerError, HTTPMovedPermanently
2929
30from loggerhead.controllers import TemplatedBranchView30from loggerhead.controllers import TemplatedBranchView
31try:31try:
@@ -120,6 +120,9 @@
120 raise HTTPServerError('Could not fetch changes')120 raise HTTPServerError('Could not fetch changes')
121 branch_breadcrumbs = util.branch_breadcrumbs(path, inv, 'files')121 branch_breadcrumbs = util.branch_breadcrumbs(path, inv, 'files')
122122
123 if inv[file_id].kind == "directory":
124 raise HTTPMovedPermanently(self._branch.context_url(['/files', revno_url, path]))
125
123 return {126 return {
124 # In AnnotateUI, "annotated" is a generator giving revision127 # In AnnotateUI, "annotated" is a generator giving revision
125 # numbers per lines, but the template checks if "annotated" is128 # numbers per lines, but the template checks if "annotated" is
126129
=== modified file 'loggerhead/tests/test_controllers.py'
--- loggerhead/tests/test_controllers.py 2011-02-10 17:01:10 +0000
+++ loggerhead/tests/test_controllers.py 2011-03-15 06:23:53 +0000
@@ -47,7 +47,7 @@
47 bzrbranch, inv_ui = self.make_bzrbranch_and_inventory_ui_for_tree_shape(47 bzrbranch, inv_ui = self.make_bzrbranch_and_inventory_ui_for_tree_shape(
48 ['filename'])48 ['filename'])
49 inv = bzrbranch.repository.get_inventory(bzrbranch.last_revision())49 inv = bzrbranch.repository.get_inventory(bzrbranch.last_revision())
50 self.assertEqual(1, len(inv_ui.get_filelist(inv, '', 'filename')))50 self.assertEqual(1, len(inv_ui.get_filelist(inv, '', 'filename', 'head')))
5151
52 def test_smoke(self):52 def test_smoke(self):
53 bzrbranch, inv_ui = self.make_bzrbranch_and_inventory_ui_for_tree_shape(53 bzrbranch, inv_ui = self.make_bzrbranch_and_inventory_ui_for_tree_shape(
5454
=== modified file 'loggerhead/tests/test_simple.py'
--- loggerhead/tests/test_simple.py 2011-03-10 14:22:12 +0000
+++ loggerhead/tests/test_simple.py 2011-03-15 06:23:53 +0000
@@ -28,7 +28,7 @@
2828
29from loggerhead.apps.branch import BranchWSGIApp29from loggerhead.apps.branch import BranchWSGIApp
30from paste.fixture import TestApp30from paste.fixture import TestApp
31from paste.httpexceptions import HTTPExceptionHandler31from paste.httpexceptions import HTTPExceptionHandler, HTTPMovedPermanently
3232
3333
3434
@@ -170,6 +170,33 @@
170 res = app.get('/changes', status=404)170 res = app.get('/changes', status=404)
171171
172172
173class TestControllerRedirects(BasicTests):
174 """
175 Test that a file under /files redirects to /view,
176 and a directory under /view redirects to /files.
177 """
178
179 def setUp(self):
180 BasicTests.setUp(self)
181 self.createBranch()
182 self.build_tree(('file', 'folder/', 'folder/file'))
183 self.tree.smart_add([])
184 self.tree.commit('')
185
186 def test_view_folder(self):
187 app = TestApp(BranchWSGIApp(self.tree.branch, '').app)
188
189 e = self.assertRaises(HTTPMovedPermanently, app.get, '/view/head:/folder')
190 self.assertEqual(e.location(), '/files/head:/folder')
191
192 def test_files_file(self):
193 app = TestApp(BranchWSGIApp(self.tree.branch, '').app)
194
195 e = self.assertRaises(HTTPMovedPermanently, app.get, '/files/head:/folder/file')
196 self.assertEqual(e.location(), '/view/head:/folder/file')
197 e = self.assertRaises(HTTPMovedPermanently, app.get, '/files/head:/file')
198 self.assertEqual(e.location(), '/view/head:/file')
199
173#class TestGlobalConfig(BasicTests):200#class TestGlobalConfig(BasicTests):
174# """201# """
175# Test that global config settings are respected202# Test that global config settings are respected

Subscribers

People subscribed via source and target branches