launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #26102
[Merge] ~cjwatson/launchpad:py3-request-body-decode-json into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:py3-request-body-decode-json into launchpad:master.
Commit message:
Decode PreparedRequest.body before passing to json.loads
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/396865
Python 3.5's json.loads only accepted str, although 3.6 accepts bytes as well.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-request-body-decode-json into launchpad:master.
diff --git a/lib/lp/code/model/tests/test_githosting.py b/lib/lp/code/model/tests/test_githosting.py
index 16a2488..995b4df 100644
--- a/lib/lp/code/model/tests/test_githosting.py
+++ b/lib/lp/code/model/tests/test_githosting.py
@@ -115,7 +115,8 @@ class TestGitHostingClient(TestCase):
method=Equals(method),
**{key: Equals(value) for key, value in kwargs.items()}))
if json_data is not None:
- self.assertEqual(json_data, json.loads(request.body))
+ self.assertEqual(
+ json_data, json.loads(request.body.decode("UTF-8")))
timeline = get_request_timeline(get_current_browser_request())
action = timeline.actions[-1]
self.assertEqual("git-hosting-%s" % method.lower(), action.category)
diff --git a/lib/lp/oci/tests/test_ociregistryclient.py b/lib/lp/oci/tests/test_ociregistryclient.py
index bda327f..60729e1 100644
--- a/lib/lp/oci/tests/test_ociregistryclient.py
+++ b/lib/lp/oci/tests/test_ociregistryclient.py
@@ -205,7 +205,7 @@ class TestOCIRegistryClient(OCIConfigHelperMixin, SpyProxyCallsMixin,
self.client.upload(self.build)
- request = json.loads(responses.calls[1].request.body)
+ request = json.loads(responses.calls[1].request.body.decode("UTF-8"))
self.assertThat(request, MatchesDict({
"layers": MatchesListwise([
@@ -690,7 +690,7 @@ class TestOCIRegistryClient(OCIConfigHelperMixin, SpyProxyCallsMixin,
"digest": "build2digest",
"size": 321
}]
- }, json.loads(send_manifest_call.request.body))
+ }, json.loads(send_manifest_call.request.body.decode("UTF-8")))
@responses.activate
def test_multi_arch_manifest_upload_update_manifest(self):
@@ -782,7 +782,7 @@ class TestOCIRegistryClient(OCIConfigHelperMixin, SpyProxyCallsMixin,
"digest": "new-build2-digest",
"size": 2222
}]
- }, json.loads(send_manifest_call.request.body))
+ }, json.loads(send_manifest_call.request.body.decode("UTF-8")))
@responses.activate
def test_multi_arch_manifest_upload_invalid_current_manifest(self):
@@ -837,7 +837,7 @@ class TestOCIRegistryClient(OCIConfigHelperMixin, SpyProxyCallsMixin,
"digest": "new-build1-digest",
"size": 1111
}]
- }, json.loads(send_manifest_call.request.body))
+ }, json.loads(send_manifest_call.request.body.decode("UTF-8")))
@responses.activate
def test_multi_arch_manifest_upload_registry_error_fetching_current(self):
diff --git a/lib/lp/snappy/browser/tests/test_snap.py b/lib/lp/snappy/browser/tests/test_snap.py
index 33da319..3e48162 100644
--- a/lib/lp/snappy/browser/tests/test_snap.py
+++ b/lib/lp/snappy/browser/tests/test_snap.py
@@ -501,7 +501,8 @@ class TestSnapAddView(BaseTestSnapView):
}],
"permissions": ["package_upload"],
}
- self.assertEqual(expected_body, json.loads(call.request.body))
+ self.assertEqual(
+ expected_body, json.loads(call.request.body.decode("UTF-8")))
self.assertEqual(303, int(browser.headers["Status"].split(" ", 1)[0]))
parsed_location = urlsplit(browser.headers["Location"])
self.assertEqual(
@@ -1201,7 +1202,8 @@ class TestSnapEditView(BaseTestSnapView):
"packages": [{"name": "two", "series": self.snappyseries.name}],
"permissions": ["package_upload"],
}
- self.assertEqual(expected_body, json.loads(call.request.body))
+ self.assertEqual(
+ expected_body, json.loads(call.request.body.decode("UTF-8")))
self.assertEqual(303, int(browser.headers["Status"].split(" ", 1)[0]))
parsed_location = urlsplit(browser.headers["Location"])
self.assertEqual(
@@ -1266,7 +1268,8 @@ class TestSnapAuthorizeView(BaseTestSnapView):
}],
"permissions": ["package_upload"],
}
- self.assertEqual(expected_body, json.loads(call.request.body))
+ self.assertEqual(
+ expected_body, json.loads(call.request.body.decode("UTF-8")))
self.assertEqual(
{"root": root_macaroon_raw}, self.snap.store_secrets)
self.assertEqual(303, int(browser.headers["Status"].split(" ", 1)[0]))
diff --git a/lib/lp/snappy/tests/test_snap.py b/lib/lp/snappy/tests/test_snap.py
index e6da91f..706255a 100644
--- a/lib/lp/snappy/tests/test_snap.py
+++ b/lib/lp/snappy/tests/test_snap.py
@@ -3254,7 +3254,8 @@ class TestSnapWebservice(TestCaseWithFactory):
}],
"permissions": ["package_upload"],
}
- self.assertEqual(expected_body, json.loads(call.request.body))
+ self.assertEqual(
+ expected_body, json.loads(call.request.body.decode("UTF-8")))
self.assertEqual({"root": root_macaroon_raw}, snap.store_secrets)
return response, root_macaroon.third_party_caveats()[0]
diff --git a/lib/lp/snappy/tests/test_snapstoreclient.py b/lib/lp/snappy/tests/test_snapstoreclient.py
index 51b0039..20d286a 100644
--- a/lib/lp/snappy/tests/test_snapstoreclient.py
+++ b/lib/lp/snappy/tests/test_snapstoreclient.py
@@ -194,7 +194,8 @@ class RequestMatches(Matcher):
if mismatch is not None:
return mismatch
if self.json_data is not None:
- mismatch = Equals(self.json_data).match(json.loads(request.body))
+ mismatch = Equals(self.json_data).match(
+ json.loads(request.body.decode("UTF-8")))
if mismatch is not None:
return mismatch
if self.form_data is not None: