Merge lp:~jcsackett/juju-gui/search-api into lp:juju-gui/experimental

Proposed by j.c.sackett
Status: Merged
Merged at revision: 554
Proposed branch: lp:~jcsackett/juju-gui/search-api
Merge into: lp:juju-gui/experimental
Diff against target: 71 lines (+50/-0)
2 files modified
app/store/charm.js (+17/-0)
test/test_charm_store.js (+33/-0)
To merge this branch: bzr merge lp:~jcsackett/juju-gui/search-api
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+158929@code.launchpad.net

Description of the change

Adds call to API client for charm search

-Adds a method, search, to CharmworldAPI0, to make the search API call.
-Adds a test for it.

Nothing in this is wired into anything; it's used by a subsequent branch that
is doing the sidebar search view.

https://codereview.appspot.com/8612045/

To post a comment you must log in.
Revision history for this message
j.c.sackett (jcsackett) wrote :

Reviewers: mp+158929_code.launchpad.net,

Message:
Please take a look.

Description:
Adds call to API client for charm search

-Adds a method, search, to CharmworldAPI0, to make the search API call.
-Adds a test for it.

Nothing in this is wired into anything; it's used by a subsequent branch
that
is doing the sidebar search view.

https://code.launchpad.net/~jcsackett/juju-gui/search-api/+merge/158929

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/8612045/

Affected files:
   A [revision details]
   M app/store/charm.js
   M test/test_charm_store.js

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision:
<email address hidden>
+New revision: <email address hidden>

Index: test/test_charm_store.js
=== modified file 'test/test_charm_store.js'
--- test/test_charm_store.js 2013-03-26 20:36:21 +0000
+++ test/test_charm_store.js 2013-04-15 13:54:32 +0000
@@ -281,6 +281,38 @@

      });

+ it('handles searching correctly', function(done) {
+ var hostname = 'http://localhost',
+ api = new Y.juju.Charmworld0({
+ apiHost: hostname
+ }),
+ data = [];
+ data.push({
+ responseText: Y.JSON.stringify({
+ name: 'foo'
+ })
+ });
+ // Create a monkeypatched datasource we can use to track the
generated
+ // apiEndpoint
+ var datasource = new Y.DataSource.Local({source: data}),
+ url;
+ datasource.realSendRequest = datasource.sendRequest;
+ datasource.sendRequest = function(params) {
+ url = params.request;
+ datasource.realSendRequest(params);
+ };
+
+ api.set('datasource', datasource);
+ var result = api.search('foo', {
+ success: function(data) {
+ assert.equal('charms?text=foo', url);
+ assert.equal('foo', data.name);
+ done();
+ },
+ failure: function(data, request) {
+ }
+ }, this);
+ });
    });

  })();

