Merge lp:~jason-jasonamyers/maas/clearer-msg-for-api-204-returns into lp:maas/trunk

Proposed by Raphaël Badin on 2015-01-06
Status: Merged
Approved by: Raphaël Badin on 2015-01-09
Approved revision: 3442
Merged at revision: 3441
Proposed branch: lp:~jason-jasonamyers/maas/clearer-msg-for-api-204-returns
Merge into: lp:maas/trunk
Diff against target: 39 lines (+5/-3)
2 files modified
src/maascli/api.py (+1/-1)
src/maascli/tests/test_api.py (+4/-2)
To merge this branch: bzr merge lp:~jason-jasonamyers/maas/clearer-msg-for-api-204-returns
Reviewer Review Type Date Requested Status
Raphaël Badin (community) Approve on 2015-01-08
Review via email: mp+245628@code.launchpad.net

Commit Message

Prints the word Success on receiving a http code of 20X from any API based command via maas-cli.

Description of the Change

Prints the word Success on receiving a http code of 20X from any API based command via maas-cli

To post a comment you must log in.
Raphaël Badin (rvb) wrote :

Thanks for the fix Jason!

Looks generally good but I think we could do a more general fix by printing "Success" for all the 20X responses.

In other words I suggest changing the check above the line you've changed ("response.status == 200") to deal with all 20X response codes instead of adding a new condition and modify the test that you've added accordingly (you should probably merge it with test_print_response_prints_textual_response_with_success_msg and randomly generate 20X response codes).

jasonamyers (jason-jasonamyers) wrote :

so would you like to print the line "Machine-readable output follows:\n"
even if there isn't going to be content like with a 204?

Thanks,
Jason

On Wed, Jan 7, 2015 at 3:49 AM, Raphaël Badin <email address hidden>
wrote:

> Thanks for the fix Jason!
>
> Looks generally good but I think we could do a more general fix by
> printing "Success" for all the 20X responses.
>
> In other words I suggest changing the check above the line you've changed
> ("response.status == 200") to deal with all 20X response codes instead of
> adding a new condition and modify the test that you've added accordingly
> (you should probably merge it with
> test_print_response_prints_textual_response_with_success_msg and randomly
> generate 20X response codes).
> --
>
> https://code.launchpad.net/~jason-jasonamyers/maas/clearer-msg-for-api-204-returns/+merge/245628
> You are the owner of
> lp:~jason-jasonamyers/maas/clearer-msg-for-api-204-returns.
>

Raphaël Badin (rvb) wrote :

> so would you like to print the line "Machine-readable output follows:\n"
> even if there isn't going to be content like with a 204?
>
> Thanks,
> Jason

Yeah, I think that's fine. Even a 200 response could have an empty response. As you pointed out, a 204 response is guaranteed to have an empty response but the textual output has to be clear and simple for human user. The information that the content is empty might be useful (even if the response is a 204).

3441. By jasonamyers on 2015-01-07

Changing code to print a Success message on any HTTP status code of 20X, and updated test to use a random HTTP status code between 200 and 209

Raphaël Badin (rvb) wrote :

Thanks for all the changes. I think this is good to land now. Please just have a look at my remark about how you to check for success error codes. Once this is fixed you can mark the MP approved and the lander will take care of the rest.

review: Approve
3442. By jasonamyers on 2015-01-08

Expanding the range from 20X to any HTTP 200 series status code.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maascli/api.py'
2--- src/maascli/api.py 2014-10-22 10:24:18 +0000
3+++ src/maascli/api.py 2015-01-08 13:36:06 +0000
4@@ -281,7 +281,7 @@
5 If the response is textual, a trailing \n is appended.
6 """
7 if file.isatty():
8- if is_response_textual(response) and response.status == 200:
9+ if is_response_textual(response) and response.status // 100 == 2:
10 file.write("Success.\n")
11 file.write("Machine-readable output follows:\n")
12
13
14=== modified file 'src/maascli/tests/test_api.py'
15--- src/maascli/tests/test_api.py 2014-10-22 10:24:18 +0000
16+++ src/maascli/tests/test_api.py 2015-01-08 13:36:06 +0000
17@@ -19,6 +19,7 @@
18 import httplib
19 import io
20 import json
21+import random
22 import sys
23 from textwrap import dedent
24
25@@ -300,11 +301,12 @@
26 self.assertEqual(response['content'], buf.getvalue())
27
28 def test_print_response_prints_textual_response_with_success_msg(self):
29- # When the response has a status code of 200, and the response
30+ # When the response has a status code of 2XX, and the response
31 # body is textual print_response() will print a success message
32 # to the TTY.
33+ status_code = random.randrange(200, 300)
34 response = httplib2.Response({
35- 'status': httplib.OK,
36+ 'status': status_code,
37 'content': "Lorem ipsum dolor sit amet.",
38 'content-type': 'text/unicode',
39 })