test_setup_params.py 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # -*- coding: utf-8 -*-
  2. # vim: tabstop=4 shiftwidth=4 softtabstop=4
  3. # Copyright 2013, Red Hat, Inc.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  6. # not use this file except in compliance with the License. You may obtain
  7. # a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. # License for the specific language governing permissions and limitations
  15. # under the License.
  16. """
  17. Test cases for packstack.installer.core.parameters module.
  18. """
  19. from unittest import TestCase
  20. from ..test_base import PackstackTestCaseMixin
  21. from packstack.installer.core.parameters import *
  22. class ParameterTestCase(PackstackTestCaseMixin, TestCase):
  23. def setUp(self):
  24. super(ParameterTestCase, self).setUp()
  25. self.data = {
  26. "CMD_OPTION": "mariadb-host",
  27. "USAGE": ("The IP address of the server on which to "
  28. "install MariaDB"),
  29. "PROMPT": "Enter the IP address of the MariaDB server",
  30. "OPTION_LIST": [],
  31. "VALIDATORS": [],
  32. "DEFAULT_VALUE": "127.0.0.1",
  33. "MASK_INPUT": False,
  34. "LOOSE_VALIDATION": True,
  35. "CONF_NAME": "CONFIG_MARIADB_HOST",
  36. "USE_DEFAULT": False,
  37. "NEED_CONFIRM": False,
  38. "CONDITION": False}
  39. def test_parameter_init(self):
  40. """
  41. Test packstack.installer.core.parameters.Parameter
  42. initialization
  43. """
  44. param = Parameter(self.data)
  45. for key, value in self.data.iteritems():
  46. self.assertEqual(getattr(param, key), value)
  47. def test_default_attribute(self):
  48. """
  49. Test packstack.installer.core.parameters.Parameter default value
  50. """
  51. param = Parameter()
  52. self.assertIsNone(param.PROCESSORS)
  53. class GroupTestCase(PackstackTestCaseMixin, TestCase):
  54. def setUp(self):
  55. super(GroupTestCase, self).setUp()
  56. self.attrs = {
  57. "GROUP_NAME": "MARIADB",
  58. "DESCRIPTION": "MariaDB Config parameters",
  59. "PRE_CONDITION": "y",
  60. "PRE_CONDITION_MATCH": "y",
  61. "POST_CONDITION": False,
  62. "POST_CONDITION_MATCH": False}
  63. self.params = [
  64. {"CONF_NAME": "CONFIG_MARIADB_HOST", "PROMPT": "find_me"},
  65. {"CONF_NAME": "CONFIG_MARIADB_USER"},
  66. {"CONF_NAME": "CONFIG_MARIADB_PW"}]
  67. def test_group_init(self):
  68. """
  69. Test packstack.installer.core.parameters.Group initialization
  70. """
  71. group = Group(attributes=self.attrs, parameters=self.params)
  72. for key, value in self.attrs.iteritems():
  73. self.assertEqual(getattr(group, key), value)
  74. for param in self.params:
  75. self.assertIn(param['CONF_NAME'], group.parameters)
  76. def test_search(self):
  77. """
  78. Test packstack.installer.core.parameters.Group search method
  79. """
  80. group = Group(attributes=self.attrs, parameters=self.params)
  81. param_list = group.search('PROMPT', 'find_me')
  82. self.assertEqual(len(param_list), 1)
  83. self.assertIsInstance(param_list[0], Parameter)
  84. self.assertEqual(param_list[0].CONF_NAME, 'CONFIG_MARIADB_HOST')