summaryrefslogtreecommitdiffstats
path: root/bitbake/lib
diff options
context:
space:
mode:
authorElliot Smith <elliot.smith@intel.com>2015-10-13 15:35:17 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-10-16 15:00:00 +0100
commita9053ac0829eb01f6f002587854d01e47a78e6f0 (patch)
treee415c7d2f14a5223d89c21d835d6d635052924a2 /bitbake/lib
parent2517987f8db37d50df03e690be2501447b7eeeb8 (diff)
downloadpoky-a9053ac0829eb01f6f002587854d01e47a78e6f0.tar.gz
bitbake: toaster: Add tests for error message display on the build dashboard
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] (Bitbake rev: 7b3ed62800cb7352154897c1c5ad2440a54df198) Signed-off-by: Elliot Smith <elliot.smith@intel.com> Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib')
-rw-r--r--bitbake/lib/toaster/toastergui/tests.py91
1 files changed, 89 insertions, 2 deletions
diff --git a/bitbake/lib/toaster/toastergui/tests.py b/bitbake/lib/toaster/toastergui/tests.py
index 7c4bd39db3..29dd7fda77 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
26from django.core.urlresolvers import reverse 26from django.core.urlresolvers import reverse
27from django.utils import timezone 27from django.utils import timezone
28 28
29from orm.models import Project, Release, BitbakeVersion, Package 29from orm.models import Project, Release, BitbakeVersion, Package, LogMessage
30from orm.models import ReleaseLayerSourcePriority, LayerSource, Layer, Build 30from orm.models import ReleaseLayerSourcePriority, LayerSource, Layer, Build
31from orm.models import Layer_Version, Recipe, Machine, ProjectLayer, Target 31from orm.models import Layer_Version, Recipe, Machine, ProjectLayer, Target
32from orm.models import CustomImageRecipe, ProjectVariable 32from orm.models import CustomImageRecipe, ProjectVariable
33from orm.models import Branch 33from orm.models import Branch
34 34
35from toastergui.tables import SoftwareRecipesTable 35from toastergui.tables import SoftwareRecipesTable
36from bs4 import BeautifulSoup
37import json 36import json
37from bs4 import BeautifulSoup
38import re 38import re
39 39
40PROJECT_NAME = "test project" 40PROJECT_NAME = "test project"
@@ -832,3 +832,90 @@ class ProjectPageTests(TestCase):
832 response = self.client.get(url, follow=True) 832 response = self.client.get(url, follow=True)
833 833
834 self.assertEqual(response.status_code, 200) 834 self.assertEqual(response.status_code, 200)
835
836class BuildDashboardTests(TestCase):
837 """ Tests for the build dashboard /build/X """
838
839 def setUp(self):
840 bbv = BitbakeVersion.objects.create(name="bbv1", giturl="/tmp/",
841 branch="master", dirpath="")
842 release = Release.objects.create(name="release1",
843 bitbake_version=bbv)
844 project = Project.objects.create_project(name=PROJECT_NAME,
845 release=release)
846
847 now = timezone.now()
848
849 self.build1 = Build.objects.create(project=project,
850 started_on=now,
851 completed_on=now)
852
853 # exception
854 msg1 = 'an exception was thrown'
855 self.exception_message = LogMessage.objects.create(
856 build=self.build1,
857 level=LogMessage.EXCEPTION,
858 message=msg1
859 )
860
861 # critical
862 msg2 = 'a critical error occurred'
863 self.critical_message = LogMessage.objects.create(
864 build=self.build1,
865 level=LogMessage.CRITICAL,
866 message=msg2
867 )
868
869 def _get_build_dashboard_errors(self):
870 """
871 Get a list of HTML fragments representing the errors on the
872 build dashboard
873 """
874 url = reverse('builddashboard', args=(self.build1.id,))
875 response = self.client.get(url)
876 soup = BeautifulSoup(response.content)
877 return soup.select('#errors div.alert-error')
878
879 def _check_for_log_message(self, log_message):
880 """
881 Check whether the LogMessage instance <log_message> is
882 represented as an HTML error in the build dashboard page
883 """
884 errors = self._get_build_dashboard_errors()
885 self.assertEqual(len(errors), 2)
886
887 expected_text = log_message.message
888 expected_id = str(log_message.id)
889
890 found = False
891 for error in errors:
892 error_text = error.find('pre').text
893 text_matches = (error_text == expected_text)
894
895 error_id = error['data-error']
896 id_matches = (error_id == expected_id)
897
898 if text_matches and id_matches:
899 found = True
900 break
901
902 template_vars = (expected_text, error_text,
903 expected_id, error_id)
904 assertion_error_msg = 'exception not found as error: ' \
905 'expected text "%s" and got "%s"; ' \
906 'expected ID %s and got %s' % template_vars
907 self.assertTrue(found, assertion_error_msg)
908
909 def test_exceptions_show_as_errors(self):
910 """
911 LogMessages with level EXCEPTION should display in the errors
912 section of the page
913 """
914 self._check_for_log_message(self.exception_message)
915
916 def test_criticals_show_as_errors(self):
917 """
918 LogMessages with level CRITICAL should display in the errors
919 section of the page
920 """
921 self._check_for_log_message(self.critical_message)