Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id 24799E008D2; Mon, 16 Nov 2015 15:40:22 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on yocto-www.yoctoproject.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-HAM-Report: * -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low * trust * [74.125.82.48 listed in list.dnswl.org] * -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] * 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily * valid * -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Received: from mail-wm0-f48.google.com (mail-wm0-f48.google.com [74.125.82.48]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id A3523E00803 for ; Mon, 16 Nov 2015 15:40:19 -0800 (PST) Received: by wmvv187 with SMTP id v187so201929260wmv.1 for ; Mon, 16 Nov 2015 15:40:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel_com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9hboHlhYsLlTXprWYMUkOvsNxpjtaFUkdIEbZq9J6Tc=; b=jHxnSrRfTKrs8+sHcSvBhLwVxQ6Hd+B0g6DXPVFczZQRSVnEZGaOdpRnRDXqfmGwgo izCx6lw9HaoI6y5HEdVzpFqIkx+mfu9UjoM5Zl1Tnfki3T0/bjkJk8hJNBSqcG6fDhoN Waf21ecCNttivpBz7cFTC41bmRLuGhF2wzxDcTFGJLwNQszxWtHVuhpKRIOLymuN7hh9 dL9CwaERzpa6XhhyK9Swt93EQC4URUgx2m3GVw94IrmfqQEuBV8Fvu4d5kTR+5t2Isn/ xM2EqYKztl6uj0nApJJXRYvA+WHDxkS9kjzOh1LfH97VTRPUt3SWMuhv442E5mDWeqtE itOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=9hboHlhYsLlTXprWYMUkOvsNxpjtaFUkdIEbZq9J6Tc=; b=Azbl/1lcMps5zPH+pxpwQYHdptOuVvRXDG4H5pOUk0+LZhaUcy9iL956TC+2AjUwYk vKBwnI5aagGQ3w07xRj9AB1B9+NhECEV0pw8j9ca1kbuMR7yT83IStgYhZAtgC0K8mv5 GAAQgGOA+qj2NF9Rpt1V1qPwHYf8uRMV3Lxhhlws1duxv6rVquSfNWKsQ3b5W2GlsXs0 DW5uoFShMZtuJxo/5lDzk5T4ZG2HGF3yIt6ectyt6WLPYnxcyFIn61kfYct6OOrh0iAw di5rehv/iZ9+c1qhuiG72FrSNtmqxgpLy/MNt4Uf2/RcnLt+MH+K044WpJTZaxwl5+LX nZ6g== X-Gm-Message-State: ALoCoQlFptJY0R9agmFvtff4RlTOBAnyrg/Lq0F06r4ITyNGnZdiB/JwYmPjQX8aPhbxYWOi1Udu X-Received: by 10.28.52.12 with SMTP id b12mr20336536wma.16.1447717219065; Mon, 16 Nov 2015 15:40:19 -0800 (PST) Received: from dorado.Home ([90.199.203.61]) by smtp.gmail.com with ESMTPSA id 5sm7152623wmx.23.2015.11.16.15.40.17 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 16 Nov 2015 15:40:18 -0800 (PST) From: Michael Wood To: toaster@yoctoproject.org Date: Mon, 16 Nov 2015 23:40:05 +0000 Message-Id: <1447717205-27780-6-git-send-email-michael.g.wood@intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1447717205-27780-1-git-send-email-michael.g.wood@intel.com> References: <1447717205-27780-1-git-send-email-michael.g.wood@intel.com> Subject: [PATCH 5/5] toaster: toastergui tests Add generic test for ToasterTables widget 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: Mon, 16 Nov 2015 23:40:22 -0000 For each of the ToasterTables defined test: - Data returned - Search - Order by - Limit - Paginate - Filter These tests test that the functions on all tables work, it does not validate the content of the data in the tables themselves, this needs to be done in table specific tests. Signed-off-by: Michael Wood --- bitbake/lib/toaster/toastergui/tests.py | 223 ++++++++++++++++++++++++++++++-- 1 file changed, 212 insertions(+), 11 deletions(-) diff --git a/bitbake/lib/toaster/toastergui/tests.py b/bitbake/lib/toaster/toastergui/tests.py index 9e6c46a..a631203 100644 --- a/bitbake/lib/toaster/toastergui/tests.py +++ b/bitbake/lib/toaster/toastergui/tests.py @@ -33,11 +33,14 @@ from orm.models import CustomImageRecipe, ProjectVariable from orm.models import Branch import toastermain +import inspect +import toastergui from toastergui.tables import SoftwareRecipesTable import json from bs4 import BeautifulSoup import re +import string PROJECT_NAME = "test project" CLI_BUILDS_PROJECT_NAME = 'Command line builds' @@ -69,32 +72,68 @@ class ViewTests(TestCase): layer = Layer.objects.create(name="base-layer", layer_source=layersrc, vcs_url="/tmp/") + layer_two = Layer.objects.create(name="z-layer", + layer_source=layersrc, + vcs_url="git://two/") + + branch = Branch.objects.create(name="master", layer_source=layersrc) - lver = Layer_Version.objects.create(layer=layer, project=self.project, - layer_source=layersrc, commit="master", - up_branch=branch) + self.lver = Layer_Version.objects.create(layer=layer, + project=self.project, + layer_source=layersrc, + commit="master", + up_branch=branch) + + lver_two = Layer_Version.objects.create(layer=layer_two, + layer_source=layersrc, + commit="master", + up_branch=branch) + + Recipe.objects.create(layer_source=layersrc, + name="z recipe", + version="5.2", + summary="z recipe", + description="G recipe", + license="Z GPL", + section="h section", + layer_version=lver_two) self.recipe1 = Recipe.objects.create(layer_source=layersrc, name="base-recipe", version="1.2", summary="one recipe", description="recipe", - layer_version=lver) + section="A section", + license="Apache", + layer_version=self.lver) - Machine.objects.create(layer_version=lver, name="wisk", + Machine.objects.create(layer_version=self.lver, name="wisk", description="wisking machine") + Machine.objects.create(layer_version=self.lver, name="zap", + description="zap machine") + Machine.objects.create(layer_version=lver_two, name="xray", + description="xray machine") + - ProjectLayer.objects.create(project=self.project, layercommit=lver) + + ProjectLayer.objects.create(project=self.project, layercommit=self.lver) self.customr = CustomImageRecipe.objects.create(\ name="custom recipe", project=self.project, base_recipe=self.recipe1) - self.package = Package.objects.create(name='pkg1', recipe=self.recipe1, + CustomImageRecipe.objects.create(name="z custom recipe", + project=self.project, + base_recipe=self.recipe1) + + self.package = Package.objects.create(name='pkg1', + size=999, + recipe=self.recipe1, build=build) + Package.objects.create(name='zpkg1', recipe=self.recipe1, build=build) # recipe with project for testing AvailableRecipe table self.recipe2 = Recipe.objects.create(layer_source=layersrc, @@ -102,10 +141,35 @@ class ViewTests(TestCase): version="1.4", summary="a fancy recipe", description="fancy recipe", - layer_version=lver, + license="MIT", + layer_version=self.lver, + section="Z section", file_path='/home/foo') - self.assertTrue(lver in self.project.compatible_layerversions()) + Recipe.objects.create(layer_source=layersrc, + is_image=True, + name="Test image one", + version="1.2", + summary="one recipe", + description="recipe", + section="A", + license="A", + file_path="/one/", + layer_version=self.lver) + + Recipe.objects.create(layer_source=layersrc, + is_image=True, + name="Z Test image two", + version="1.3", + summary="two image recipe", + description="recipe two", + section="B", + license="Z", + file_path="/two/", + layer_version=lver_two) + + + def test_get_base_call_returns_html(self): """Basic test for all-projects view""" @@ -181,7 +245,6 @@ class ViewTests(TestCase): return False - import string for url in urls: results = False @@ -344,7 +407,7 @@ class ViewTests(TestCase): row2 = next(x for x in rows if x['name'] == self.recipe2.name) self.assertEqual(response.status_code, 200, 'should be 200 OK status') - self.assertEqual(len(rows), 2, 'should be 2 recipes') + self.assertTrue(row2, 'should be 2 recipes') # check other columns have been populated correctly self.assertEqual(row1['name'], self.recipe1.name) @@ -360,6 +423,144 @@ class ViewTests(TestCase): self.assertEqual(row2['layer_version__layer__name'], self.recipe2.layer_version.layer.name) + def test_toaster_tables(self): + """Test all ToasterTables instances""" + + def get_data(table, options={}): + """Send a request and parse the json response""" + options['format'] = "json" + options['nocache'] = "true" + request = RequestFactory().get('/', options) + # Add any kwargs that are needed by any of the possible tables + response = table.get(request, + pid=self.project.id, + layerid=self.lver.pk, + recipeid=self.recipe1.pk) + return json.loads(response.content) + + # Get a list of classes in tables module + tables = inspect.getmembers(toastergui.tables, inspect.isclass) + + for name, table_cls in tables: + # Filter out the non ToasterTables from the tables module + if not issubclass(table_cls, toastergui.widgets.ToasterTable) or \ + table_cls == toastergui.widgets.ToasterTable: + continue + + # Get the table data without any options, this also does the + # initialisation of the table i.e. setup_columns, + # setup_filters and setup_queryset that we can use later + table = table_cls() + all_data = get_data(table) + + self.assertTrue(len(all_data['rows']) > 1, + "Cannot test on a table with < 1 row") + + if table.default_orderby: + row_one = all_data['rows'][0][table.default_orderby.strip("-")] + row_two = all_data['rows'][1][table.default_orderby.strip("-")] + + if '-' in table.default_orderby: + self.assertTrue(row_one >= row_two, + "Default ordering not working on %s" % name) + else: + self.assertTrue(row_one <= row_two, + "Default ordering not working on %s" % name) + + # Test the column ordering and filtering functionality + for column in table.columns: + if column['orderable']: + # 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']}) + + row_one = ascending['rows'][0][column['field_name']] + row_two = ascending['rows'][1][column['field_name']] + + self.assertTrue(row_one <= row_two, + "Ascending sort applied but row 0 is less " + "than row 1") + + descending = get_data(table_cls(), + {"orderby" : + '-'+column['field_name']}) + + row_one = descending['rows'][0][column['field_name']] + row_two = descending['rows'][1][column['field_name']] + + self.assertTrue(row_one >= row_two, + "Descending sort applied but row 0 is " + "greater than row 1") + + # If the two start rows are the same we haven't actually + # changed the order + self.assertNotEqual(ascending['rows'][0], + descending['rows'][0], + "An orderby %s has not changed the " + "order of the data in table %s" % + (column['field_name'], name)) + + if column['filter_name']: + # If a filter is available for the column get the filter + # info. This contains what filter actions are defined. + filter_info = get_data(table_cls(), + {"cmd": "filterinfo", + "name": column['filter_name']}) + self.assertTrue(len(filter_info['filter_actions']) > 0, + "Filter %s was defined but no actions " + "added to it" % column['filter_name']) + + for filter_action in filter_info['filter_actions']: + # filter string to pass as the option + # This is the name of the filter:action + # e.g. project_filter:not_in_project + filter_string = "%s:%s" % (column['filter_name'], + filter_action['name']) + # Now get the data with the filter applied + filtered_data = get_data(table_cls(), + {"filter" : filter_string}) + self.assertEqual(len(filtered_data['rows']), + int(filter_action['count']), + "We added a table filter for %s but " + "the number of rows returned was not " + "what the filter info said there " + "would be" % name) + + + # Test search functionality on the table + something_found = False + for search in list(string.ascii_letters): + search_data = get_data(table_cls(), {'search' : search}) + + if len(search_data['rows']) > 0: + something_found = True + break + + self.assertTrue(something_found, + "We went through the whole alphabet and nothing" + " was found for the search of table %s" % name) + + # Test the limit functionality on the table + limited_data = get_data(table_cls(), {'limit' : "1"}) + self.assertEqual(len(limited_data['rows']), + 1, + "Limit 1 set on table %s but not 1 row returned" + % name) + + # Test the pagination functionality on the table + page_one_data = get_data(table_cls(), {'limit' : "1", + "page": "1"})['rows'][0] + + page_two_data = get_data(table_cls(), {'limit' : "1", + "page": "2"})['rows'][0] + + self.assertNotEqual(page_one_data, + page_two_data, + "Changed page on table %s but first row is the " + "same as the previous page" % name) + + class LandingPageTests(TestCase): """ Tests for redirects on the landing page """ # disable bogus pylint message error: -- 2.5.0