launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #13009
[Merge] lp:~jameinel/maas/maasclient-multipart into lp:maas
John A Meinel has proposed merging lp:~jameinel/maas/maasclient-multipart into lp:maas.
Commit message:
Support MAASClient.post(..., variable=['list', 'of', 'bytes']) which allows us to send in a list of content.
The multipart code already supported passing the same variable multiple times, but you can't expose that from a **kwargs style function.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~jameinel/maas/maasclient-multipart/+merge/128176
For the Tag updates, we need to pass a list to the API. It turns out that MAASClient didn't actually support it via the .get()/.post() methods.
The fix is pretty straightforward, and the tests assert that Django properly understands the results.
The other way to do this is to have the get/post methods themselves translate a "x=[list]" argument into a series of [(x, item1), (x, item2), (x, item3)...], which is already supported by the multipart code. But this made the most sense to me.
--
https://code.launchpad.net/~jameinel/maas/maasclient-multipart/+merge/128176
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jameinel/maas/maasclient-multipart into lp:maas.
=== modified file 'src/apiclient/multipart.py'
--- src/apiclient/multipart.py 2012-09-24 11:13:39 +0000
+++ src/apiclient/multipart.py 2012-10-05 07:38:31 +0000
@@ -77,8 +77,13 @@
def build_multipart_message(data):
message = MIMEMultipart("form-data")
for name, content in data:
- payload = make_payload(name, content)
- message.attach(payload)
+ if isinstance(content, list):
+ for part in content:
+ payload = make_payload(name, part)
+ message.attach(payload)
+ else:
+ payload = make_payload(name, content)
+ message.attach(payload)
return message
=== modified file 'src/apiclient/tests/test_multipart.py'
--- src/apiclient/tests/test_multipart.py 2012-09-22 19:43:13 +0000
+++ src/apiclient/tests/test_multipart.py 2012-10-05 07:38:31 +0000
@@ -116,3 +116,14 @@
self.assertEqual(
files_expected, files_observed,
ahem_django_ahem)
+
+ def test_encode_multipart_data_list_params(self):
+ params_in = [
+ ("one", ["ABC", "XYZ"]),
+ ("one", "UVW"),
+ ]
+ body, headers = encode_multipart_data(params_in, [])
+ params_out, files_out = (
+ parse_headers_and_body_with_django(headers, body))
+ self.assertEqual({'one': ['ABC', 'XYZ', 'UVW']}, params_out)
+ self.assertSetEqual(set(), set(files_out))
Follow ups