PageRenderTime 57ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/pulp_rpm/test/unit/server/test_plugins_configuration_utils.py

https://github.com/arnisoph/pulp_rpm
Python | 53 lines | 18 code | 9 blank | 26 comment | 2 complexity | bc66c66675fabd4a007ed07b94ceb054 MD5 | raw file
  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright © 2013 Red Hat, Inc.
  4. #
  5. # This software is licensed to you under the GNU General Public
  6. # License as published by the Free Software Foundation; either version
  7. # 2 of the License (GPLv2) or (at your option) any later version.
  8. # There is NO WARRANTY for this software, express or implied,
  9. # including the implied warranties of MERCHANTABILITY,
  10. # NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
  11. # have received a copy of GPLv2 along with this software; if not, see
  12. # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
  13. import unittest
  14. from distributor_mocks import get_basic_config
  15. from pulp_rpm.plugins import configuration_utils
  16. class TestValidateNonRequiredBool(unittest.TestCase):
  17. """
  18. Assert correct behavior from the _validate_required_bool() function.
  19. """
  20. def test_bool_not_set(self):
  21. """
  22. If the bool is not set, it should be cool.
  23. """
  24. config = get_basic_config()
  25. # This should not raise an Exception, since the setting is not required
  26. configuration_utils.validate_non_required_bool(config, 'setting_name')
  27. def test_bool_not_valid(self):
  28. """
  29. If the bool is not valid, it should return an error.
  30. """
  31. config = get_basic_config(**{'setting_name': 'Not true or false.'})
  32. try:
  33. configuration_utils.validate_non_required_bool(config, 'setting_name')
  34. self.fail('The validation should have failed, but it did not.')
  35. except configuration_utils.ValidationError, e:
  36. self.assertEqual(str(e), 'The configuration parameter <setting_name> may only be set to a '
  37. 'boolean value, but is currently set to <Not true or false.>.')
  38. def test_bool_valid(self):
  39. """
  40. If the bool is valid, it should return successfully.
  41. """
  42. config = get_basic_config(**{'setting_name': 'false'})
  43. # This should not raise an Exception
  44. configuration_utils.validate_non_required_bool(config, 'setting_name')