test_project_config_page.py 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #! /usr/bin/env python3
  2. #
  3. # BitBake Toaster Implementation
  4. #
  5. # Copyright (C) 2013-2016 Intel Corporation
  6. #
  7. # SPDX-License-Identifier: GPL-2.0-only
  8. #
  9. from django.urls import reverse
  10. from tests.browser.selenium_helpers import SeleniumTestCase
  11. from orm.models import BitbakeVersion, Release, Project, ProjectVariable
  12. class TestProjectConfigsPage(SeleniumTestCase):
  13. """ Test data at /project/X/builds is displayed correctly """
  14. PROJECT_NAME = 'test project'
  15. INVALID_PATH_START_TEXT = 'The directory path should either start with a /'
  16. INVALID_PATH_CHAR_TEXT = 'The directory path cannot include spaces or ' \
  17. 'any of these characters'
  18. def setUp(self):
  19. bbv = BitbakeVersion.objects.create(name='bbv1', giturl='/tmp/',
  20. branch='master', dirpath='')
  21. release = Release.objects.create(name='release1',
  22. bitbake_version=bbv)
  23. self.project1 = Project.objects.create_project(name=self.PROJECT_NAME,
  24. release=release)
  25. self.project1.save()
  26. def test_no_underscore_iamgefs_type(self):
  27. """
  28. Should not accept IMAGEFS_TYPE with an underscore
  29. """
  30. imagefs_type = "foo_bar"
  31. ProjectVariable.objects.get_or_create(project = self.project1, name = "IMAGE_FSTYPES", value = "abcd ")
  32. url = reverse('projectconf', args=(self.project1.id,));
  33. self.get(url);
  34. self.click('#change-image_fstypes-icon')
  35. self.enter_text('#new-imagefs_types', imagefs_type)
  36. element = self.wait_until_visible('#hintError-image-fs_type')
  37. self.assertTrue(("A valid image type cannot include underscores" in element.text),
  38. "Did not find underscore error message")
  39. def test_checkbox_verification(self):
  40. """
  41. Should automatically check the checkbox if user enters value
  42. text box, if value is there in the checkbox.
  43. """
  44. imagefs_type = "btrfs"
  45. ProjectVariable.objects.get_or_create(project = self.project1, name = "IMAGE_FSTYPES", value = "abcd ")
  46. url = reverse('projectconf', args=(self.project1.id,));
  47. self.get(url);
  48. self.click('#change-image_fstypes-icon')
  49. self.enter_text('#new-imagefs_types', imagefs_type)
  50. checkboxes = self.driver.find_elements_by_xpath("//input[@class='fs-checkbox-fstypes']")
  51. for checkbox in checkboxes:
  52. if checkbox.get_attribute("value") == "btrfs":
  53. self.assertEqual(checkbox.is_selected(), True)
  54. def test_textbox_with_checkbox_verification(self):
  55. """
  56. Should automatically add or remove value in textbox, if user checks
  57. or unchecks checkboxes.
  58. """
  59. ProjectVariable.objects.get_or_create(project = self.project1, name = "IMAGE_FSTYPES", value = "abcd ")
  60. url = reverse('projectconf', args=(self.project1.id,));
  61. self.get(url);
  62. self.click('#change-image_fstypes-icon')
  63. self.wait_until_visible('#new-imagefs_types')
  64. checkboxes_selector = '.fs-checkbox-fstypes'
  65. self.wait_until_visible(checkboxes_selector)
  66. checkboxes = self.find_all(checkboxes_selector)
  67. for checkbox in checkboxes:
  68. if checkbox.get_attribute("value") == "cpio":
  69. checkbox.click()
  70. element = self.driver.find_element_by_id('new-imagefs_types')
  71. self.wait_until_visible('#new-imagefs_types')
  72. self.assertTrue(("cpio" in element.get_attribute('value'),
  73. "Imagefs not added into the textbox"))
  74. checkbox.click()
  75. self.assertTrue(("cpio" not in element.text),
  76. "Image still present in the textbox")
  77. def test_set_download_dir(self):
  78. """
  79. Validate the allowed and disallowed types in the directory field for
  80. DL_DIR
  81. """
  82. ProjectVariable.objects.get_or_create(project=self.project1,
  83. name='DL_DIR')
  84. url = reverse('projectconf', args=(self.project1.id,))
  85. self.get(url)
  86. # activate the input to edit download dir
  87. self.click('#change-dl_dir-icon')
  88. self.wait_until_visible('#new-dl_dir')
  89. # downloads dir path doesn't start with / or ${...}
  90. self.enter_text('#new-dl_dir', 'home/foo')
  91. element = self.wait_until_visible('#hintError-initialChar-dl_dir')
  92. msg = 'downloads directory path starts with invalid character but ' \
  93. 'treated as valid'
  94. self.assertTrue((self.INVALID_PATH_START_TEXT in element.text), msg)
  95. # downloads dir path has a space
  96. self.driver.find_element_by_id('new-dl_dir').clear()
  97. self.enter_text('#new-dl_dir', '/foo/bar a')
  98. element = self.wait_until_visible('#hintError-dl_dir')
  99. msg = 'downloads directory path characters invalid but treated as valid'
  100. self.assertTrue((self.INVALID_PATH_CHAR_TEXT in element.text), msg)
  101. # downloads dir path starts with ${...} but has a space
  102. self.driver.find_element_by_id('new-dl_dir').clear()
  103. self.enter_text('#new-dl_dir', '${TOPDIR}/down foo')
  104. element = self.wait_until_visible('#hintError-dl_dir')
  105. msg = 'downloads directory path characters invalid but treated as valid'
  106. self.assertTrue((self.INVALID_PATH_CHAR_TEXT in element.text), msg)
  107. # downloads dir path starts with /
  108. self.driver.find_element_by_id('new-dl_dir').clear()
  109. self.enter_text('#new-dl_dir', '/bar/foo')
  110. hidden_element = self.driver.find_element_by_id('hintError-dl_dir')
  111. self.assertEqual(hidden_element.is_displayed(), False,
  112. 'downloads directory path valid but treated as invalid')
  113. # downloads dir path starts with ${...}
  114. self.driver.find_element_by_id('new-dl_dir').clear()
  115. self.enter_text('#new-dl_dir', '${TOPDIR}/down')
  116. hidden_element = self.driver.find_element_by_id('hintError-dl_dir')
  117. self.assertEqual(hidden_element.is_displayed(), False,
  118. 'downloads directory path valid but treated as invalid')
  119. def test_set_sstate_dir(self):
  120. """
  121. Validate the allowed and disallowed types in the directory field for
  122. SSTATE_DIR
  123. """
  124. ProjectVariable.objects.get_or_create(project=self.project1,
  125. name='SSTATE_DIR')
  126. url = reverse('projectconf', args=(self.project1.id,))
  127. self.get(url)
  128. self.click('#change-sstate_dir-icon')
  129. self.wait_until_visible('#new-sstate_dir')
  130. # path doesn't start with / or ${...}
  131. self.enter_text('#new-sstate_dir', 'home/foo')
  132. element = self.wait_until_visible('#hintError-initialChar-sstate_dir')
  133. msg = 'sstate directory path starts with invalid character but ' \
  134. 'treated as valid'
  135. self.assertTrue((self.INVALID_PATH_START_TEXT in element.text), msg)
  136. # path has a space
  137. self.driver.find_element_by_id('new-sstate_dir').clear()
  138. self.enter_text('#new-sstate_dir', '/foo/bar a')
  139. element = self.wait_until_visible('#hintError-sstate_dir')
  140. msg = 'sstate directory path characters invalid but treated as valid'
  141. self.assertTrue((self.INVALID_PATH_CHAR_TEXT in element.text), msg)
  142. # path starts with ${...} but has a space
  143. self.driver.find_element_by_id('new-sstate_dir').clear()
  144. self.enter_text('#new-sstate_dir', '${TOPDIR}/down foo')
  145. element = self.wait_until_visible('#hintError-sstate_dir')
  146. msg = 'sstate directory path characters invalid but treated as valid'
  147. self.assertTrue((self.INVALID_PATH_CHAR_TEXT in element.text), msg)
  148. # path starts with /
  149. self.driver.find_element_by_id('new-sstate_dir').clear()
  150. self.enter_text('#new-sstate_dir', '/bar/foo')
  151. hidden_element = self.driver.find_element_by_id('hintError-sstate_dir')
  152. self.assertEqual(hidden_element.is_displayed(), False,
  153. 'sstate directory path valid but treated as invalid')
  154. # paths starts with ${...}
  155. self.driver.find_element_by_id('new-sstate_dir').clear()
  156. self.enter_text('#new-sstate_dir', '${TOPDIR}/down')
  157. hidden_element = self.driver.find_element_by_id('hintError-sstate_dir')
  158. self.assertEqual(hidden_element.is_displayed(), False,
  159. 'sstate directory path valid but treated as invalid')