Merge ~jsseidel/maas:jsseidel-add-annotation-type into maas:master

Proposed by Spencer Seidel
Status: Merged
Approved by: Newell Jensen
Approved revision: 234d4d284dcae00175afeca804c0e2087e52195d
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~jsseidel/maas:jsseidel-add-annotation-type
Merge into: maas:master
Diff against target: 102 lines (+42/-3)
2 files modified
src/maasserver/api/annotations.py (+5/-1)
src/maasserver/api/tests/test_annotations.py (+37/-2)
Reviewer Review Type Date Requested Status
MAAS Lander Approve
Blake Rouse (community) Approve
Review via email: mp+357692@code.launchpad.net

Commit message

Added addition API annotation type "json".

To post a comment you must log in.
Revision history for this message
Blake Rouse (blake-rouse) wrote :

Looks good.

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b jsseidel-add-annotation-type lp:~jsseidel/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 234d4d284dcae00175afeca804c0e2087e52195d

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/api/annotations.py b/src/maasserver/api/annotations.py
2index 7233150..8d02791 100644
3--- a/src/maasserver/api/annotations.py
4+++ b/src/maasserver/api/annotations.py
5@@ -31,6 +31,7 @@ embedded annoations of the form:
6
7 string: a unicode string
8 int: an integer
9+ json: a json object
10 url-string: a URL-encoded string
11 http-status-code: an HTTP status code
12 content: content served via a MAAS server
13@@ -153,7 +154,8 @@ class APIDocstringParser:
14 "url-string",
15 "int",
16 "content",
17- "http-status-code"
18+ "http-status-code",
19+ "json"
20 ]
21
22 @staticmethod
23@@ -181,6 +183,8 @@ class APIDocstringParser:
24 return "URL String"
25 elif ttype == "http-status-code":
26 return "HTTP Status Code"
27+ elif ttype == "json":
28+ return "JSON"
29
30 return ttype.title().replace("-", " ")
31
32diff --git a/src/maasserver/api/tests/test_annotations.py b/src/maasserver/api/tests/test_annotations.py
33index 312cfcd..5a5eea7 100644
34--- a/src/maasserver/api/tests/test_annotations.py
35+++ b/src/maasserver/api/tests/test_annotations.py
36@@ -34,6 +34,13 @@ class TestAPIAnnotations(APITestCase.ForUser):
37 @param (url-string) "param_name3" [required=false] param3 description
38 @param-example "param_name3" param3-ex
39
40+ @param (json) "param_name4" [required=false] param4 description
41+ @param-example "param_name4"
42+ {
43+ "id": 1,
44+ "foo": "bar"
45+ }
46+
47 @success (content) "success_name" success description
48 @success-example "success_name" success content
49
50@@ -121,6 +128,15 @@ class TestAPIAnnotations(APITestCase.ForUser):
51 " ".join(p['description'].split()), "param3 description")
52 self.assertEqual(" ".join(p['example'].split()), "param3-ex")
53
54+ p = params[3]
55+ self.assertEqual(p['type'], "JSON")
56+ self.assertEqual(p['name'], "param_name4")
57+ self.assertEqual(
58+ " ".join(p['description'].split()), "param4 description")
59+ self.assertEqual(
60+ " ".join(p['example'].split()),
61+ "{ \"id\": 1, \"foo\": \"bar\" }")
62+
63 s = successes[0]
64 self.assertEqual(s['type'], "Content")
65 self.assertEqual(s['name'], "success_name")
66@@ -182,8 +198,8 @@ class TestAPIAnnotations(APITestCase.ForUser):
67 d = api_docstring_parser.get_dict()
68 self.assert_has_api_warning(d)
69
70- def test_parse_annotations_indent(self):
71- """Indentation should be kept when present."""
72+ def test_parse_annotations_indent_descriptions(self):
73+ """Indentation should be kept when present in descriptions."""
74 docstring = self.sample_api_annotated_docstring
75 ref_string = (
76 "Longer description with\n"
77@@ -198,6 +214,25 @@ class TestAPIAnnotations(APITestCase.ForUser):
78 # tags. E.g. @tag (type) "name" [options] description
79 self.assertEqual(d['description'], ref_string)
80
81+ def test_parse_annotations_indent_example(self):
82+ """Indentation should be kept when present in examples."""
83+ docstring = self.sample_api_annotated_docstring
84+ ref_string = (
85+ "{\n"
86+ " \"id\": 1,\n"
87+ " \"foo\": \"bar\"\n"
88+ " }\n\n "
89+ )
90+ api_docstring_parser = APIDocstringParser()
91+ api_docstring_parser.parse(docstring)
92+ d = api_docstring_parser.get_dict()
93+
94+ # Note that we only test one example here because the
95+ # same code is used to gather all description areas of the
96+ # tags. E.g. @tag-example (type) "name" [options] description
97+ params = d['params']
98+ self.assertEqual(params[3]['example'], ref_string)
99+
100 def test_whether_name_in_single_quotes_works(self):
101 """Single quotes should be allowed in annotations."""
102 ds_orig = self.sample_api_annotated_docstring

Subscribers

People subscribed via source and target branches