Comment 4 for bug 583318

Revision history for this message
Leonard Richardson (leonardr) wrote :

I wrote some lazr.restfulclient tests. The plot thickens!

1. The reason launchpad.projects['foo'].getMergeProposals() makes a request for /projects/foo is that the ability to do .projects['foo'] in the first place is a launchpadlib hack. There's no indication in the WADL that this is possible, and no information in the WADL or in the launchpadlib hack about what kind of object .projects['foo'] is going to be. If we know it's a project (and it shouldn't be that hard to figure it out or add it to the hack), we can avoid making that request.

2. Here's some lazr.restfulclient code I use in my test.

recipe1 = services.recipes[1]
recipes = recipe1.cookbook.find_recipes(search="bar")

The first LOC makes a request for /recipes/1 for the reason given above--the service-specific hack.

The second LOC makes one and only one request, to /cookbooks/Cookbook%20Name?ws.op=find_recipes. It does NOT make a request to /cookbooks/Cookbook%20Name.

Now, here's some launchpadlib code.

bug = launchpad.bugs[1]
branches = bug.owner.getBranches()

The first LOC makes a request for /bugs/1.

The second LOC makes what appears to be TWO requests for /~sabdfl, and only then makes a request for /~sabdfl?ws.op=getBranches. 'bug.owner' all on its own makes TWO requests for /~sabdfl.

Clearly something funny is going on. Here are the two requests for /~safbdl:

>>> bug.owner
send: 'GET /1.0/~sabdfl HTTP/1.1\r\nHost: api.staging.launchpad.net\r\nAccept-Encoding: identity\r\nte: deflate, gzip\r\nAuthorization: OAuth realm="OAuth", oauth_nonce="50222755", oauth_timestamp="1276634241", oauth_consumer_key="foo", oauth_signature_method="PLAINTEXT", oauth_version="1.0", oauth_token="", oauth_signature="%26"\r\naccept: application/json\r\nuser-agent: lazr.restfulclient 0.9.14; oauth_consumer="foo"\r\n\r\n'
reply: ''
send: 'GET /1.0/~sabdfl HTTP/1.1\r\nHost: api.staging.launchpad.net\r\nAccept-Encoding: identity\r\nte: deflate, gzip\r\nAuthorization: OAuth realm="OAuth", oauth_nonce="50222755", oauth_timestamp="1276634241", oauth_consumer_key="foo", oauth_signature_method="PLAINTEXT", oauth_version="1.0", oauth_token="", oauth_signature="%26"\r\naccept: application/json\r\nuser-agent: lazr.restfulclient 0.9.14; oauth_consumer="foo"\r\n\r\n'
reply: 'HTTP/1.1 200 Ok\r\n'
...
<person at https://api.staging.launchpad.net/1.0/~sabdfl>

The first request gets no reply, and the two requests have the same nonce, so it's likely something weird is happening and that first request is not really going over the wire. But according to the lazr.restfulclient example, there should be NO request happening here. I don't know why launchpadlib feels the need to make this request at all.

To sum up, we have a problem that can be fixed in lazr.restfulclient + launchpadlib, and a problem that seems specific to launchpadlib about which I have no clue. But we're actually in better shape than I thought. I wrote a whole bunch of tests against lazr.restfulclient to test the features I thought I'd be adding, and all but one of the tests pass already.