Merge lp:~bac/launchpad/js-client-link into lp:launchpad

Proposed by Brad Crittenden
Status: Merged
Approved by: Brad Crittenden
Approved revision: no longer in the source branch.
Merged at revision: 14634
Proposed branch: lp:~bac/launchpad/js-client-link
Merge into: lp:launchpad
Diff against target: 95 lines (+33/-8)
3 files modified
lib/lp/app/javascript/client.js (+9/-7)
lib/lp/app/javascript/tests/test_lp_client_integration.js (+15/-1)
lib/lp/app/javascript/tests/test_lp_client_integration.py.disabled (+9/-0)
To merge this branch: bzr merge lp:~bac/launchpad/js-client-link
Reviewer Review Type Date Requested Status
Benji York (community) code Approve
Review via email: mp+87532@code.launchpad.net

Commit message

[r=benji][bug=911973] Set lp_original_uri properly for objects returned by named_get and named_post that have a self_link.

Description of the change

If the object returned by wrap_resource_on_success has a self_link, it
should be used as the URI (eventually set as lp_original_uri).

You'll note I added a test to test_lp_client_integration even though
it remains disabled.

To post a comment you must log in.
Revision history for this message
Benji York (benji) wrote :

This looks good. As discussed on IRC, we may be able to remove the wrap_resource functionality that substitutes lp_redirect_location for the passed in uri.

review: Approve (code)
Revision history for this message
Brad Crittenden (bac) wrote :

Thanks for the review Benji. I have removed lp_redirect_location.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/app/javascript/client.js'
2--- lib/lp/app/javascript/client.js 2011-12-19 09:53:25 +0000
3+++ lib/lp/app/javascript/client.js 2012-01-04 21:05:43 +0000
4@@ -343,12 +343,17 @@
5 representation = Y.JSON.parse(response.responseText);
6 // If the response contains a notification header, display the
7 // notifications.
8- notificaxns = response.getResponseHeader('X-Lazr-Notifications');
9- if (notificaxns !== null) {
10- module.display_notifications(notificaxns);
11+ var notifications = response.getResponseHeader(
12+ 'X-Lazr-Notifications');
13+ if (notifications !== null) {
14+ module.display_notifications(notifications);
15+ }
16+ if (Y.Lang.isValue(representation) &&
17+ Y.Lang.isValue(representation.self_link)) {
18+ uri = representation.self_link;
19 }
20 wrapped = client.wrap_resource(uri, representation);
21- result = old_on_success(wrapped);
22+ var result = old_on_success(wrapped);
23 if (update_cache) {
24 module.update_cache(wrapped);
25 }
26@@ -801,9 +806,6 @@
27 if (representation === null || representation === undefined) {
28 return representation;
29 }
30- if (representation.lp_redirect_location !== undefined) {
31- uri = representation.lp_redirect_location;
32- }
33 if (representation.resource_type_link === undefined) {
34 // This is a non-entry object returned by a named operation.
35 // It's either a list or a random JSON object.
36
37=== modified file 'lib/lp/app/javascript/tests/test_lp_client_integration.js'
38--- lib/lp/app/javascript/tests/test_lp_client_integration.js 2011-11-18 17:09:28 +0000
39+++ lib/lp/app/javascript/tests/test_lp_client_integration.js 2012-01-04 21:05:43 +0000
40@@ -127,13 +127,27 @@
41 Y.Assert.areSame(1, config.result.total_size);
42 },
43
44+ test_named_get_uri: function() {
45+ var data = serverfixture.setup(
46+ this, 'create_product_with_milestone_and_login');
47+ var client = new Y.lp.client.Launchpad({sync: true});
48+ var config = makeTestConfig({parameters: {name: data.milestone.name}});
49+ var product = new Y.lp.client.Entry(
50+ client, data.product, data.product.self_link);
51+ product.named_get('getMilestone', config);
52+ Y.Assert.isTrue(config.successful, 'Getting milestone failed');
53+ var milestone = config.result;
54+ Y.Assert.isInstanceOf(Y.lp.client.Entry, milestone);
55+ Y.Assert.areSame(data.milestone_self_link, milestone.lp_original_uri);
56+ },
57+
58 test_named_post_integration: function() {
59 var data = serverfixture.setup(this, 'create_bug_and_login');
60 var client = new Y.lp.client.Launchpad({sync: true});
61 var config = makeTestConfig();
62 client.named_post(
63 data.bug.self_link, 'mute', config);
64- Y.Assert.isTrue(config.successful);
65+ Y.Assert.isTrue(config.successful, "named_post failed: " + config.result);
66 },
67
68 test_follow_link: function() {
69
70=== modified file 'lib/lp/app/javascript/tests/test_lp_client_integration.py.disabled'
71--- lib/lp/app/javascript/tests/test_lp_client_integration.py.disabled 2011-11-23 07:14:36 +0000
72+++ lib/lp/app/javascript/tests/test_lp_client_integration.py.disabled 2012-01-04 21:05:43 +0000
73@@ -7,6 +7,9 @@
74 __metaclass__ = type
75 __all__ = []
76
77+from zope.traversing.browser import absoluteURL
78+from lazr.restful.interfaces import IWebServiceClientRequest
79+
80 from lp.testing import person_logged_in
81 from lp.testing.yuixhr import (
82 login_as_person,
83@@ -38,6 +41,12 @@
84 def create_product_and_login(request, data):
85 login_as_person(data['user'])
86
87+@create_product_and_login.extend
88+def create_product_with_milestone_and_login(request, data):
89+ data['milestone'] = factory.makeMilestone(
90+ product=data['product'])
91+ api_request = IWebServiceClientRequest(request)
92+ data['milestone_self_link'] = absoluteURL(data['milestone'], api_request)
93
94 @create_product_and_login.extend
95 def create_bug_and_login(request, data):