← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad/snap-upload-content-type into lp:launchpad

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/snap-upload-content-type into lp:launchpad.

Commit message:
Use Content-Type: application/json when POSTing to snap-upload endpoint.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1572605 in Launchpad itself: "Automatically upload snap builds to store"
  https://bugs.launchpad.net/launchpad/+bug/1572605

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/snap-upload-content-type/+merge/295983

Use Content-Type: application/json when POSTing to snap-upload endpoint.  SCA now requires this.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/snap-upload-content-type into lp:launchpad.
=== modified file 'lib/lp/snappy/model/snapstoreclient.py'
--- lib/lp/snappy/model/snapstoreclient.py	2016-05-24 09:36:45 +0000
+++ lib/lp/snappy/model/snapstoreclient.py	2016-05-27 20:29:51 +0000
@@ -157,7 +157,7 @@
         try:
             assert snap.store_secrets is not None
             urlfetch(
-                upload_url, method="POST", data=data,
+                upload_url, method="POST", json=data,
                 auth=MacaroonAuth(
                     snap.store_secrets["root"],
                     snap.store_secrets["discharge"]))

=== modified file 'lib/lp/snappy/tests/test_snapstoreclient.py'
--- lib/lp/snappy/tests/test_snapstoreclient.py	2016-05-24 09:36:45 +0000
+++ lib/lp/snappy/tests/test_snapstoreclient.py	2016-05-27 20:29:51 +0000
@@ -26,6 +26,7 @@
 from requests.utils import parse_dict_header
 from testtools.matchers import (
     Contains,
+    ContainsDict,
     Equals,
     KeysEqual,
     Matcher,
@@ -168,6 +169,7 @@
         self.assertThat(self.request, RequestMatches(
             url=Equals("http://sca.example/dev/api/acl/";),
             method=Equals("POST"),
+            headers=ContainsDict({"Content-Type": Equals("application/json")}),
             json_data={
                 "packages": [{"name": "test-snap", "series": "rolling"}],
                 "permissions": ["package_upload"],
@@ -255,11 +257,8 @@
         self.assertThat(self.snap_upload_request, RequestMatches(
             url=Equals("http://sca.example/dev/api/snap-upload/";),
             method=Equals("POST"),
+            headers=ContainsDict({"Content-Type": Equals("application/json")}),
             auth=("Macaroon", MacaroonsVerify(root_key)),
-            form_data={
-                "name": MatchesStructure.byEquality(
-                    name="name", value="test-snap"),
-                "updown_id": MatchesStructure.byEquality(
-                    name="updown_id", value="1"),
-                "series": MatchesStructure.byEquality(
-                    name="series", value="rolling")}))
+            json_data={
+                "name": "test-snap", "updown_id": 1, "series": "rolling",
+                }))


Follow ups