Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id 63FEBE00AB0; Thu, 15 Oct 2015 01:01:51 -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=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 X-Spam-HAM-Report: * -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high * trust * [134.134.136.65 listed in list.dnswl.org] * -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id ED6E7E006D5 for ; Thu, 15 Oct 2015 01:01:47 -0700 (PDT) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP; 15 Oct 2015 01:01:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,684,1437462000"; d="scan'208";a="581183530" Received: from scotter-mobl1.ger.corp.intel.com (HELO lp.ger.corp.intel.com) ([10.252.22.76]) by FMSMGA003.fm.intel.com with ESMTP; 15 Oct 2015 01:01:45 -0700 From: Elliot Smith To: toaster@yoctoproject.org Date: Thu, 15 Oct 2015 09:01:24 +0100 Message-Id: <1444896084-9521-5-git-send-email-elliot.smith@intel.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1444896084-9521-1-git-send-email-elliot.smith@intel.com> References: <1444896084-9521-1-git-send-email-elliot.smith@intel.com> Subject: [review-request][PATCH 4/4] toaster: Add tests for error message display on the build dashboard 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: Thu, 15 Oct 2015 08:01:51 -0000 Add tests to ensure that log messages with CRITICAL level and with EXCEPTION level are shown in the main errors display on the build dashboard. [YOCTO #8320] Signed-off-by: Elliot Smith --- bitbake/lib/toaster/toastergui/tests.py | 91 ++++++++++++++++++++++++++++++++- 1 file changed, 89 insertions(+), 2 deletions(-) diff --git a/bitbake/lib/toaster/toastergui/tests.py b/bitbake/lib/toaster/toastergui/tests.py index 7c4bd39..29dd7fd 100644 --- a/bitbake/lib/toaster/toastergui/tests.py +++ b/bitbake/lib/toaster/toastergui/tests.py @@ -26,15 +26,15 @@ from django.test.client import RequestFactory from django.core.urlresolvers import reverse from django.utils import timezone -from orm.models import Project, Release, BitbakeVersion, Package +from orm.models import Project, Release, BitbakeVersion, Package, LogMessage from orm.models import ReleaseLayerSourcePriority, LayerSource, Layer, Build from orm.models import Layer_Version, Recipe, Machine, ProjectLayer, Target from orm.models import CustomImageRecipe, ProjectVariable from orm.models import Branch from toastergui.tables import SoftwareRecipesTable -from bs4 import BeautifulSoup import json +from bs4 import BeautifulSoup import re PROJECT_NAME = "test project" @@ -832,3 +832,90 @@ class ProjectPageTests(TestCase): response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) + +class BuildDashboardTests(TestCase): + """ Tests for the build dashboard /build/X """ + + def setUp(self): + bbv = BitbakeVersion.objects.create(name="bbv1", giturl="/tmp/", + branch="master", dirpath="") + release = Release.objects.create(name="release1", + bitbake_version=bbv) + project = Project.objects.create_project(name=PROJECT_NAME, + release=release) + + now = timezone.now() + + self.build1 = Build.objects.create(project=project, + started_on=now, + completed_on=now) + + # exception + msg1 = 'an exception was thrown' + self.exception_message = LogMessage.objects.create( + build=self.build1, + level=LogMessage.EXCEPTION, + message=msg1 + ) + + # critical + msg2 = 'a critical error occurred' + self.critical_message = LogMessage.objects.create( + build=self.build1, + level=LogMessage.CRITICAL, + message=msg2 + ) + + def _get_build_dashboard_errors(self): + """ + Get a list of HTML fragments representing the errors on the + build dashboard + """ + url = reverse('builddashboard', args=(self.build1.id,)) + response = self.client.get(url) + soup = BeautifulSoup(response.content) + return soup.select('#errors div.alert-error') + + def _check_for_log_message(self, log_message): + """ + Check whether the LogMessage instance is + represented as an HTML error in the build dashboard page + """ + errors = self._get_build_dashboard_errors() + self.assertEqual(len(errors), 2) + + expected_text = log_message.message + expected_id = str(log_message.id) + + found = False + for error in errors: + error_text = error.find('pre').text + text_matches = (error_text == expected_text) + + error_id = error['data-error'] + id_matches = (error_id == expected_id) + + if text_matches and id_matches: + found = True + break + + template_vars = (expected_text, error_text, + expected_id, error_id) + assertion_error_msg = 'exception not found as error: ' \ + 'expected text "%s" and got "%s"; ' \ + 'expected ID %s and got %s' % template_vars + self.assertTrue(found, assertion_error_msg) + + def test_exceptions_show_as_errors(self): + """ + LogMessages with level EXCEPTION should display in the errors + section of the page + """ + self._check_for_log_message(self.exception_message) + + def test_criticals_show_as_errors(self): + """ + LogMessages with level CRITICAL should display in the errors + section of the page + """ + self._check_for_log_message(self.critical_message) -- Elliot Smith Software Engineer Intel OTC --------------------------------------------------------------------- Intel Corporation (UK) Limited Registered No. 1134945 (England) Registered Office: Pipers Way, Swindon SN3 1RJ VAT No: 860 2173 47 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.