Looks good. I think [4] needs fixing, but it's minor, so +1.
[1]
+ :param as_json: Encode params as application/json instead of
+ application/x-www-form-urlencoded. Only use this if you know the
..
+ :param as_json: Instead of POSTing the content as multipart
+ x-www-form-urlencoded post it as application/json
I think this should be multipart/form-data for all non-GET calls.
Elsewhere in MAAS it's been useful to use testtools' compound
matchers, so that failures contain more information about their
nature. Consider something like:
Looks good. I think [4] needs fixing, but it's minor, so +1.
[1]
+ :param as_json: Encode params as application/json instead of x-www-form- urlencoded. Only use this if you know the urlencoded post it as application/json
+ application/
..
+ :param as_json: Instead of POSTing the content as multipart
+ x-www-form-
I think this should be multipart/form-data for all non-GET calls.
[2]
+ def assertEncodeJSO NData(self, expected_body, expected_headers, params): json_data( params) )
+ self.assertEqual(
+ (expected_body, expected_headers),
+ encode_
Something I used for the first time earlier today might make failures
here prettier:
expected = Equals( (expected_ body, expected_headers))
self.assertTha t(
encode_ json_data, Equals(expected)))
params, AfterPreprocessing(
Up to you though; it's a small win.
[3]
+ self.assertEqua l('application/ json', headers. get('Content- Type')) l(len(body) , headers. get('Content- Length' )) l(params, json.loads(body)) and_body_ with_mimer( headers, body) l(params, data)
+ self.assertEqua
+ self.assertEqua
+ data = parse_headers_
+ self.assertEqua
Elsewhere in MAAS it's been useful to use testtools' compound
matchers, so that failures contain more information about their
nature. Consider something like:
observed = (
headers. get('Content- Type'),
headers. get('Content- Length' ),
'applicati on/json' ,
AfterPrepr ocessing( json.loads, Equals(params)),
self.assertTha t(observed, MatchesListwise (expected) )
body,
)
expected = (
"%d" % len(body),
)
[4]
+ self.assertEqua l(len(body) , headers. get('Content- Length' ))
The header should be a string value, so check that it's being
populated correctly.