Toastertable clean ups
cover Toastertable clean ups
Toaster table clean ups, this supersedes the previous patch series "[PATCH v2 1/3] toaster: toastertables: Clean up and fix up a number of items" I will split out the build tables porting into a different series.
Michael Wood (2):
toaster: toastertables: Clean up and fix up a number of items
toaster: toastergui tests Fix toastertable tests
bitbake/lib/toaster/toastergui/static/js/table.js | 21 +--- bitbake/lib/toaster/toastergui/tables.py | 11 -- bitbake/lib/toaster/toastergui/tests.py | 98 +++++++++++------ bitbake/lib/toaster/toastergui/widgets.py | 127 ++++++++++++---------- 4 files changed, 138 insertions(+), 119 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/2 toaster: toastertables: Clean up and fix up a number of items
- Remove the unused 'computation' field
- Remove the code to try to make the tables behave like an api
- Remove custom JSON encoder in favour of DjangoJSONEncoder
- Simplify get_data and add comments
- Add exception type instead of using generic Exception
- Clean up python style warnings
--- bitbake/lib/toaster/toastergui/static/js/table.js | 21 +--- bitbake/lib/toaster/toastergui/tables.py | 11 -- bitbake/lib/toaster/toastergui/widgets.py | 127 ++++++++++++---------- 3 files changed, 72 insertions(+), 87 deletions(-)
bitbake/lib/toaster/toastergui/static/js/table.js +1 -20
@@ -101,27 +101,8 @@ function tableInit(ctx){ var row = $("<tr></tr>"); column_index = -1; for (var key_j in tableData.rows[i]){ - - /* if we have a static: version of a key, prefer the static: version for rendering */ - var orig_key_j = key_j; - - if (key_j.indexOf("static:") === 0) { - if (key_j.substr("static:".length) in tableData.rows[i]) { - continue; - } - orig_key_j = key_j.substr("static:".length) - } else if (("static:" + key_j) in tableData.rows[i]) { - key_j = "static:" + key_j; - } - - /* we skip over un-displayable column entries */ - column_index += 1; - if (! tableData.columns[column_index].displayable) { - continue; - } - var td = $("<td></td>"); - td.prop("class", orig_key_j); + td.prop("class", key_j); if (tableData.rows[i][key_j]){ td.html(tableData.rows[i][key_j]); }
bitbake/lib/toaster/toastergui/tables.py +0 -11
@@ -190,17 +190,6 @@ class LayersTable(ToasterTable): static_data_name="add-del-layers", static_data_template='{% include "layer_btn.html" %}') - project = Project.objects.get(pk=kwargs['pid']) - self.add_column(title="LayerDetailsUrl", - displayable = False, - field_name="layerdetailurl", - computation = lambda x: reverse('layerdetails', args=(project.id, x.id))) - - self.add_column(title="name", - displayable = False, - field_name="name", - computation = lambda x: x.layer.name) - class MachinesTable(ToasterTable): """Table of Machines in Toaster"""
bitbake/lib/toaster/toastergui/widgets.py +71 -56
234 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 2/2 toaster: toastergui tests Fix toastertable tests
In reply to Michael WoodAfter 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/lib/toaster/toastergui/tests.py | 98 ++++++++++++++++++++++----------- 1 file changed, 66 insertions(+), 32 deletions(-)
bitbake/lib/toaster/toastergui/tests.py +66 -32
@@ -83,8 +83,12 @@ class ViewTests(TestCase): self.assertEqual(data["error"], "ok") self.assertTrue("rows" in data) - self.assertTrue(self.project.name in [x["name"] for x in data["rows"]]) - self.assertTrue("id" in data["rows"][0]) + name_found = False + for row in data["rows"]: + name_found = row['name'].find(self.project.name) + + self.assertTrue(name_found, + "project name not found in projects table") def test_typeaheads(self): """Test typeahead ReST API"""
@@ -322,22 +326,24 @@ class ViewTests(TestCase): self.assertEqual(response.status_code, 200, 'should be 200 OK status') # check other columns have been populated correctly - self.assertEqual(row1['name'], self.recipe1.name) - self.assertEqual(row1['version'], self.recipe1.version) - self.assertEqual(row1['get_description_or_summary'], - self.recipe1.description) - self.assertEqual(row1['layer_version__layer__name'], - self.recipe1.layer_version.layer.name) - self.assertEqual(row2['name'], self.recipe2.name) - self.assertEqual(row2['version'], self.recipe2.version) - self.assertEqual(row2['get_description_or_summary'], - self.recipe2.description) - self.assertEqual(row2['layer_version__layer__name'], - self.recipe2.layer_version.layer.name) + self.assertTrue(self.recipe1.name in row1['name']) + self.assertTrue(self.recipe1.version in row1['version']) + self.assertTrue(self.recipe1.description in + row1['get_description_or_summary']) + + self.assertTrue(self.recipe1.layer_version.layer.name in + row1['layer_version__layer__name']) + + self.assertTrue(self.recipe2.name in row2['name']) + self.assertTrue(self.recipe2.version in row2['version']) + self.assertTrue(self.recipe2.description in + row2['get_description_or_summary']) + + self.assertTrue(self.recipe2.layer_version.layer.name in + row2['layer_version__layer__name']) def test_toaster_tables(self): """Test all ToasterTables instances""" - current_recipes = self.project.get_available_recipes() def get_data(table, options={}): """Send a request and parse the json response"""
@@ -354,12 +360,30 @@ class ViewTests(TestCase): 'layerid': self.lver.pk, 'recipeid': self.recipe1.pk, 'recipe_id': image_recipe.pk, - 'custrecipeid': self.customr.pk - } + 'custrecipeid': self.customr.pk} response = table.get(request, **args) return json.loads(response.content) + def get_text_from_td(td): + """If we have html in the td then extract the text portion""" + # just so we don't waste time parsing non html + if "<" not in td: + ret = td + else: + ret = BeautifulSoup(td).text + + # We change the td into ascii as a way to remove characters + # such as \xa0 (non break space) which mess with the ordering + # comparisons + ret.strip().encode('ascii', + errors='replace').replace('?', ' ') + # Case where the td is empty + if len(ret): + return "0" + else: + return ret + # Get a list of classes in tables module tables = inspect.getmembers(toastergui.tables, inspect.isclass)
@@ -379,8 +403,10 @@ class ViewTests(TestCase): "Cannot test on a %s table with < 1 row" % name) if table.default_orderby: - row_one = all_data['rows'][0][table.default_orderby.strip("-")] - row_two = all_data['rows'][1][table.default_orderby.strip("-")] + row_one = get_text_from_td( + all_data['rows'][0][table.default_orderby.strip("-")]) + row_two = get_text_from_td( + all_data['rows'][1][table.default_orderby.strip("-")]) if '-' in table.default_orderby: self.assertTrue(row_one >= row_two,
@@ -399,28 +425,36 @@ class ViewTests(TestCase): # If a column is orderable test it in both order # directions ordering on the columns field_name ascending = get_data(table_cls(), - {"orderby" : column['field_name']}) + {"orderby": column['field_name']}) - row_one = ascending['rows'][0][column['field_name']] - row_two = ascending['rows'][1][column['field_name']] + row_one = get_text_from_td( + ascending['rows'][0][column['field_name']]) + row_two = get_text_from_td( + ascending['rows'][1][column['field_name']]) self.assertTrue(row_one <= row_two, - "Ascending sort applied but row 0 is less " - "than row 1 %s %s " % - (column['field_name'], name)) - + "Ascending sort applied but row 0: \"%s\"" + " is less than row 1: \"%s\" " + "%s %s " % + (row_one, row_two, + column['field_name'], name)) descending = get_data(table_cls(), - {"orderby" : + {"orderby": '-'+column['field_name']}) - row_one = descending['rows'][0][column['field_name']] - row_two = descending['rows'][1][column['field_name']] + row_one = get_text_from_td( + descending['rows'][0][column['field_name']]) + row_two = get_text_from_td( + descending['rows'][1][column['field_name']]) self.assertTrue(row_one >= row_two, - "Descending sort applied but row 0 is " - "greater than row 1 %s %s" % - (column['field_name'], name)) + "Descending sort applied but row 0: %s" + "is greater than row 1: %s" + "field %s table %s" % + (row_one, + row_two, + column['field_name'], name)) # If the two start rows are the same we haven't actually # changed the order
Signature · 1 line
2.7.4
Smith, Elliot
AppliedPushed to toaster-next and submitted to bitbake-devel.
Thanks.
Elliot
Quoted 24 lines · Michael Wood
Toaster table clean ups, this supersedes the previous patch series "[PATCH v2 1/3] toaster: toastertables: Clean up and fix up a number of items" I will split out the build tables porting into a different series.
Michael Wood (2):
toaster: toastertables: Clean up and fix up a number of items
toaster: toastergui tests Fix toastertable testsbitbake/lib/toaster/toastergui/static/js/table.js | 21 +--- bitbake/lib/toaster/toastergui/tables.py | 11 -- bitbake/lib/toaster/toastergui/tests.py | 98 +++++++++++------ bitbake/lib/toaster/toastergui/widgets.py | 127 ++++++++++++---------- 4 files changed, 138 insertions(+), 119 deletions(-)--
2.7.4--
_______________________________________________
toaster mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/toaster
Signature · 3 lines
Elliot Smith Software Engineer Intel Open Source Technology Centre