Index: app/store/charm.js
=== modified file 'app/store/charm.js'
--- app/store/charm.js 2013-04-08 21:03:12 +0000
+++ app/store/charm.js 2013-04-15 14:02:02 +0000
@@ -202,6 +202,21 @@
      },

      /**
+ * Api call to search charms
+ *
+ * @method search
+ * @param {String} text the search text.
+ */
+ search: function(text, callbacks, bindScope) {
+ var endpoint = 'charms';
+ if (bindScope) {
+ callbacks.success = Y.bind(callbacks.success, bindScope);
+ callbacks.failure = Y.bind(callbacks.failure, bindScope);
+ }
+ this._makeRequest(endpoint, callbacks, {text: text});
+ },
+
+ /**
       * Fetch the contents of a charm's file.
       *
       * @method file

Revision history for this message
Jeff Pihach (hatch) wrote :

LGTM with trivial and cleanup in the test.

https://codereview.appspot.com/8612045/diff/1/app/store/charm.js
File app/store/charm.js (right):

https://codereview.appspot.com/8612045/diff/1/app/store/charm.js#newcode208
app/store/charm.js:208: * @param {String} text the search text.
Missing a couple params.

https://codereview.appspot.com/8612045/diff/1/test/test_charm_store.js
File test/test_charm_store.js (right):

https://codereview.appspot.com/8612045/diff/1/test/test_charm_store.js#newcode286
test/test_charm_store.js:286: api = new Y.juju.Charmworld0({
should be destroyed?

https://codereview.appspot.com/8612045/

Revision history for this message
Richard Harding (rharding) wrote :

LGTM with a couple of notes on naming/var setup.

https://codereview.appspot.com/8612045/diff/1/app/store/charm.js
File app/store/charm.js (right):

https://codereview.appspot.com/8612045/diff/1/app/store/charm.js#newcode208
app/store/charm.js:208: * @param {String} text the search text.
can we standardize on term for the search text? We'll use that in the
query params for the search and it'd be cool to keep it in sync.

https://codereview.appspot.com/8612045/diff/1/test/test_charm_store.js
File test/test_charm_store.js (right):

https://codereview.appspot.com/8612045/diff/1/test/test_charm_store.js#newcode286
test/test_charm_store.js:286: api = new Y.juju.Charmworld0({
multi-line var should be on their own and not grouped. You can move the
url up here though to declare it in the function scope.

https://codereview.appspot.com/8612045/diff/1/test/test_charm_store.js#newcode299
test/test_charm_store.js:299: datasource.realSendRequest =
datasource.sendRequest;
I think you can just set this datasource on the Charmworld0 instance and
it'll use it.

https://codereview.appspot.com/8612045/

Revision history for this message
j.c.sackett (jcsackett) wrote :

Replies here, and changes coming.

https://codereview.appspot.com/8612045/diff/1/app/store/charm.js
File app/store/charm.js (right):

https://codereview.appspot.com/8612045/diff/1/app/store/charm.js#newcode208
app/store/charm.js:208: * @param {String} text the search text.
On 2013/04/15 14:24:36, rharding wrote:
> can we standardize on term for the search text? We'll use that in the
query
> params for the search and it'd be cool to keep it in sync.

Right now we're actually using "text", unless I misunderstand you're
suggestion.

http://staging.jujucharms.com/api/0/charms?text=apache2

https://codereview.appspot.com/8612045/diff/1/app/store/charm.js#newcode208
app/store/charm.js:208: * @param {String} text the search text.
On 2013/04/15 14:13:56, jeff.pihach wrote:
> Missing a couple params.

Fixed.

https://codereview.appspot.com/8612045/diff/1/test/test_charm_store.js
File test/test_charm_store.js (right):

https://codereview.appspot.com/8612045/diff/1/test/test_charm_store.js#newcode286
test/test_charm_store.js:286: api = new Y.juju.Charmworld0({
On 2013/04/15 14:13:56, jeff.pihach wrote:
> should be destroyed?

There are other tests creating 'api' and not destroying it. I have
however added destroy for api in this test, as it passes with it. We may
want to clean up the other tests, but I think that's out of scope for
this, since it's a bit more than a driveby fix.

https://codereview.appspot.com/8612045/diff/1/test/test_charm_store.js#newcode286
test/test_charm_store.js:286: api = new Y.juju.Charmworld0({
On 2013/04/15 14:24:36, rharding wrote:
> multi-line var should be on their own and not grouped. You can move
the url up
> here though to declare it in the function scope.

Done.

https://codereview.appspot.com/8612045/diff/1/test/test_charm_store.js#newcode299
test/test_charm_store.js:299: datasource.realSendRequest =
datasource.sendRequest;
On 2013/04/15 14:24:36, rharding wrote:
> I think you can just set this datasource on the Charmworld0 instance
and it'll
> use it.

Not sure I follow what you mean; I do set it as the datasource on the
instance a few lines down; do you mean reorder declaration and create
the instance after I've created this, and set it in the declaration?

https://codereview.appspot.com/8612045/

lp:~jcsackett/juju-gui/search-api updated
544. By j.c.sackett

Changes from review.

545. By j.c.sackett

Shut up, lint.

Revision history for this message
j.c.sackett (jcsackett) wrote :

*** Submitted:

Adds call to API client for charm search

-Adds a method, search, to CharmworldAPI0, to make the search API call.
-Adds a test for it.

Nothing in this is wired into anything; it's used by a subsequent branch
that
is doing the sidebar search view.

R=jeff.pihach, rharding
CC=
https://codereview.appspot.com/8612045

https://codereview.appspot.com/8612045/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'app/store/charm.js'
2--- app/store/charm.js 2013-04-08 21:03:12 +0000
3+++ app/store/charm.js 2013-04-15 15:50:39 +0000
4@@ -202,6 +202,23 @@
5 },
6
7 /**
8+ * Api call to search charms
9+ *
10+ * @method search
11+ * @param {String} text the search text.
12+ * @param {Object} callbacks the success/failure callbacks to use.
13+ * @param {Object} bindScope the scope of *this* in the callbacks.
14+ */
15+ search: function(text, callbacks, bindScope) {
16+ var endpoint = 'charms';
17+ if (bindScope) {
18+ callbacks.success = Y.bind(callbacks.success, bindScope);
19+ callbacks.failure = Y.bind(callbacks.failure, bindScope);
20+ }
21+ this._makeRequest(endpoint, callbacks, {text: text});
22+ },
23+
24+ /**
25 * Fetch the contents of a charm's file.
26 *
27 * @method file
28
29=== modified file 'test/test_charm_store.js'
30--- test/test_charm_store.js 2013-03-26 20:36:21 +0000
31+++ test/test_charm_store.js 2013-04-15 15:50:39 +0000
32@@ -281,6 +281,39 @@
33
34 });
35
36+ it('handles searching correctly', function(done) {
37+ var hostname = 'http://localhost',
38+ data = [],
39+ url;
40+ var api = new Y.juju.Charmworld0({
41+ apiHost: hostname
42+ });
43+ data.push({
44+ responseText: Y.JSON.stringify({
45+ name: 'foo'
46+ })
47+ });
48+ // Create a monkeypatched datasource we can use to track the generated
49+ // apiEndpoint
50+ var datasource = new Y.DataSource.Local({source: data});
51+ datasource.realSendRequest = datasource.sendRequest;
52+ datasource.sendRequest = function(params) {
53+ url = params.request;
54+ datasource.realSendRequest(params);
55+ };
56+
57+ api.set('datasource', datasource);
58+ var result = api.search('foo', {
59+ success: function(data) {
60+ assert.equal('charms?text=foo', url);
61+ assert.equal('foo', data.name);
62+ done();
63+ },
64+ failure: function(data, request) {
65+ }
66+ }, this);
67+ api.destroy();
68+ });
69 });
70
71 })();

Subscribers

People subscribed via source and target branches