1
0

test_oracle.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # -*- coding: utf-8 -*-
  2. """
  3. :codeauthor: Rahul Handay <rahulha@saltstack.com>
  4. """
  5. # Import Python Libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. import os
  8. # Import Salt Libs
  9. import salt.modules.oracle as oracle
  10. # Import Salt Testing Libs
  11. from tests.support.mixins import LoaderModuleMockMixin
  12. from tests.support.mock import MagicMock, patch
  13. from tests.support.unit import TestCase
  14. class OracleTestCase(TestCase, LoaderModuleMockMixin):
  15. """
  16. Test cases for salt.modules.oracle
  17. """
  18. def setup_loader_modules(self):
  19. return {oracle: {"cx_Oracle": object()}}
  20. def test_run_query(self):
  21. """
  22. Test for Run SQL query and return result
  23. """
  24. with patch.object(oracle, "_connect", MagicMock()) as mock_connect:
  25. mock_connect.cursor.execute.fetchall.return_value = True
  26. with patch.object(oracle, "show_dbs", MagicMock()):
  27. self.assertTrue(oracle.run_query("db", "query"))
  28. def test_show_dbs(self):
  29. """
  30. Test for Show databases configuration from pillar. Filter by `*args`
  31. """
  32. with patch.dict(oracle.__salt__, {"pillar.get": MagicMock(return_value="a")}):
  33. self.assertDictEqual(oracle.show_dbs("A", "B"), {"A": "a", "B": "a"})
  34. self.assertEqual(oracle.show_dbs(), "a")
  35. def test_version(self):
  36. """
  37. Test for Server Version (select banner from v$version)
  38. """
  39. with patch.dict(oracle.__salt__, {"pillar.get": MagicMock(return_value="a")}):
  40. with patch.object(oracle, "run_query", return_value="A"):
  41. self.assertDictEqual(oracle.version(), {})
  42. def test_client_version(self):
  43. """
  44. Test for Oracle Client Version
  45. """
  46. with patch.object(oracle, "cx_Oracle", MagicMock(side_effect=MagicMock())):
  47. self.assertEqual(oracle.client_version(), "")
  48. def test_show_pillar(self):
  49. """
  50. Test for Show Pillar segment oracle.*
  51. """
  52. with patch.dict(oracle.__salt__, {"pillar.get": MagicMock(return_value="a")}):
  53. self.assertEqual(oracle.show_pillar("item"), "a")
  54. def test_show_env(self):
  55. """
  56. Test for Show Environment used by Oracle Client
  57. """
  58. with patch.object(
  59. os,
  60. "environ",
  61. return_value={
  62. "PATH": "PATH",
  63. "ORACLE_HOME": "ORACLE_HOME",
  64. "TNS_ADMIN": "TNS_ADMIN",
  65. "NLS_LANG": "NLS_LANG",
  66. },
  67. ):
  68. self.assertDictEqual(oracle.show_env(), {})