← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~gmb/launchpad/bug-197775 into lp:launchpad/devel

 

Graham Binns has proposed merging lp:~gmb/launchpad/bug-197775 into lp:launchpad/devel.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  #197775 "Change bug subscriptions" page returns to "Change bug subscriptions" page
  https://bugs.launchpad.net/bugs/197775


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.
-- 
https://code.launchpad.net/~gmb/launchpad/bug-197775/+merge/41171
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~gmb/launchpad/bug-197775 into lp:launchpad/devel.
=== 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

=== 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()
 
 
+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, StructuralSubscriptionView,
+                # We need to specify this so that the assertEqual()
+                # below works. The LaunchpadTestRequest uses 127.0.0.1
+                # by default for its hostname.
+                request_environ={
+                    'SERVER_URL':         'http://launchpad.dev',
+                    'HTTP_HOST':          'launchpad.dev',
+                    })
+            form_data = {
+                'field.subscribe_me': 'on',
+                }
+            harness.submit('save', form_data)
+            self.assertEqual(
+                canonical_url(target),
+                harness.view.next_url,
+                "Next URL does not match target's canonical_url.")
+
 def test_suite():
     return unittest.TestLoader().loadTestsFromName(__name__)