Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id 09CB1E00DC6; Mon, 16 May 2016 03:45:49 -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=-1.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FSL_HELO_HOME,RCVD_IN_DNSWL_LOW autolearn=no 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.41 listed in list.dnswl.org] * 1.0 FSL_HELO_HOME FSL_HELO_HOME * -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-f41.google.com (mail-wm0-f41.google.com [74.125.82.41]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id A1221E00DC2 for ; Mon, 16 May 2016 03:45:46 -0700 (PDT) Received: by mail-wm0-f41.google.com with SMTP id n129so95951034wmn.1 for ; Mon, 16 May 2016 03:45:46 -0700 (PDT) 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=WNQgRdXPl6LllQ3vKGSEgWh5CNimZoIsGbFEsXUWC1k=; b=gVoqZHvI+HrtZlNVLCcKwZonKPKSho20jKrYV+3VlpZKENBTEJRhfY7273UdecELYB uMVsllhzFjI4cdKcw+7Cxadg57P1puFAhWLAyiD1SnfpclL7R8lmW1zb2LXm4I7vkmUB sh3bITtEkZbqSq69omTKIDKobTm4t/ytAV+8qZDdquIgOVOtaDAhrLr5qojKkFJXN5s4 UGhASlbALY7woQM6RS+inHhswwqgd3ZwDJif627YSRsmjdbXAFljSsaZFArCB3c0k/KA HDDmoKKzGiZh/7XlCCIzC9ontvQLgmafNyg1Kcq9Dne7IUGiesQ3ETryxFiuNjOzJfCR xCfg== 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=WNQgRdXPl6LllQ3vKGSEgWh5CNimZoIsGbFEsXUWC1k=; b=hHPCd6M9/QeX4u3aj6XaJjIAqwR1dppdhoP53dhOTER2uZC1WwZkBxMGUvg1oejJyj 5kJv9kxxnDotG759QUnB1D9n1P6M+Fe2HCaJcjr65jbP/vtSfHG5T7S8ThFSOZiQ/xGn zaNmSpMjNCgKMUP2DRSQ8vVkV1Iwf32XnqMFFUoKJTgiAXN4Q4XmaxxOWCq7xJutIPee oA5PUgFdSfsW07DrgC6JLKOJhOdbVDaRaRq0EQe9QQyP5CY7FgRhRXFq3AEeUCoYb2ZO KKJGCiL1iBCBYCSmo4iuLEetAbv77cRAgptq7gqN5zDhF9BAfbeNvqgA4uXA3MwsSqLh IgrQ== X-Gm-Message-State: AOPr4FV2dW/gE3zwnYkcCGNWsgT5hBCKk/pEEt7kFyvTPYrAyY8vE5BZ/4IGlyPLX36QaUt5 X-Received: by 10.28.57.85 with SMTP id g82mr17913028wma.3.1463395544744; Mon, 16 May 2016 03:45:44 -0700 (PDT) Received: from orion.home (host31-48-249-108.range31-48.btcentralplus.com. [31.48.249.108]) by smtp.gmail.com with ESMTPSA id s125sm3910490wms.14.2016.05.16.03.45.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 16 May 2016 03:45:44 -0700 (PDT) From: Michael Wood To: toaster@yoctoproject.org Date: Mon, 16 May 2016 11:45:41 +0100 Message-Id: <1463395541-4527-3-git-send-email-michael.g.wood@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1463395541-4527-1-git-send-email-michael.g.wood@intel.com> References: <1463395541-4527-1-git-send-email-michael.g.wood@intel.com> Subject: [PATCH 2/2] toaster: toastergui tests Fix toastertable tests 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 May 2016 10:45:49 -0000 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. Signed-off-by: Michael Wood --- bitbake/lib/toaster/toastergui/tests.py | 98 ++++++++++++++++++++++----------- 1 file changed, 66 insertions(+), 32 deletions(-) diff --git a/bitbake/lib/toaster/toastergui/tests.py b/bitbake/lib/toaster/toastergui/tests.py index a4cab58..869c39d 100644 --- a/bitbake/lib/toaster/toastergui/tests.py +++ b/bitbake/lib/toaster/toastergui/tests.py @@ -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 -- 2.7.4