PageRenderTime 45ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/IntegrationTests/src/bkr/inttest/client/test_wizard.py

https://github.com/beaker-project/beaker
Python | 132 lines | 115 code | 9 blank | 8 comment | 2 complexity | 5e0c5f2a799c65bd95f59ab56d5f343e MD5 | raw file
Possible License(s): GPL-2.0, CC-BY-SA-3.0
  1. # This program is free software; you can redistribute it and/or modify
  2. # it under the terms of the GNU General Public License as published by
  3. # the Free Software Foundation; either version 2 of the License, or
  4. # (at your option) any later version.
  5. import os
  6. import os.path
  7. import re
  8. import shutil
  9. import tempfile
  10. import unittest2 as unittest
  11. from bkr.inttest.client import run_wizard
  12. class BaseWizardTestCase(unittest.TestCase):
  13. def setUp(self):
  14. base_tempdir = tempfile.mkdtemp()
  15. # Create a sub directory to avoid sending the wizard in an infinite
  16. # loop. The subdirectory will be treated as a package directory by the
  17. # wizard. Any invalid characters in the name will cause the wizard to
  18. # ask for a new name until provided by the user.
  19. self.tempdir = os.path.join(base_tempdir, 'dummy')
  20. os.mkdir(self.tempdir)
  21. self.addCleanup(shutil.rmtree, base_tempdir)
  22. class TestWizard(BaseWizardTestCase):
  23. def test_shows_help_successfully(self):
  24. out = run_wizard(['beaker-wizard', '--help'])
  25. self.assertRegexpMatches(out, re.compile(r'\bBeaker Wizard\b', re.I), out)
  26. def test_shows_help_with_nonexistend_command(self):
  27. """Tests that we don't get a traceback if the user invokes the wizard
  28. with a nonexistend command."""
  29. out = run_wizard(['beaker-wizard', 'bogus', '--help'], cwd=self.tempdir)
  30. self.assertRegexpMatches(out, re.compile(r'\bBeaker Wizard\b', re.I), out)
  31. def test_wizard_guesses_package_from_cwd(self):
  32. # When run with no args, beaker-wizard guesses the package from the cwd
  33. # and uses defaults for everything else.
  34. package = 'bash'
  35. test_path = os.path.join(self.tempdir, package)
  36. os.mkdir(test_path)
  37. out = run_wizard(['beaker-wizard'], cwd=test_path)
  38. self.assertIn('Package : %s' % package, out)
  39. def test_wizard_guesses_values_from_test_name(self):
  40. # When given a test name, beaker-wizard creates its output in that
  41. # subdirectory and also guesses some values based on the directory
  42. # structure. Here we cover each of the possibilities described in the
  43. # man page.
  44. # TESTNAME
  45. out = run_wizard(['beaker-wizard', 'test-it-works'], cwd=self.tempdir)
  46. self.assertIn('Test name : test-it-works', out)
  47. # TYPE/TESTNAME
  48. out = run_wizard(['beaker-wizard', 'Sanity/test-it-works'], cwd=self.tempdir)
  49. self.assertIn('Test type : Sanity', out)
  50. self.assertIn('Test name : test-it-works', out)
  51. # TYPE/PATH/TESTNAME
  52. out = run_wizard(['beaker-wizard', 'Sanity/http/test-it-works'], cwd=self.tempdir)
  53. self.assertIn('Test type : Sanity', out)
  54. self.assertIn('Relative path : http', out)
  55. self.assertIn('Test name : test-it-works', out)
  56. # PACKAGE/TYPE/NAME
  57. out = run_wizard(['beaker-wizard', 'wget/Sanity/test-it-works'], cwd=self.tempdir)
  58. self.assertIn('Package : wget', out)
  59. self.assertIn('Test type : Sanity', out)
  60. self.assertIn('Relative path : None', out)
  61. self.assertIn('Test name : test-it-works', out)
  62. # PACKAGE/TYPE/PATH/NAME
  63. out = run_wizard(['beaker-wizard', 'wget/Sanity/http/test-it-works'], cwd=self.tempdir)
  64. self.assertIn('Package : wget', out)
  65. self.assertIn('Test type : Sanity', out)
  66. self.assertIn('Relative path : http', out)
  67. self.assertIn('Test name : test-it-works', out)
  68. # NAMESPACE/PACKAGE/TYPE/NAME
  69. out = run_wizard(['beaker-wizard', 'distribution/wget/Sanity/test-it-works'], cwd=self.tempdir)
  70. self.assertIn('Namespace : distribution', out)
  71. self.assertIn('Package : wget', out)
  72. self.assertIn('Test type : Sanity', out)
  73. self.assertIn('Relative path : None', out)
  74. self.assertIn('Test name : test-it-works', out)
  75. # NAMESPACE/PACKAGE/TYPE/PATH/NAME
  76. out = run_wizard(['beaker-wizard', 'distribution/wget/Sanity/http/test-it-works'], cwd=self.tempdir)
  77. self.assertIn('Namespace : distribution', out)
  78. self.assertIn('Package : wget', out)
  79. self.assertIn('Test type : Sanity', out)
  80. self.assertIn('Relative path : http', out)
  81. self.assertIn('Test name : test-it-works', out)
  82. # https://bugzilla.redhat.com/show_bug.cgi?id=1184907
  83. def test_creates_successfully_custom_test_type(self):
  84. out = run_wizard(['beaker-wizard', 'http/test1'], cwd=self.tempdir)
  85. self.assertIn('Test type : http', out)
  86. self.assertIn('Relative path : None', out)
  87. self.assertIn('Test name : test1', out)
  88. # https://bugzilla.redhat.com/show_bug.cgi?id=857090
  89. def test_rhtsrequired_option(self):
  90. out = run_wizard(['beaker-wizard', '-Q', 'library(perl/lib1)',
  91. 'http/test-rhtsrequired'],
  92. cwd=self.tempdir)
  93. self.assertIn('Required RHTS tests/libraries : library(perl/lib1)', out)
  94. # assert if it's set properly in the Makefile
  95. makefile_contents = open(os.path.join(self.tempdir,
  96. 'http', 'test-rhtsrequired', 'Makefile'), 'r').readlines()
  97. self.assertIn('\t@echo "RhtsRequires: library(perl/lib1)" >> $(METADATA)\n',
  98. makefile_contents)
  99. # https://bugzilla.redhat.com/show_bug.cgi?id=857090
  100. def test_rhtsrequires_in_skeleton_xml_tag(self):
  101. out = run_wizard(['beaker-wizard', '-s', 'skel1',
  102. 'http/test-rhtsrequired'], cwd=self.tempdir)
  103. self.assertIn('Required RHTS tests/libraries : '
  104. 'library(perl/lib1), library(scl/lib2)', out)
  105. # assert if it's set properly in the Makefile
  106. makefile_contents = open(os.path.join(self.tempdir,
  107. 'http', 'test-rhtsrequired', 'Makefile'), 'r').readlines()
  108. self.assertIn('\t@echo "RhtsRequires: '
  109. 'library(perl/lib1) library(scl/lib2)" >> $(METADATA)\n',
  110. makefile_contents)