summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorMichael Wood <michael.g.wood@intel.com>2016-05-16 14:50:41 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-05-17 14:43:30 +0100
commit3718f8d90c84a68cb7a87deb32921c1f0ecc3b1b (patch)
tree9e20e2ef008f9f6293eca638d43a6872684da906 /bitbake
parent54bf7cce48547289489203812f2e01cb755f0db4 (diff)
downloadpoky-3718f8d90c84a68cb7a87deb32921c1f0ecc3b1b.tar.gz
bitbake: toaster: toastergui tests Fix toastertable tests
After clean ups remove api assumptions. Our table data often contains html snippets to display certain things such as dependency pop overs or simply links to other parts of the UI. Take these into account when testing the values of the table data. (Bitbake rev: 7f61a68f2caba538e302ca9c2727bb43a6c77c64) Signed-off-by: Michael Wood <michael.g.wood@intel.com> Signed-off-by: Elliot Smith <elliot.smith@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/toaster/toastergui/tests.py98
1 files changed, 66 insertions, 32 deletions
diff --git a/bitbake/lib/toaster/toastergui/tests.py b/bitbake/lib/toaster/toastergui/tests.py
index a4cab58483..869c39d84c 100644
--- a/bitbake/lib/toaster/toastergui/tests.py
+++ b/bitbake/lib/toaster/toastergui/tests.py
@@ -83,8 +83,12 @@ class ViewTests(TestCase):
83 self.assertEqual(data["error"], "ok") 83 self.assertEqual(data["error"], "ok")
84 self.assertTrue("rows" in data) 84 self.assertTrue("rows" in data)
85 85
86 self.assertTrue(self.project.name in [x["name"] for x in data["rows"]]) 86 name_found = False
87 self.assertTrue("id" in data["rows"][0]) 87 for row in data["rows"]:
88 name_found = row['name'].find(self.project.name)
89
90 self.assertTrue(name_found,
91 "project name not found in projects table")
88 92
89 def test_typeaheads(self): 93 def test_typeaheads(self):
90 """Test typeahead ReST API""" 94 """Test typeahead ReST API"""
@@ -322,22 +326,24 @@ class ViewTests(TestCase):
322 self.assertEqual(response.status_code, 200, 'should be 200 OK status') 326 self.assertEqual(response.status_code, 200, 'should be 200 OK status')
323 327
324 # check other columns have been populated correctly 328 # check other columns have been populated correctly
325 self.assertEqual(row1['name'], self.recipe1.name) 329 self.assertTrue(self.recipe1.name in row1['name'])
326 self.assertEqual(row1['version'], self.recipe1.version) 330 self.assertTrue(self.recipe1.version in row1['version'])
327 self.assertEqual(row1['get_description_or_summary'], 331 self.assertTrue(self.recipe1.description in
328 self.recipe1.description) 332 row1['get_description_or_summary'])
329 self.assertEqual(row1['layer_version__layer__name'], 333
330 self.recipe1.layer_version.layer.name) 334 self.assertTrue(self.recipe1.layer_version.layer.name in
331 self.assertEqual(row2['name'], self.recipe2.name) 335 row1['layer_version__layer__name'])
332 self.assertEqual(row2['version'], self.recipe2.version) 336
333 self.assertEqual(row2['get_description_or_summary'], 337 self.assertTrue(self.recipe2.name in row2['name'])
334 self.recipe2.description) 338 self.assertTrue(self.recipe2.version in row2['version'])
335 self.assertEqual(row2['layer_version__layer__name'], 339 self.assertTrue(self.recipe2.description in
336 self.recipe2.layer_version.layer.name) 340 row2['get_description_or_summary'])
341
342 self.assertTrue(self.recipe2.layer_version.layer.name in
343 row2['layer_version__layer__name'])
337 344
338 def test_toaster_tables(self): 345 def test_toaster_tables(self):
339 """Test all ToasterTables instances""" 346 """Test all ToasterTables instances"""
340 current_recipes = self.project.get_available_recipes()
341 347
342 def get_data(table, options={}): 348 def get_data(table, options={}):
343 """Send a request and parse the json response""" 349 """Send a request and parse the json response"""
@@ -354,12 +360,30 @@ class ViewTests(TestCase):
354 'layerid': self.lver.pk, 360 'layerid': self.lver.pk,
355 'recipeid': self.recipe1.pk, 361 'recipeid': self.recipe1.pk,
356 'recipe_id': image_recipe.pk, 362 'recipe_id': image_recipe.pk,
357 'custrecipeid': self.customr.pk 363 'custrecipeid': self.customr.pk}
358 }
359 364
360 response = table.get(request, **args) 365 response = table.get(request, **args)
361 return json.loads(response.content) 366 return json.loads(response.content)
362 367
368 def get_text_from_td(td):
369 """If we have html in the td then extract the text portion"""
370 # just so we don't waste time parsing non html
371 if "<" not in td:
372 ret = td
373 else:
374 ret = BeautifulSoup(td).text
375
376 # We change the td into ascii as a way to remove characters
377 # such as \xa0 (non break space) which mess with the ordering
378 # comparisons
379 ret.strip().encode('ascii',
380 errors='replace').replace('?', ' ')
381 # Case where the td is empty
382 if len(ret):
383 return "0"
384 else:
385 return ret
386
363 # Get a list of classes in tables module 387 # Get a list of classes in tables module
364 tables = inspect.getmembers(toastergui.tables, inspect.isclass) 388 tables = inspect.getmembers(toastergui.tables, inspect.isclass)
365 389
@@ -379,8 +403,10 @@ class ViewTests(TestCase):
379 "Cannot test on a %s table with < 1 row" % name) 403 "Cannot test on a %s table with < 1 row" % name)
380 404
381 if table.default_orderby: 405 if table.default_orderby:
382 row_one = all_data['rows'][0][table.default_orderby.strip("-")] 406 row_one = get_text_from_td(
383 row_two = all_data['rows'][1][table.default_orderby.strip("-")] 407 all_data['rows'][0][table.default_orderby.strip("-")])
408 row_two = get_text_from_td(
409 all_data['rows'][1][table.default_orderby.strip("-")])
384 410
385 if '-' in table.default_orderby: 411 if '-' in table.default_orderby:
386 self.assertTrue(row_one >= row_two, 412 self.assertTrue(row_one >= row_two,
@@ -399,28 +425,36 @@ class ViewTests(TestCase):
399 # If a column is orderable test it in both order 425 # If a column is orderable test it in both order
400 # directions ordering on the columns field_name 426 # directions ordering on the columns field_name
401 ascending = get_data(table_cls(), 427 ascending = get_data(table_cls(),
402 {"orderby" : column['field_name']}) 428 {"orderby": column['field_name']})
403 429
404 row_one = ascending['rows'][0][column['field_name']] 430 row_one = get_text_from_td(
405 row_two = ascending['rows'][1][column['field_name']] 431 ascending['rows'][0][column['field_name']])
432 row_two = get_text_from_td(
433 ascending['rows'][1][column['field_name']])
406 434
407 self.assertTrue(row_one <= row_two, 435 self.assertTrue(row_one <= row_two,
408 "Ascending sort applied but row 0 is less " 436 "Ascending sort applied but row 0: \"%s\""
409 "than row 1 %s %s " % 437 " is less than row 1: \"%s\" "
410 (column['field_name'], name)) 438 "%s %s " %
411 439 (row_one, row_two,
440 column['field_name'], name))
412 441
413 descending = get_data(table_cls(), 442 descending = get_data(table_cls(),
414 {"orderby" : 443 {"orderby":
415 '-'+column['field_name']}) 444 '-'+column['field_name']})
416 445
417 row_one = descending['rows'][0][column['field_name']] 446 row_one = get_text_from_td(
418 row_two = descending['rows'][1][column['field_name']] 447 descending['rows'][0][column['field_name']])
448 row_two = get_text_from_td(
449 descending['rows'][1][column['field_name']])
419 450
420 self.assertTrue(row_one >= row_two, 451 self.assertTrue(row_one >= row_two,
421 "Descending sort applied but row 0 is " 452 "Descending sort applied but row 0: %s"
422 "greater than row 1 %s %s" % 453 "is greater than row 1: %s"
423 (column['field_name'], name)) 454 "field %s table %s" %
455 (row_one,
456 row_two,
457 column['field_name'], name))
424 458
425 # If the two start rows are the same we haven't actually 459 # If the two start rows are the same we haven't actually
426 # changed the order 460 # changed the order