Merge lp:~gmb/launchpad/bug-197775 into lp:launchpad

Proposed by Graham Binns on 2010-11-18
Status: Merged
Approved by: Graham Binns on 2010-11-19
Approved revision: no longer in the source branch.
Merged at revision: 11969
Proposed branch: lp:~gmb/launchpad/bug-197775
Merge into: lp:launchpad
Diff against target: 138 lines (+37/-5)
4 files modified
lib/canonical/launchpad/ftests/_launchpadformharness.py (+4/-2)
lib/lp/bugs/stories/structural-subscriptions/xx-bug-subscriptions.txt (+12/-0)
lib/lp/registry/browser/structuralsubscription.py (+4/-1)
lib/lp/registry/browser/tests/test_structuralsubscription.py (+17/-2)
To merge this branch: bzr merge lp:~gmb/launchpad/bug-197775
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code 2010-11-18 Approve on 2010-11-19
j.c.sackett (community) code* 2010-11-18 Approve on 2010-11-18
Review via email: mp+41171@code.launchpad.net

Commit Message

[r=jcsackett,sinzui][ui=none][bug=197775] Submitting the +subscribe form of a StructuralSubscription target will now take you to the context's canonical_url rather than returning you to the form.

Description of the Change

This branch fixes bug 197775 by changing the next_url for StructuralSubscriptionView to be the canonical URL of the context rather than the context's +subscribe page.

To post a comment you must log in.
j.c.sackett (jcsackett) wrote :
Download full text (4.2 KiB)

Graham--

I like anything that gets rid of manual url hacking/building in the code. This will be nice.

I have a few comments below.

> === modified file 'lib/canonical/launchpad/ftests/_launchpadformharness.py'
> --- lib/canonical/launchpad/ftests/_launchpadformharness.py 2010-08-20 20:31:18 +0000
> +++ lib/canonical/launchpad/ftests/_launchpadformharness.py 2010-11-18 14:02:07 +0000
> @@ -19,15 +19,17 @@
> class LaunchpadFormHarness:
>
> def __init__(self, context, view_class, form_values=None,
> - request_class=LaunchpadTestRequest):
> + request_class=LaunchpadTestRequest, request_environ=None):
> self.context = context
> self.view_class = view_class
> self.request_class = request_class
> + self.request_environ = request_environ
> self._render(form_values)
>
> def _render(self, form_values=None, method='GET'):
> self.request = self.request_class(
> - method=method, form=form_values, PATH_INFO='/')
> + method=method, form=form_values, PATH_INFO='/',
> + environ=self.request_environ)
> if queryInteraction() is not None:
> self.request.setPrincipal(get_current_principal())
> # Setup a new interaction using self.request, create the view,
> @@ -58,3 +60,4 @@
>
> def redirectionTarget(self):
> return self.request.response.getHeader('location')
> + self.request_environ = request_environ

Doesn't this require passing in request_environ as an argument? Or is it in scope in a way I have missed?

> === modified file 'lib/lp/registry/browser/structuralsubscription.py'
> --- lib/lp/registry/browser/structuralsubscription.py 2010-11-10 11:13:05 +0000
> +++ lib/lp/registry/browser/structuralsubscription.py 2010-11-18 14:02:07 +0000
> @@ -205,7 +205,7 @@
> self._handleUserSubscription(data)
> self._handleTeamSubscriptions(data)
> self._handleDriverChanges(data)
> - self.next_url = canonical_url(self.context) + '/+subscribe'
> + self.next_url = canonical_url(self.context)
>
> def _handleUserSubscription(self, data):
> """Process the subscription for the user."""
>
> === modified file 'lib/lp/registry/browser/tests/test_structuralsubscription.py'
> --- lib/lp/registry/browser/tests/test_structuralsubscription.py 2010-11-10 11:33:45 +0000
> +++ lib/lp/registry/browser/tests/test_structuralsubscription.py 2010-11-18 14:02:07 +0000
> @@ -282,5 +282,35 @@
> self.target = self.factory.makeMilestone()

There are a couple of lint errors in the test file:

