Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id 23C0EE00C40; Fri, 13 May 2016 03:56:47 -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=-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 * [209.85.192.175 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-pf0-f175.google.com (mail-pf0-f175.google.com [209.85.192.175]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id BF226E00C40 for ; Fri, 13 May 2016 03:56:43 -0700 (PDT) Received: by mail-pf0-f175.google.com with SMTP id 77so41306049pfv.2 for ; Fri, 13 May 2016 03:56:43 -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=Dkk/y1SkFDMtGUY36aZNNLqhXaAXS0bebTU/V7GXASK4G7EIHSaDBTVhCt0/839f1I 9cDWKt1yGTrcWGRPmC2xU3XnB5rxioK6Gye7YXZz4q7ooCBG988HXXinS///172leXwr 3ONBCIAxCqx6vlJqhudtfzHMMNeJYRvPt/VXbaDPiBgBFfPRMJiI47Lg65Tw8EiYxlR5 0BsizekFdByRByQmEjw59UymdxPBBDJRl2eo0+tLxi8hQk6/SzeOdP+R6Z239yRyCkoy LTGIDQ3aFvSqnE9b3wfwEVKqelvkFjBopaKDyjn+FcAYlutvD3NX7c34iTPcCjLvIoRx NOUQ== 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=XaU9kqHx8O/HmQ5rJVZAnacWjbSs//3I1OZLfZ9sRVClnJdedeFuUVntqqn7kvB06L 0mECGAgx4Zlla/Sp6+rdO9Hs++AOVSh9KVnahzy4wAwaU0Sw/zOYbjeGm7lWFlMJvI6d zs0TdgiVi6klFJOfQGhoWuvEtEgxF8QS6Zk50Ws+tfwPBHM6+6dfFmnPZqbmMP/8RCQ5 HgMcqnhvaURZ0ey/LV3Oq9Gfpg6g9W3v7MwtES6FsdWWuUxFkdH50s6JxLW7aPZYy5bd EaOfbI5xWEKBao33IITEf5PN0/e2Xw6FYHLXBNcU4MIe96aBbMHOtgpFFwYqvg1u3X6J pOdg== X-Gm-Message-State: AOPr4FUkVuHM1tktbMrcZZ0Qp1aPshf32w91KE/ExM1l9Ayl/rbe7bOW8jG14Z3QOlsIpFRh X-Received: by 10.98.3.4 with SMTP id 4mr21976998pfd.33.1463137002896; Fri, 13 May 2016 03:56:42 -0700 (PDT) Received: from orion.ger.corp.intel.com ([192.55.54.42]) by smtp.gmail.com with ESMTPSA id p80sm26521441pfj.58.2016.05.13.03.56.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 13 May 2016 03:56:42 -0700 (PDT) From: Michael Wood To: toaster@yoctoproject.org Date: Fri, 13 May 2016 11:56:32 +0100 Message-Id: <1463136993-26934-2-git-send-email-michael.g.wood@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1463136993-26934-1-git-send-email-michael.g.wood@intel.com> References: <1463136993-26934-1-git-send-email-michael.g.wood@intel.com> Subject: [PATCH v2 2/3] 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: Fri, 13 May 2016 10:56:47 -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