test_all_builds_page.py 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #! /usr/bin/env python
  2. # ex:ts=4:sw=4:sts=4:et
  3. # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
  4. #
  5. # BitBake Toaster Implementation
  6. #
  7. # Copyright (C) 2013-2016 Intel Corporation
  8. #
  9. # SPDX-License-Identifier: GPL-2.0-only
  10. #
  11. import re
  12. from django.core.urlresolvers import reverse
  13. from django.utils import timezone
  14. from tests.browser.selenium_helpers import SeleniumTestCase
  15. from orm.models import BitbakeVersion, Release, Project, Build, Target
  16. class TestAllBuildsPage(SeleniumTestCase):
  17. """ Tests for all builds page /builds/ """
  18. PROJECT_NAME = 'test project'
  19. CLI_BUILDS_PROJECT_NAME = 'command line builds'
  20. def setUp(self):
  21. bbv = BitbakeVersion.objects.create(name='bbv1', giturl='/tmp/',
  22. branch='master', dirpath='')
  23. release = Release.objects.create(name='release1',
  24. bitbake_version=bbv)
  25. self.project1 = Project.objects.create_project(name=self.PROJECT_NAME,
  26. release=release)
  27. self.default_project = Project.objects.create_project(
  28. name=self.CLI_BUILDS_PROJECT_NAME,
  29. release=release
  30. )
  31. self.default_project.is_default = True
  32. self.default_project.save()
  33. # parameters for builds to associate with the projects
  34. now = timezone.now()
  35. self.project1_build_success = {
  36. 'project': self.project1,
  37. 'started_on': now,
  38. 'completed_on': now,
  39. 'outcome': Build.SUCCEEDED
  40. }
  41. self.project1_build_failure = {
  42. 'project': self.project1,
  43. 'started_on': now,
  44. 'completed_on': now,
  45. 'outcome': Build.FAILED
  46. }
  47. self.default_project_build_success = {
  48. 'project': self.default_project,
  49. 'started_on': now,
  50. 'completed_on': now,
  51. 'outcome': Build.SUCCEEDED
  52. }
  53. def _get_build_time_element(self, build):
  54. """
  55. Return the HTML element containing the build time for a build
  56. in the recent builds area
  57. """
  58. selector = 'div[data-latest-build-result="%s"] ' \
  59. '[data-role="data-recent-build-buildtime-field"]' % build.id
  60. # because this loads via Ajax, wait for it to be visible
  61. self.wait_until_present(selector)
  62. build_time_spans = self.find_all(selector)
  63. self.assertEqual(len(build_time_spans), 1)
  64. return build_time_spans[0]
  65. def _get_row_for_build(self, build):
  66. """ Get the table row for the build from the all builds table """
  67. self.wait_until_present('#allbuildstable')
  68. rows = self.find_all('#allbuildstable tr')
  69. # look for the row with a download link on the recipe which matches the
  70. # build ID
  71. url = reverse('builddashboard', args=(build.id,))
  72. selector = 'td.target a[href="%s"]' % url
  73. found_row = None
  74. for row in rows:
  75. outcome_links = row.find_elements_by_css_selector(selector)
  76. if len(outcome_links) == 1:
  77. found_row = row
  78. break
  79. self.assertNotEqual(found_row, None)
  80. return found_row
  81. def test_show_tasks_with_suffix(self):
  82. """ Task should be shown as suffix on build name """
  83. build = Build.objects.create(**self.project1_build_success)
  84. target = 'bash'
  85. task = 'clean'
  86. Target.objects.create(build=build, target=target, task=task)
  87. url = reverse('all-builds')
  88. self.get(url)
  89. self.wait_until_present('td[class="target"]')
  90. cell = self.find('td[class="target"]')
  91. content = cell.get_attribute('innerHTML')
  92. expected_text = '%s:%s' % (target, task)
  93. self.assertTrue(re.search(expected_text, content),
  94. '"target" cell should contain text %s' % expected_text)
  95. def test_rebuild_buttons(self):
  96. """
  97. Test 'Rebuild' buttons in recent builds section
  98. 'Rebuild' button should not be shown for command-line builds,
  99. but should be shown for other builds
  100. """
  101. build1 = Build.objects.create(**self.project1_build_success)
  102. default_build = Build.objects.create(**self.default_project_build_success)
  103. url = reverse('all-builds')
  104. self.get(url)
  105. # shouldn't see a rebuild button for command-line builds
  106. selector = 'div[data-latest-build-result="%s"] .rebuild-btn' % default_build.id
  107. run_again_button = self.find_all(selector)
  108. self.assertEqual(len(run_again_button), 0,
  109. 'should not see a rebuild button for cli builds')
  110. # should see a rebuild button for non-command-line builds
  111. selector = 'div[data-latest-build-result="%s"] .rebuild-btn' % build1.id
  112. run_again_button = self.find_all(selector)
  113. self.assertEqual(len(run_again_button), 1,
  114. 'should see a rebuild button for non-cli builds')
  115. def test_tooltips_on_project_name(self):
  116. """
  117. Test tooltips shown next to project name in the main table
  118. A tooltip should be present next to the command line
  119. builds project name in the all builds page, but not for
  120. other projects
  121. """
  122. Build.objects.create(**self.project1_build_success)
  123. Build.objects.create(**self.default_project_build_success)
  124. url = reverse('all-builds')
  125. self.get(url)
  126. # get the project name cells from the table
  127. cells = self.find_all('#allbuildstable td[class="project"]')
  128. selector = 'span.get-help'
  129. for cell in cells:
  130. content = cell.get_attribute('innerHTML')
  131. help_icons = cell.find_elements_by_css_selector(selector)
  132. if re.search(self.PROJECT_NAME, content):
  133. # no help icon next to non-cli project name
  134. msg = 'should not be a help icon for non-cli builds name'
  135. self.assertEqual(len(help_icons), 0, msg)
  136. elif re.search(self.CLI_BUILDS_PROJECT_NAME, content):
  137. # help icon next to cli project name
  138. msg = 'should be a help icon for cli builds name'
  139. self.assertEqual(len(help_icons), 1, msg)
  140. else:
  141. msg = 'found unexpected project name cell in all builds table'
  142. self.fail(msg)
  143. def test_builds_time_links(self):
  144. """
  145. Successful builds should have links on the time column and in the
  146. recent builds area; failed builds should not have links on the time column,
  147. or in the recent builds area
  148. """
  149. build1 = Build.objects.create(**self.project1_build_success)
  150. build2 = Build.objects.create(**self.project1_build_failure)
  151. # add some targets to these builds so they have recipe links
  152. # (and so we can find the row in the ToasterTable corresponding to
  153. # a particular build)
  154. Target.objects.create(build=build1, target='foo')
  155. Target.objects.create(build=build2, target='bar')
  156. url = reverse('all-builds')
  157. self.get(url)
  158. # test recent builds area for successful build
  159. element = self._get_build_time_element(build1)
  160. links = element.find_elements_by_css_selector('a')
  161. msg = 'should be a link on the build time for a successful recent build'
  162. self.assertEquals(len(links), 1, msg)
  163. # test recent builds area for failed build
  164. element = self._get_build_time_element(build2)
  165. links = element.find_elements_by_css_selector('a')
  166. msg = 'should not be a link on the build time for a failed recent build'
  167. self.assertEquals(len(links), 0, msg)
  168. # test the time column for successful build
  169. build1_row = self._get_row_for_build(build1)
  170. links = build1_row.find_elements_by_css_selector('td.time a')
  171. msg = 'should be a link on the build time for a successful build'
  172. self.assertEquals(len(links), 1, msg)
  173. # test the time column for failed build
  174. build2_row = self._get_row_for_build(build2)
  175. links = build2_row.find_elements_by_css_selector('td.time a')
  176. msg = 'should not be a link on the build time for a failed build'
  177. self.assertEquals(len(links), 0, msg)