diff options
author | Ed Bartosh <ed.bartosh@linux.intel.com> | 2016-06-07 16:37:24 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-06-15 08:35:05 +0100 |
commit | c28f918e5d0df775324da965f03b354a83e78920 (patch) | |
tree | 83a2a2a9ab949b0b8bf6b0a7c053448fd27c3ba5 /bitbake/lib/toaster | |
parent | 1fd160016ddc8a3260545b73fc0b89ec42eb882f (diff) | |
download | poky-c28f918e5d0df775324da965f03b354a83e78920.tar.gz |
bitbake: toaster: decode response content
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]
(Bitbake rev: 3566ecc3ae682358d1fc58bdc0bed5cbed5e9608)
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster')
-rw-r--r-- | bitbake/lib/toaster/toastergui/tests.py | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/bitbake/lib/toaster/toastergui/tests.py b/bitbake/lib/toaster/toastergui/tests.py index 9af101804f..722b383509 100644 --- a/bitbake/lib/toaster/toastergui/tests.py +++ b/bitbake/lib/toaster/toastergui/tests.py | |||
@@ -77,7 +77,7 @@ class ViewTests(TestCase): | |||
77 | self.assertEqual(response.status_code, 200) | 77 | self.assertEqual(response.status_code, 200) |
78 | self.assertTrue(response['Content-Type'].startswith('application/json')) | 78 | self.assertTrue(response['Content-Type'].startswith('application/json')) |
79 | 79 | ||
80 | data = json.loads(response.content) | 80 | data = json.loads(response.content.decode('utf-8')) |
81 | 81 | ||
82 | self.assertTrue("error" in data) | 82 | self.assertTrue("error" in data) |
83 | self.assertEqual(data["error"], "ok") | 83 | self.assertEqual(data["error"], "ok") |
@@ -106,7 +106,7 @@ class ViewTests(TestCase): | |||
106 | self.assertEqual(response.status_code, 200) | 106 | self.assertEqual(response.status_code, 200) |
107 | self.assertTrue(response['Content-Type'].startswith('application/json')) | 107 | self.assertTrue(response['Content-Type'].startswith('application/json')) |
108 | 108 | ||
109 | data = json.loads(response.content) | 109 | data = json.loads(response.content.decode('utf-8')) |
110 | 110 | ||
111 | self.assertTrue("error" in data) | 111 | self.assertTrue("error" in data) |
112 | self.assertEqual(data["error"], "ok") | 112 | self.assertEqual(data["error"], "ok") |
@@ -157,26 +157,26 @@ class ViewTests(TestCase): | |||
157 | 'project_id': self.project.id, | 157 | 'project_id': self.project.id, |
158 | 'dir_path' : "/path/in/repository"} | 158 | 'dir_path' : "/path/in/repository"} |
159 | response = self.client.post(reverse('xhr_importlayer'), args) | 159 | response = self.client.post(reverse('xhr_importlayer'), args) |
160 | data = json.loads(response.content) | 160 | data = json.loads(response.content.decode('utf-8')) |
161 | self.assertEqual(response.status_code, 200) | 161 | self.assertEqual(response.status_code, 200) |
162 | self.assertEqual(data["error"], "ok") | 162 | self.assertEqual(data["error"], "ok") |
163 | 163 | ||
164 | #Test to verify import of a layer successful | 164 | #Test to verify import of a layer successful |
165 | args['name'] = "meta-oe" | 165 | args['name'] = "meta-oe" |
166 | response = self.client.post(reverse('xhr_importlayer'), args) | 166 | response = self.client.post(reverse('xhr_importlayer'), args) |
167 | data = json.loads(response.content) | 167 | data = json.loads(response.content.decode('utf-8')) |
168 | self.assertTrue(data["error"], "ok") | 168 | self.assertTrue(data["error"], "ok") |
169 | 169 | ||
170 | #Test for html tag in the data | 170 | #Test for html tag in the data |
171 | args['<'] = "testing html tag" | 171 | args['<'] = "testing html tag" |
172 | response = self.client.post(reverse('xhr_importlayer'), args) | 172 | response = self.client.post(reverse('xhr_importlayer'), args) |
173 | data = json.loads(response.content) | 173 | data = json.loads(response.content.decode('utf-8')) |
174 | self.assertNotEqual(data["error"], "ok") | 174 | self.assertNotEqual(data["error"], "ok") |
175 | 175 | ||
176 | #Empty data passed | 176 | #Empty data passed |
177 | args = {} | 177 | args = {} |
178 | response = self.client.post(reverse('xhr_importlayer'), args) | 178 | response = self.client.post(reverse('xhr_importlayer'), args) |
179 | data = json.loads(response.content) | 179 | data = json.loads(response.content.decode('utf-8')) |
180 | self.assertNotEqual(data["error"], "ok") | 180 | self.assertNotEqual(data["error"], "ok") |
181 | 181 | ||
182 | def test_custom_ok(self): | 182 | def test_custom_ok(self): |
@@ -186,7 +186,7 @@ class ViewTests(TestCase): | |||
186 | 'base': self.recipe1.id} | 186 | 'base': self.recipe1.id} |
187 | response = self.client.post(url, params) | 187 | response = self.client.post(url, params) |
188 | self.assertEqual(response.status_code, 200) | 188 | self.assertEqual(response.status_code, 200) |
189 | data = json.loads(response.content) | 189 | data = json.loads(response.content.decode('utf-8')) |
190 | self.assertEqual(data['error'], 'ok') | 190 | self.assertEqual(data['error'], 'ok') |
191 | self.assertTrue('url' in data) | 191 | self.assertTrue('url' in data) |
192 | # get recipe from the database | 192 | # get recipe from the database |
@@ -202,7 +202,7 @@ class ViewTests(TestCase): | |||
202 | {'name': 'custom', 'project': self.project.id}]: | 202 | {'name': 'custom', 'project': self.project.id}]: |
203 | response = self.client.post(url, params) | 203 | response = self.client.post(url, params) |
204 | self.assertEqual(response.status_code, 200) | 204 | self.assertEqual(response.status_code, 200) |
205 | data = json.loads(response.content) | 205 | data = json.loads(response.content.decode('utf-8')) |
206 | self.assertNotEqual(data["error"], "ok") | 206 | self.assertNotEqual(data["error"], "ok") |
207 | 207 | ||
208 | def test_xhr_custom_wrong_project(self): | 208 | def test_xhr_custom_wrong_project(self): |
@@ -211,7 +211,7 @@ class ViewTests(TestCase): | |||
211 | params = {'name': 'custom', 'project': 0, "base": self.recipe1.id} | 211 | params = {'name': 'custom', 'project': 0, "base": self.recipe1.id} |
212 | response = self.client.post(url, params) | 212 | response = self.client.post(url, params) |
213 | self.assertEqual(response.status_code, 200) | 213 | self.assertEqual(response.status_code, 200) |
214 | data = json.loads(response.content) | 214 | data = json.loads(response.content.decode('utf-8')) |
215 | self.assertNotEqual(data["error"], "ok") | 215 | self.assertNotEqual(data["error"], "ok") |
216 | 216 | ||
217 | def test_xhr_custom_wrong_base(self): | 217 | def test_xhr_custom_wrong_base(self): |
@@ -220,7 +220,7 @@ class ViewTests(TestCase): | |||
220 | params = {'name': 'custom', 'project': self.project.id, "base": 0} | 220 | params = {'name': 'custom', 'project': self.project.id, "base": 0} |
221 | response = self.client.post(url, params) | 221 | response = self.client.post(url, params) |
222 | self.assertEqual(response.status_code, 200) | 222 | self.assertEqual(response.status_code, 200) |
223 | data = json.loads(response.content) | 223 | data = json.loads(response.content.decode('utf-8')) |
224 | self.assertNotEqual(data["error"], "ok") | 224 | self.assertNotEqual(data["error"], "ok") |
225 | 225 | ||
226 | def test_xhr_custom_details(self): | 226 | def test_xhr_custom_details(self): |
@@ -235,7 +235,7 @@ class ViewTests(TestCase): | |||
235 | 'project_id': self.project.id, | 235 | 'project_id': self.project.id, |
236 | } | 236 | } |
237 | } | 237 | } |
238 | self.assertEqual(json.loads(response.content), expected) | 238 | self.assertEqual(json.loads(response.content.decode('utf-8')), expected) |
239 | 239 | ||
240 | def test_xhr_custom_del(self): | 240 | def test_xhr_custom_del(self): |
241 | """Test deleting custom recipe""" | 241 | """Test deleting custom recipe""" |
@@ -248,12 +248,12 @@ class ViewTests(TestCase): | |||
248 | url = reverse('xhr_customrecipe_id', args=(recipe.id,)) | 248 | url = reverse('xhr_customrecipe_id', args=(recipe.id,)) |
249 | response = self.client.delete(url) | 249 | response = self.client.delete(url) |
250 | self.assertEqual(response.status_code, 200) | 250 | self.assertEqual(response.status_code, 200) |
251 | self.assertEqual(json.loads(response.content), {"error": "ok"}) | 251 | self.assertEqual(json.loads(response.content.decode('utf-8')), {"error": "ok"}) |
252 | # try to delete not-existent recipe | 252 | # try to delete not-existent recipe |
253 | url = reverse('xhr_customrecipe_id', args=(recipe.id,)) | 253 | url = reverse('xhr_customrecipe_id', args=(recipe.id,)) |
254 | response = self.client.delete(url) | 254 | response = self.client.delete(url) |
255 | self.assertEqual(response.status_code, 200) | 255 | self.assertEqual(response.status_code, 200) |
256 | self.assertNotEqual(json.loads(response.content)["error"], "ok") | 256 | self.assertNotEqual(json.loads(response.content.decode('utf-8'))["error"], "ok") |
257 | 257 | ||
258 | def test_xhr_custom_packages(self): | 258 | def test_xhr_custom_packages(self): |
259 | """Test adding and deleting package to a custom recipe""" | 259 | """Test adding and deleting package to a custom recipe""" |
@@ -263,7 +263,7 @@ class ViewTests(TestCase): | |||
263 | self.cust_package.id))) | 263 | self.cust_package.id))) |
264 | 264 | ||
265 | self.assertEqual(response.status_code, 200) | 265 | self.assertEqual(response.status_code, 200) |
266 | self.assertEqual(json.loads(response.content), | 266 | self.assertEqual(json.loads(response.content.decode('utf-8')), |
267 | {"error": "ok"}) | 267 | {"error": "ok"}) |
268 | self.assertEqual(self.customr.appends_set.first().name, | 268 | self.assertEqual(self.customr.appends_set.first().name, |
269 | self.cust_package.name) | 269 | self.cust_package.name) |
@@ -274,7 +274,7 @@ class ViewTests(TestCase): | |||
274 | 274 | ||
275 | response = self.client.delete(del_url) | 275 | response = self.client.delete(del_url) |
276 | self.assertEqual(response.status_code, 200) | 276 | self.assertEqual(response.status_code, 200) |
277 | self.assertEqual(json.loads(response.content), {"error": "ok"}) | 277 | self.assertEqual(json.loads(response.content.decode('utf-8')), {"error": "ok"}) |
278 | all_packages = self.customr.get_all_packages().values_list('pk', | 278 | all_packages = self.customr.get_all_packages().values_list('pk', |
279 | flat=True) | 279 | flat=True) |
280 | 280 | ||
@@ -286,7 +286,7 @@ class ViewTests(TestCase): | |||
286 | 286 | ||
287 | response = self.client.delete(del_url) | 287 | response = self.client.delete(del_url) |
288 | self.assertEqual(response.status_code, 200) | 288 | self.assertEqual(response.status_code, 200) |
289 | self.assertNotEqual(json.loads(response.content)["error"], "ok") | 289 | self.assertNotEqual(json.loads(response.content.decode('utf-8'))["error"], "ok") |
290 | 290 | ||
291 | def test_xhr_custom_packages_err(self): | 291 | def test_xhr_custom_packages_err(self): |
292 | """Test error conditions of xhr_customrecipe_packages""" | 292 | """Test error conditions of xhr_customrecipe_packages""" |
@@ -297,7 +297,7 @@ class ViewTests(TestCase): | |||
297 | for method in (self.client.put, self.client.delete): | 297 | for method in (self.client.put, self.client.delete): |
298 | response = method(url) | 298 | response = method(url) |
299 | self.assertEqual(response.status_code, 200) | 299 | self.assertEqual(response.status_code, 200) |
300 | self.assertNotEqual(json.loads(response.content), | 300 | self.assertNotEqual(json.loads(response.content.decode('utf-8')), |
301 | {"error": "ok"}) | 301 | {"error": "ok"}) |
302 | 302 | ||
303 | def test_download_custom_recipe(self): | 303 | def test_download_custom_recipe(self): |
@@ -316,7 +316,7 @@ class ViewTests(TestCase): | |||
316 | table = SoftwareRecipesTable() | 316 | table = SoftwareRecipesTable() |
317 | request = RequestFactory().get('/foo/', {'format': 'json'}) | 317 | request = RequestFactory().get('/foo/', {'format': 'json'}) |
318 | response = table.get(request, pid=self.project.id) | 318 | response = table.get(request, pid=self.project.id) |
319 | data = json.loads(response.content) | 319 | data = json.loads(response.content.decode('utf-8')) |
320 | 320 | ||
321 | recipes = Recipe.objects.filter(Q(is_image=False)) | 321 | recipes = Recipe.objects.filter(Q(is_image=False)) |
322 | self.assertTrue(len(recipes) > 1, | 322 | self.assertTrue(len(recipes) > 1, |
@@ -372,7 +372,7 @@ class ViewTests(TestCase): | |||
372 | 'target_id': 1} | 372 | 'target_id': 1} |
373 | 373 | ||
374 | response = table.get(request, **args) | 374 | response = table.get(request, **args) |
375 | return json.loads(response.content) | 375 | return json.loads(response.content.decode('utf-8')) |
376 | 376 | ||
377 | def get_text_from_td(td): | 377 | def get_text_from_td(td): |
378 | """If we have html in the td then extract the text portion""" | 378 | """If we have html in the td then extract the text portion""" |