Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id 8B78DE00C4F; Tue, 7 Jun 2016 08:38:02 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on yocto-www.yoctoproject.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 X-Spam-HAM-Report: * -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high * trust * [192.55.52.115 listed in list.dnswl.org] * -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id 9DCFFE00C28 for ; Tue, 7 Jun 2016 08:37:54 -0700 (PDT) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP; 07 Jun 2016 08:37:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,433,1459839600"; d="scan'208";a="117614655" Received: from tblazejc-mobl.ger.corp.intel.com (HELO lp.ger.corp.intel.com) ([10.252.19.29]) by fmsmga004.fm.intel.com with ESMTP; 07 Jun 2016 08:37:41 -0700 From: Elliot Smith To: toaster@yoctoproject.org Date: Tue, 7 Jun 2016 16:37:24 +0100 Message-Id: <1465313849-20109-3-git-send-email-elliot.smith@intel.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1465313849-20109-1-git-send-email-elliot.smith@intel.com> References: <1465313849-20109-1-git-send-email-elliot.smith@intel.com> Subject: [PATCH][v2 3/8] toaster: decode response content X-BeenThere: toaster@yoctoproject.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Web based interface for BitBake List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Jun 2016 15:38:02 -0000 From: Ed Bartosh Decoded response content to str to pass it to json.load as it breaks in Python 3 with this error: TypeError: expected bytes, bytearray or buffer compatible object [YOCTO #9584] Signed-off-by: Ed Bartosh --- bitbake/lib/toaster/toastergui/tests.py | 38 ++++++++++++++++----------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/bitbake/lib/toaster/toastergui/tests.py b/bitbake/lib/toaster/toastergui/tests.py index 9af1018..722b383 100644 --- a/bitbake/lib/toaster/toastergui/tests.py +++ b/bitbake/lib/toaster/toastergui/tests.py @@ -77,7 +77,7 @@ class ViewTests(TestCase): self.assertEqual(response.status_code, 200) self.assertTrue(response['Content-Type'].startswith('application/json')) - data = json.loads(response.content) + data = json.loads(response.content.decode('utf-8')) self.assertTrue("error" in data) self.assertEqual(data["error"], "ok") @@ -106,7 +106,7 @@ class ViewTests(TestCase): self.assertEqual(response.status_code, 200) self.assertTrue(response['Content-Type'].startswith('application/json')) - data = json.loads(response.content) + data = json.loads(response.content.decode('utf-8')) self.assertTrue("error" in data) self.assertEqual(data["error"], "ok") @@ -157,26 +157,26 @@ class ViewTests(TestCase): 'project_id': self.project.id, 'dir_path' : "/path/in/repository"} response = self.client.post(reverse('xhr_importlayer'), args) - data = json.loads(response.content) + data = json.loads(response.content.decode('utf-8')) self.assertEqual(response.status_code, 200) self.assertEqual(data["error"], "ok") #Test to verify import of a layer successful args['name'] = "meta-oe" response = self.client.post(reverse('xhr_importlayer'), args) - data = json.loads(response.content) + data = json.loads(response.content.decode('utf-8')) self.assertTrue(data["error"], "ok") #Test for html tag in the data args['<'] = "testing html tag" response = self.client.post(reverse('xhr_importlayer'), args) - data = json.loads(response.content) + data = json.loads(response.content.decode('utf-8')) self.assertNotEqual(data["error"], "ok") #Empty data passed args = {} response = self.client.post(reverse('xhr_importlayer'), args) - data = json.loads(response.content) + data = json.loads(response.content.decode('utf-8')) self.assertNotEqual(data["error"], "ok") def test_custom_ok(self): @@ -186,7 +186,7 @@ class ViewTests(TestCase): 'base': self.recipe1.id} response = self.client.post(url, params) self.assertEqual(response.status_code, 200) - data = json.loads(response.content) + data = json.loads(response.content.decode('utf-8')) self.assertEqual(data['error'], 'ok') self.assertTrue('url' in data) # get recipe from the database @@ -202,7 +202,7 @@ class ViewTests(TestCase): {'name': 'custom', 'project': self.project.id}]: response = self.client.post(url, params) self.assertEqual(response.status_code, 200) - data = json.loads(response.content) + data = json.loads(response.content.decode('utf-8')) self.assertNotEqual(data["error"], "ok") def test_xhr_custom_wrong_project(self): @@ -211,7 +211,7 @@ class ViewTests(TestCase): params = {'name': 'custom', 'project': 0, "base": self.recipe1.id} response = self.client.post(url, params) self.assertEqual(response.status_code, 200) - data = json.loads(response.content) + data = json.loads(response.content.decode('utf-8')) self.assertNotEqual(data["error"], "ok") def test_xhr_custom_wrong_base(self): @@ -220,7 +220,7 @@ class ViewTests(TestCase): params = {'name': 'custom', 'project': self.project.id, "base": 0} response = self.client.post(url, params) self.assertEqual(response.status_code, 200) - data = json.loads(response.content) + data = json.loads(response.content.decode('utf-8')) self.assertNotEqual(data["error"], "ok") def test_xhr_custom_details(self): @@ -235,7 +235,7 @@ class ViewTests(TestCase): 'project_id': self.project.id, } } - self.assertEqual(json.loads(response.content), expected) + self.assertEqual(json.loads(response.content.decode('utf-8')), expected) def test_xhr_custom_del(self): """Test deleting custom recipe""" @@ -248,12 +248,12 @@ class ViewTests(TestCase): url = reverse('xhr_customrecipe_id', args=(recipe.id,)) response = self.client.delete(url) self.assertEqual(response.status_code, 200) - self.assertEqual(json.loads(response.content), {"error": "ok"}) + self.assertEqual(json.loads(response.content.decode('utf-8')), {"error": "ok"}) # try to delete not-existent recipe url = reverse('xhr_customrecipe_id', args=(recipe.id,)) response = self.client.delete(url) self.assertEqual(response.status_code, 200) - self.assertNotEqual(json.loads(response.content)["error"], "ok") + self.assertNotEqual(json.loads(response.content.decode('utf-8'))["error"], "ok") def test_xhr_custom_packages(self): """Test adding and deleting package to a custom recipe""" @@ -263,7 +263,7 @@ class ViewTests(TestCase): self.cust_package.id))) self.assertEqual(response.status_code, 200) - self.assertEqual(json.loads(response.content), + self.assertEqual(json.loads(response.content.decode('utf-8')), {"error": "ok"}) self.assertEqual(self.customr.appends_set.first().name, self.cust_package.name) @@ -274,7 +274,7 @@ class ViewTests(TestCase): response = self.client.delete(del_url) self.assertEqual(response.status_code, 200) - self.assertEqual(json.loads(response.content), {"error": "ok"}) + self.assertEqual(json.loads(response.content.decode('utf-8')), {"error": "ok"}) all_packages = self.customr.get_all_packages().values_list('pk', flat=True) @@ -286,7 +286,7 @@ class ViewTests(TestCase): response = self.client.delete(del_url) self.assertEqual(response.status_code, 200) - self.assertNotEqual(json.loads(response.content)["error"], "ok") + self.assertNotEqual(json.loads(response.content.decode('utf-8'))["error"], "ok") def test_xhr_custom_packages_err(self): """Test error conditions of xhr_customrecipe_packages""" @@ -297,7 +297,7 @@ class ViewTests(TestCase): for method in (self.client.put, self.client.delete): response = method(url) self.assertEqual(response.status_code, 200) - self.assertNotEqual(json.loads(response.content), + self.assertNotEqual(json.loads(response.content.decode('utf-8')), {"error": "ok"}) def test_download_custom_recipe(self): @@ -316,7 +316,7 @@ class ViewTests(TestCase): table = SoftwareRecipesTable() request = RequestFactory().get('/foo/', {'format': 'json'}) response = table.get(request, pid=self.project.id) - data = json.loads(response.content) + data = json.loads(response.content.decode('utf-8')) recipes = Recipe.objects.filter(Q(is_image=False)) self.assertTrue(len(recipes) > 1, @@ -372,7 +372,7 @@ class ViewTests(TestCase): 'target_id': 1} response = table.get(request, **args) - return json.loads(response.content) + return json.loads(response.content.decode('utf-8')) def get_text_from_td(td): """If we have html in the td then extract the text portion""" -- 1.9.3 --------------------------------------------------------------------- Intel Corporation (UK) Limited Registered No. 1134945 (England) Registered Office: Pipers Way, Swindon SN3 1RJ VAT No: 860 2173 47 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.