test_all_builds_page.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License version 2 as
  11. # published by the Free Software Foundation.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License along
  19. # with this program; if not, write to the Free Software Foundation, Inc.,
  20. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. import re
  22. from django.core.urlresolvers import reverse
  23. from django.utils import timezone
  24. from tests.browser.selenium_helpers import SeleniumTestCase
  25. from orm.models import BitbakeVersion, Release, Project, Build, Target
  26. class TestAllBuildsPage(SeleniumTestCase):
  27. """ Tests for all builds page /builds/ """
  28. PROJECT_NAME = 'test project'
  29. CLI_BUILDS_PROJECT_NAME = 'command line builds'
  30. def setUp(self):
  31. bbv = BitbakeVersion.objects.create(name='bbv1', giturl='/tmp/',
  32. branch='master', dirpath='')
  33. release = Release.objects.create(name='release1',
  34. bitbake_version=bbv)
  35. self.project1 = Project.objects.create_project(name=self.PROJECT_NAME,
  36. release=release)
  37. self.default_project = Project.objects.create_project(
  38. name=self.CLI_BUILDS_PROJECT_NAME,
  39. release=release
  40. )
  41. self.default_project.is_default = True
  42. self.default_project.save()
  43. # parameters for builds to associate with the projects
  44. now = timezone.now()
  45. self.project1_build_success = {
  46. 'project': self.project1,
  47. 'started_on': now,
  48. 'completed_on': now,
  49. 'outcome': Build.SUCCEEDED
  50. }
  51. self.default_project_build_success = {
  52. 'project': self.default_project,
  53. 'started_on': now,
  54. 'completed_on': now,
  55. 'outcome': Build.SUCCEEDED
  56. }
  57. def test_show_tasks_with_suffix(self):
  58. """ Task should be shown as suffix on build name """
  59. build = Build.objects.create(**self.project1_build_success)
  60. target = 'bash'
  61. task = 'clean'
  62. Target.objects.create(build=build, target=target, task=task)
  63. url = reverse('all-builds')
  64. self.get(url)
  65. self.wait_until_present('td[class="target"]')
  66. cell = self.find('td[class="target"]')
  67. content = cell.get_attribute('innerHTML')
  68. expected_text = '%s:%s' % (target, task)
  69. self.assertTrue(re.search(expected_text, content),
  70. '"target" cell should contain text %s' % expected_text)
  71. def test_rebuild_buttons(self):
  72. """
  73. Test 'Rebuild' buttons in recent builds section
  74. 'Rebuild' button should not be shown for command-line builds,
  75. but should be shown for other builds
  76. """
  77. build1 = Build.objects.create(**self.project1_build_success)
  78. default_build = Build.objects.create(**self.default_project_build_success)
  79. url = reverse('all-builds')
  80. self.get(url)
  81. # shouldn't see a rebuild button for command-line builds
  82. selector = 'div[data-latest-build-result="%s"] .rebuild-btn' % default_build.id
  83. run_again_button = self.find_all(selector)
  84. self.assertEqual(len(run_again_button), 0,
  85. 'should not see a rebuild button for cli builds')
  86. # should see a rebuild button for non-command-line builds
  87. selector = 'div[data-latest-build-result="%s"] .rebuild-btn' % build1.id
  88. run_again_button = self.find_all(selector)
  89. self.assertEqual(len(run_again_button), 1,
  90. 'should see a rebuild button for non-cli builds')
  91. def test_tooltips_on_project_name(self):
  92. """
  93. Test tooltips shown next to project name in the main table
  94. A tooltip should be present next to the command line
  95. builds project name in the all builds page, but not for
  96. other projects
  97. """
  98. Build.objects.create(**self.project1_build_success)
  99. Build.objects.create(**self.default_project_build_success)
  100. url = reverse('all-builds')
  101. self.get(url)
  102. # get the project name cells from the table
  103. cells = self.find_all('#allbuildstable td[class="project"]')
  104. selector = 'span.get-help'
  105. for cell in cells:
  106. content = cell.get_attribute('innerHTML')
  107. help_icons = cell.find_elements_by_css_selector(selector)
  108. if re.search(self.PROJECT_NAME, content):
  109. # no help icon next to non-cli project name
  110. msg = 'should not be a help icon for non-cli builds name'
  111. self.assertEqual(len(help_icons), 0, msg)
  112. elif re.search(self.CLI_BUILDS_PROJECT_NAME, content):
  113. # help icon next to cli project name
  114. msg = 'should be a help icon for cli builds name'
  115. self.assertEqual(len(help_icons), 1, msg)
  116. else:
  117. msg = 'found unexpected project name cell in all builds table'
  118. self.fail(msg)