test_new_custom_image_page.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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, ProjectLayer, Layer
  12. from orm.models import Layer_Version, Recipe, CustomImageRecipe
  13. class TestNewCustomImagePage(SeleniumTestCase):
  14. CUSTOM_IMAGE_NAME = 'roopa-doopa'
  15. def setUp(self):
  16. release = Release.objects.create(
  17. name='baz',
  18. bitbake_version=BitbakeVersion.objects.create(name='v1')
  19. )
  20. # project to add new custom images to
  21. self.project = Project.objects.create(name='foo', release=release)
  22. # layer associated with the project
  23. layer = Layer.objects.create(name='bar')
  24. layer_version = Layer_Version.objects.create(
  25. layer=layer,
  26. project=self.project
  27. )
  28. # properly add the layer to the project
  29. ProjectLayer.objects.create(
  30. project=self.project,
  31. layercommit=layer_version,
  32. optional=False
  33. )
  34. # add a fake image recipe to the layer that can be customised
  35. self.recipe = Recipe.objects.create(
  36. name='core-image-minimal',
  37. layer_version=layer_version,
  38. is_image=True
  39. )
  40. # another project with a custom image already in it
  41. project2 = Project.objects.create(name='whoop', release=release)
  42. layer_version2 = Layer_Version.objects.create(
  43. layer=layer,
  44. project=project2
  45. )
  46. ProjectLayer.objects.create(
  47. project=project2,
  48. layercommit=layer_version2,
  49. optional=False
  50. )
  51. recipe2 = Recipe.objects.create(
  52. name='core-image-minimal',
  53. layer_version=layer_version2,
  54. is_image=True
  55. )
  56. CustomImageRecipe.objects.create(
  57. name=self.CUSTOM_IMAGE_NAME,
  58. base_recipe=recipe2,
  59. layer_version=layer_version2,
  60. file_path='/1/2',
  61. project=project2
  62. )
  63. def _create_custom_image(self, new_custom_image_name):
  64. """
  65. 1. Go to the 'new custom image' page
  66. 2. Click the button for the fake core-image-minimal
  67. 3. Wait for the dialog box for setting the name of the new custom
  68. image
  69. 4. Insert new_custom_image_name into that dialog's text box
  70. """
  71. url = reverse('newcustomimage', args=(self.project.id,))
  72. self.get(url)
  73. self.click('button[data-recipe="%s"]' % self.recipe.id)
  74. selector = '#new-custom-image-modal input[type="text"]'
  75. self.enter_text(selector, new_custom_image_name)
  76. self.click('#create-new-custom-image-btn')
  77. def _check_for_custom_image(self, image_name):
  78. """
  79. Fetch the list of custom images for the project and check the
  80. image with name image_name is listed there
  81. """
  82. url = reverse('projectcustomimages', args=(self.project.id,))
  83. self.get(url)
  84. self.wait_until_visible('#customimagestable')
  85. element = self.find('#customimagestable td[class="name"] a')
  86. msg = 'should be a custom image link with text %s' % image_name
  87. self.assertEqual(element.text.strip(), image_name, msg)
  88. def test_new_image(self):
  89. """
  90. Should be able to create a new custom image
  91. """
  92. custom_image_name = 'boo-image'
  93. self._create_custom_image(custom_image_name)
  94. self.wait_until_visible('#image-created-notification')
  95. self._check_for_custom_image(custom_image_name)
  96. def test_new_duplicates_other_project_image(self):
  97. """
  98. Should be able to create a new custom image if its name is the same
  99. as a custom image in another project
  100. """
  101. self._create_custom_image(self.CUSTOM_IMAGE_NAME)
  102. self.wait_until_visible('#image-created-notification')
  103. self._check_for_custom_image(self.CUSTOM_IMAGE_NAME)
  104. def test_new_duplicates_non_image_recipe(self):
  105. """
  106. Should not be able to create a new custom image whose name is the
  107. same as an existing non-image recipe
  108. """
  109. self._create_custom_image(self.recipe.name)
  110. element = self.wait_until_visible('#invalid-name-help')
  111. self.assertRegexpMatches(element.text.strip(),
  112. 'image with this name already exists')
  113. def test_new_duplicates_project_image(self):
  114. """
  115. Should not be able to create a new custom image whose name is the same
  116. as a custom image in this project
  117. """
  118. # create the image
  119. custom_image_name = 'doh-image'
  120. self._create_custom_image(custom_image_name)
  121. self.wait_until_visible('#image-created-notification')
  122. self._check_for_custom_image(custom_image_name)
  123. # try to create an image with the same name
  124. self._create_custom_image(custom_image_name)
  125. element = self.wait_until_visible('#invalid-name-help')
  126. expected = 'An image with this name already exists in this project'
  127. self.assertRegexpMatches(element.text.strip(), expected)