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
1=== modified file 'loggerhead/controllers/inventory_ui.py'
2--- loggerhead/controllers/inventory_ui.py 2009-03-19 00:44:05 +0000
3+++ loggerhead/controllers/inventory_ui.py 2011-03-15 06:23:53 +0000
4@@ -22,7 +22,7 @@
5 import posixpath
6 import urllib
7
8-from paste.httpexceptions import HTTPNotFound
9+from paste.httpexceptions import HTTPNotFound, HTTPMovedPermanently
10
11 from bzrlib import errors
12 from bzrlib.revision import is_null as is_null_rev
13@@ -45,7 +45,7 @@
14
15 template_path = 'loggerhead.templates.inventory'
16
17- def get_filelist(self, inv, path, sort_type):
18+ def get_filelist(self, inv, path, sort_type, revno_url):
19 """
20 return the list of all files (and their attributes) within a given
21 path subtree.
22@@ -58,6 +58,9 @@
23 dir_ie = inv[file_id]
24 file_list = []
25
26+ if dir_ie.kind != 'directory':
27+ raise HTTPMovedPermanently(self._branch.context_url(['/view', revno_url, path]))
28+
29 revid_set = set()
30
31 for filename, entry in dir_ie.children.iteritems():
32@@ -150,7 +153,7 @@
33
34 # Create breadcrumb trail for the path within the branch
35 branch_breadcrumbs = util.branch_breadcrumbs(path, rev_tree, 'files')
36- filelist = self.get_filelist(rev_tree.inventory, path, sort_type)
37+ filelist = self.get_filelist(rev_tree.inventory, path, sort_type, revno_url)
38 else:
39 start_revid = None
40 change = None
41
42=== modified file 'loggerhead/controllers/view_ui.py'
43--- loggerhead/controllers/view_ui.py 2010-12-01 08:30:02 +0000
44+++ loggerhead/controllers/view_ui.py 2011-03-15 06:23:53 +0000
45@@ -25,7 +25,7 @@
46 import bzrlib.textfile
47 import bzrlib.osutils
48
49-from paste.httpexceptions import HTTPBadRequest, HTTPServerError
50+from paste.httpexceptions import HTTPBadRequest, HTTPServerError, HTTPMovedPermanently
51
52 from loggerhead.controllers import TemplatedBranchView
53 try:
54@@ -120,6 +120,9 @@
55 raise HTTPServerError('Could not fetch changes')
56 branch_breadcrumbs = util.branch_breadcrumbs(path, inv, 'files')
57
58+ if inv[file_id].kind == "directory":
59+ raise HTTPMovedPermanently(self._branch.context_url(['/files', revno_url, path]))
60+
61 return {
62 # In AnnotateUI, "annotated" is a generator giving revision
63 # numbers per lines, but the template checks if "annotated" is
64
65=== modified file 'loggerhead/tests/test_controllers.py'
66--- loggerhead/tests/test_controllers.py 2011-02-10 17:01:10 +0000
67+++ loggerhead/tests/test_controllers.py 2011-03-15 06:23:53 +0000
68@@ -47,7 +47,7 @@
69 bzrbranch, inv_ui = self.make_bzrbranch_and_inventory_ui_for_tree_shape(
70 ['filename'])
71 inv = bzrbranch.repository.get_inventory(bzrbranch.last_revision())
72- self.assertEqual(1, len(inv_ui.get_filelist(inv, '', 'filename')))
73+ self.assertEqual(1, len(inv_ui.get_filelist(inv, '', 'filename', 'head')))
74
75 def test_smoke(self):
76 bzrbranch, inv_ui = self.make_bzrbranch_and_inventory_ui_for_tree_shape(
77
78=== modified file 'loggerhead/tests/test_simple.py'
79--- loggerhead/tests/test_simple.py 2011-03-10 14:22:12 +0000
80+++ loggerhead/tests/test_simple.py 2011-03-15 06:23:53 +0000
81@@ -28,7 +28,7 @@
82
83 from loggerhead.apps.branch import BranchWSGIApp
84 from paste.fixture import TestApp
85-from paste.httpexceptions import HTTPExceptionHandler
86+from paste.httpexceptions import HTTPExceptionHandler, HTTPMovedPermanently
87
88
89
90@@ -170,6 +170,33 @@
91 res = app.get('/changes', status=404)
92
93
94+class TestControllerRedirects(BasicTests):
95+ """
96+ Test that a file under /files redirects to /view,
97+ and a directory under /view redirects to /files.
98+ """
99+
100+ def setUp(self):
101+ BasicTests.setUp(self)
102+ self.createBranch()
103+ self.build_tree(('file', 'folder/', 'folder/file'))
104+ self.tree.smart_add([])
105+ self.tree.commit('')
106+
107+ def test_view_folder(self):
108+ app = TestApp(BranchWSGIApp(self.tree.branch, '').app)
109+
110+ e = self.assertRaises(HTTPMovedPermanently, app.get, '/view/head:/folder')
111+ self.assertEqual(e.location(), '/files/head:/folder')
112+
113+ def test_files_file(self):
114+ app = TestApp(BranchWSGIApp(self.tree.branch, '').app)
115+
116+ e = self.assertRaises(HTTPMovedPermanently, app.get, '/files/head:/folder/file')
117+ self.assertEqual(e.location(), '/view/head:/folder/file')
118+ e = self.assertRaises(HTTPMovedPermanently, app.get, '/files/head:/file')
119+ self.assertEqual(e.location(), '/view/head:/file')
120+
121 #class TestGlobalConfig(BasicTests):
122 # """
123 # Test that global config settings are respected

Subscribers

People subscribed via source and target branches