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

Proposed by Colin Watson
Status: Merged
Merged at revision: 18077
Proposed branch: lp:~cjwatson/launchpad/snap-upload-content-type
Merge into: lp:launchpad
Diff against target: 48 lines (+7/-8)
2 files modified
lib/lp/snappy/model/snapstoreclient.py (+1/-1)
lib/lp/snappy/tests/test_snapstoreclient.py (+6/-7)
To merge this branch: bzr merge lp:~cjwatson/launchpad/snap-upload-content-type
Reviewer Review Type Date Requested Status
Maximiliano Bertacchini (community) Approve
Launchpad code reviewers Pending
Review via email: mp+295983@code.launchpad.net

Commit message

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

Description of the change

Use Content-Type: application/json when POSTing to snap-upload endpoint. SCA now requires this.

To post a comment you must log in.
Maximiliano Bertacchini (maxiberta) wrote :

LGTM.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/snappy/model/snapstoreclient.py'
2--- lib/lp/snappy/model/snapstoreclient.py 2016-05-24 09:36:45 +0000
3+++ lib/lp/snappy/model/snapstoreclient.py 2016-05-27 20:29:51 +0000
4@@ -157,7 +157,7 @@
5 try:
6 assert snap.store_secrets is not None
7 urlfetch(
8- upload_url, method="POST", data=data,
9+ upload_url, method="POST", json=data,
10 auth=MacaroonAuth(
11 snap.store_secrets["root"],
12 snap.store_secrets["discharge"]))
13
14=== modified file 'lib/lp/snappy/tests/test_snapstoreclient.py'
15--- lib/lp/snappy/tests/test_snapstoreclient.py 2016-05-24 09:36:45 +0000
16+++ lib/lp/snappy/tests/test_snapstoreclient.py 2016-05-27 20:29:51 +0000
17@@ -26,6 +26,7 @@
18 from requests.utils import parse_dict_header
19 from testtools.matchers import (
20 Contains,
21+ ContainsDict,
22 Equals,
23 KeysEqual,
24 Matcher,
25@@ -168,6 +169,7 @@
26 self.assertThat(self.request, RequestMatches(
27 url=Equals("http://sca.example/dev/api/acl/"),
28 method=Equals("POST"),
29+ headers=ContainsDict({"Content-Type": Equals("application/json")}),
30 json_data={
31 "packages": [{"name": "test-snap", "series": "rolling"}],
32 "permissions": ["package_upload"],
33@@ -255,11 +257,8 @@
34 self.assertThat(self.snap_upload_request, RequestMatches(
35 url=Equals("http://sca.example/dev/api/snap-upload/"),
36 method=Equals("POST"),
37+ headers=ContainsDict({"Content-Type": Equals("application/json")}),
38 auth=("Macaroon", MacaroonsVerify(root_key)),
39- form_data={
40- "name": MatchesStructure.byEquality(
41- name="name", value="test-snap"),
42- "updown_id": MatchesStructure.byEquality(
43- name="updown_id", value="1"),
44- "series": MatchesStructure.byEquality(
45- name="series", value="rolling")}))
46+ json_data={
47+ "name": "test-snap", "updown_id": 1, "series": "rolling",
48+ }))