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
diff --git a/src/maasserver/api/annotations.py b/src/maasserver/api/annotations.py
index 7233150..8d02791 100644
--- a/src/maasserver/api/annotations.py
+++ b/src/maasserver/api/annotations.py
@@ -31,6 +31,7 @@ embedded annoations of the form:
3131
32 string: a unicode string32 string: a unicode string
33 int: an integer33 int: an integer
34 json: a json object
34 url-string: a URL-encoded string35 url-string: a URL-encoded string
35 http-status-code: an HTTP status code36 http-status-code: an HTTP status code
36 content: content served via a MAAS server37 content: content served via a MAAS server
@@ -153,7 +154,8 @@ class APIDocstringParser:
153 "url-string",154 "url-string",
154 "int",155 "int",
155 "content",156 "content",
156 "http-status-code"157 "http-status-code",
158 "json"
157 ]159 ]
158160
159 @staticmethod161 @staticmethod
@@ -181,6 +183,8 @@ class APIDocstringParser:
181 return "URL String"183 return "URL String"
182 elif ttype == "http-status-code":184 elif ttype == "http-status-code":
183 return "HTTP Status Code"185 return "HTTP Status Code"
186 elif ttype == "json":
187 return "JSON"
184188
185 return ttype.title().replace("-", " ")189 return ttype.title().replace("-", " ")
186190
diff --git a/src/maasserver/api/tests/test_annotations.py b/src/maasserver/api/tests/test_annotations.py
index 312cfcd..5a5eea7 100644
--- a/src/maasserver/api/tests/test_annotations.py
+++ b/src/maasserver/api/tests/test_annotations.py
@@ -34,6 +34,13 @@ class TestAPIAnnotations(APITestCase.ForUser):
34 @param (url-string) "param_name3" [required=false] param3 description34 @param (url-string) "param_name3" [required=false] param3 description
35 @param-example "param_name3" param3-ex35 @param-example "param_name3" param3-ex
3636
37 @param (json) "param_name4" [required=false] param4 description
38 @param-example "param_name4"
39 {
40 "id": 1,
41 "foo": "bar"
42 }
43
37 @success (content) "success_name" success description44 @success (content) "success_name" success description
38 @success-example "success_name" success content45 @success-example "success_name" success content
3946
@@ -121,6 +128,15 @@ class TestAPIAnnotations(APITestCase.ForUser):
121 " ".join(p['description'].split()), "param3 description")128 " ".join(p['description'].split()), "param3 description")
122 self.assertEqual(" ".join(p['example'].split()), "param3-ex")129 self.assertEqual(" ".join(p['example'].split()), "param3-ex")
123130
131 p = params[3]
132 self.assertEqual(p['type'], "JSON")
133 self.assertEqual(p['name'], "param_name4")
134 self.assertEqual(
135 " ".join(p['description'].split()), "param4 description")
136 self.assertEqual(
137 " ".join(p['example'].split()),
138 "{ \"id\": 1, \"foo\": \"bar\" }")
139
124 s = successes[0]140 s = successes[0]
125 self.assertEqual(s['type'], "Content")141 self.assertEqual(s['type'], "Content")
126 self.assertEqual(s['name'], "success_name")142 self.assertEqual(s['name'], "success_name")
@@ -182,8 +198,8 @@ class TestAPIAnnotations(APITestCase.ForUser):
182 d = api_docstring_parser.get_dict()198 d = api_docstring_parser.get_dict()
183 self.assert_has_api_warning(d)199 self.assert_has_api_warning(d)
184200
185 def test_parse_annotations_indent(self):201 def test_parse_annotations_indent_descriptions(self):
186 """Indentation should be kept when present."""202 """Indentation should be kept when present in descriptions."""
187 docstring = self.sample_api_annotated_docstring203 docstring = self.sample_api_annotated_docstring
188 ref_string = (204 ref_string = (
189 "Longer description with\n"205 "Longer description with\n"
@@ -198,6 +214,25 @@ class TestAPIAnnotations(APITestCase.ForUser):
198 # tags. E.g. @tag (type) "name" [options] description214 # tags. E.g. @tag (type) "name" [options] description
199 self.assertEqual(d['description'], ref_string)215 self.assertEqual(d['description'], ref_string)
200216
217 def test_parse_annotations_indent_example(self):
218 """Indentation should be kept when present in examples."""
219 docstring = self.sample_api_annotated_docstring
220 ref_string = (
221 "{\n"
222 " \"id\": 1,\n"
223 " \"foo\": \"bar\"\n"
224 " }\n\n "
225 )
226 api_docstring_parser = APIDocstringParser()
227 api_docstring_parser.parse(docstring)
228 d = api_docstring_parser.get_dict()
229
230 # Note that we only test one example here because the
231 # same code is used to gather all description areas of the
232 # tags. E.g. @tag-example (type) "name" [options] description
233 params = d['params']
234 self.assertEqual(params[3]['example'], ref_string)
235
201 def test_whether_name_in_single_quotes_works(self):236 def test_whether_name_in_single_quotes_works(self):
202 """Single quotes should be allowed in annotations."""237 """Single quotes should be allowed in annotations."""
203 ds_orig = self.sample_api_annotated_docstring238 ds_orig = self.sample_api_annotated_docstring

Subscribers

People subscribed via source and target branches