> +class TestStructuralSubscriptionView(TestCaseWithFactory):
> + """General tests for the StructuralSubscriptionView."""
> +
> + layer = LaunchpadFunctionalLayer
> +
> + def test_next_url_set_to_context(self):
> + # When the StructuralSubscriptionView form is submitted, the
> + # view's next_url is set to the canonical_url of the current
> + # target.
> + target = self.factory.makeProduct()
> + person = self.factory.makePerson()
> + with person_logged_in(person):
> + harness = LaunchpadFormHarness(
> + target, ...

Read more...

Graham Binns (gmb) wrote :

I've made the changes as requested.

j.c.sackett (jcsackett) wrote :

Thanks for making those changes, Graham.

review: Approve (code*)
Curtis Hovey (sinzui) wrote :

Does this test really require the librarian (LaunchpadFunctionalLayer)? This looks like it requires DatabaseFunctionalLayer.

Why isn't this tested with lp.testing.views.create_initialized_view?

    view = create_initialized_view(target, name='+subscribe', form=form)
    self.assertEqual(canonical_url(target), view.next_url)

We can remove the loadTestsFromName() stuff. The testrunner will find the test without
it.

review: Needs Information (code)
Graham Binns (gmb) wrote :

> Does this test really require the librarian (LaunchpadFunctionalLayer)? This
> looks like it requires DatabaseFunctionalLayer.
>

It doesn't. Fixed.

> Why isn't this tested with lp.testing.views.create_initialized_view?
>
> view = create_initialized_view(target, name='+subscribe', form=form)
> self.assertEqual(canonical_url(target), view.next_url)
>

Out of habit. I've been using the harness elsewhere. Fixed.

> We can remove the loadTestsFromName() stuff. The testrunner will find the test
> without
> it.

Done.

Curtis Hovey (sinzui) wrote :

Thank you for addressing my concerns,

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/launchpad/ftests/_launchpadformharness.py'
2--- lib/canonical/launchpad/ftests/_launchpadformharness.py 2010-08-20 20:31:18 +0000
3+++ lib/canonical/launchpad/ftests/_launchpadformharness.py 2010-11-23 13:30:34 +0000
4@@ -19,15 +19,17 @@
5 class LaunchpadFormHarness:
6
7 def __init__(self, context, view_class, form_values=None,
8- request_class=LaunchpadTestRequest):
9+ request_class=LaunchpadTestRequest, request_environ=None):
10 self.context = context
11 self.view_class = view_class
12 self.request_class = request_class
13+ self.request_environ = request_environ
14 self._render(form_values)
15
16 def _render(self, form_values=None, method='GET'):
17 self.request = self.request_class(
18- method=method, form=form_values, PATH_INFO='/')
19+ method=method, form=form_values, PATH_INFO='/',
20+ environ=self.request_environ)
21 if queryInteraction() is not None:
22 self.request.setPrincipal(get_current_principal())
23 # Setup a new interaction using self.request, create the view,
24
25=== modified file 'lib/lp/bugs/stories/structural-subscriptions/xx-bug-subscriptions.txt'
26--- lib/lp/bugs/stories/structural-subscriptions/xx-bug-subscriptions.txt 2010-10-17 15:44:08 +0000
27+++ lib/lp/bugs/stories/structural-subscriptions/xx-bug-subscriptions.txt 2010-11-23 13:30:34 +0000
28@@ -15,6 +15,8 @@
29 >>> subscribe_team.selected = True
30 >>> browser.getControl('Save these changes').click()
31
32+ >>> browser.open(
33+ ... 'http://bugs.launchpad.dev/ubuntu/+subscribe')
34 >>> print extract_text(find_portlet(browser.contents, 'Bug subscriptions'))
35 Bug subscriptions
36 For Ubuntu Linux:
37@@ -38,6 +40,8 @@
38
39 Sample Person and the Landscape team are now subscribed.
40
41+ >>> browser.open(
42+ ... 'http://bugs.launchpad.dev/ubuntu/+source/mozilla-firefox/+subscribe')
43 >>> print extract_text(find_portlet(
44 ... browser.contents, 'Bug subscriptions')).encode(
45 ... 'ascii', 'backslashreplace')
46@@ -57,6 +61,8 @@
47 >>> subscribe_team = browser.getControl('Landscape')
48 >>> subscribe_team.selected = False
49 >>> browser.getControl('Save these changes').click()
50+ >>> browser.open(
51+ ... 'http://bugs.launchpad.dev/ubuntu/+source/mozilla-firefox/+subscribe')
52 >>> print extract_text(find_portlet(browser.contents, 'Bug subscriptions'))
53 Bug subscriptions
54 For...mozilla-firefox...package in Ubuntu:
55@@ -102,6 +108,8 @@
56 No Privileges Person will now receive an e-mail each time someone reports
57 or changes a public bug in "mozilla-firefox in ubuntu".
58
59+ >>> browser.open(
60+ ... 'http://bugs.launchpad.dev/ubuntu/+source/mozilla-firefox/+subscribe')
61 >>> print extract_text(find_portlet(browser.contents, 'Bug subscriptions'))
62 Bug subscriptions
63 For...mozilla-firefox...package in Ubuntu:
64@@ -122,6 +130,8 @@
65 ... browser.contents, 'informational message')[0].contents[0]
66 No Privileges Person will no longer automatically receive e-mail about
67 public bugs in "mozilla-firefox in ubuntu".
68+ >>> browser.open(
69+ ... 'http://bugs.launchpad.dev/ubuntu/+source/mozilla-firefox/+subscribe')
70 >>> print extract_text(find_portlet(browser.contents, 'Bug subscriptions'))
71 Bug subscriptions
72 For...mozilla-firefox...package in Ubuntu:
73@@ -160,6 +170,8 @@
74 >>> subscribe_other = browser.getControl('Subscribe someone else:')
75 >>> subscribe_other.value = 'nopriv'
76 >>> browser.getControl('Save these changes').click()
77+ >>> browser.open(
78+ ... 'http://bugs.launchpad.dev/ubuntu/+source/mozilla-firefox/+subscribe')
79 >>> print extract_text(find_portlet(browser.contents, 'Bug subscriptions'))
80 Bug subscriptions
81 For...mozilla-firefox...package in Ubuntu:
82
83=== modified file 'lib/lp/registry/browser/structuralsubscription.py'
84--- lib/lp/registry/browser/structuralsubscription.py 2010-11-10 11:13:05 +0000
85+++ lib/lp/registry/browser/structuralsubscription.py 2010-11-23 13:30:34 +0000
86@@ -80,6 +80,10 @@
87 def label(self):
88 return self.page_title
89
90+ @property
91+ def next_url(self):
92+ return canonical_url(self.context)
93+
94 def setUpFields(self):
95 """See LaunchpadFormView."""
96 LaunchpadFormView.setUpFields(self)
97@@ -205,7 +209,6 @@
98 self._handleUserSubscription(data)
99 self._handleTeamSubscriptions(data)
100 self._handleDriverChanges(data)
101- self.next_url = canonical_url(self.context) + '/+subscribe'
102
103 def _handleUserSubscription(self, data):
104 """Process the subscription for the user."""
105
106=== modified file 'lib/lp/registry/browser/tests/test_structuralsubscription.py'
107--- lib/lp/registry/browser/tests/test_structuralsubscription.py 2010-11-18 16:13:19 +0000
108+++ lib/lp/registry/browser/tests/test_structuralsubscription.py 2010-11-23 13:30:34 +0000
109@@ -37,6 +37,7 @@
110 set_feature_flag,
111 TestCaseWithFactory,
112 )
113+from lp.testing.views import create_initialized_view
114
115
116 class FakeLaunchpadRequest(FakeRequest):
117@@ -293,5 +294,19 @@
118 self.target = self.factory.makeMilestone()
119
120
121-def test_suite():
122- return unittest.TestLoader().loadTestsFromName(__name__)
123+class TestStructuralSubscriptionView(TestCaseWithFactory):
124+ """General tests for the StructuralSubscriptionView."""
125+
126+ layer = DatabaseFunctionalLayer
127+
128+ def test_next_url_set_to_context(self):
129+ # When the StructuralSubscriptionView form is submitted, the
130+ # view's next_url is set to the canonical_url of the current
131+ # target.
132+ target = self.factory.makeProduct()
133+ person = self.factory.makePerson()
134+ with person_logged_in(person):
135+ view = create_initialized_view(target, name='+subscribe')
136+ self.assertEqual(
137+ canonical_url(target), view.next_url,
138+ "Next URL does not match target's canonical_url.")