1
0

test_pgjsonb.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # -*- coding: utf-8 -*-
  2. '''
  3. tests.unit.returners.pgjsonb_test
  4. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5. Unit tests for the PGJsonb returner (pgjsonb).
  6. '''
  7. # Import Python libs
  8. from __future__ import absolute_import, print_function, unicode_literals
  9. import logging
  10. # Import Salt Testing libs
  11. from tests.support.mixins import LoaderModuleMockMixin
  12. from tests.support.unit import TestCase, skipIf
  13. from tests.support.mock import (
  14. MagicMock,
  15. NO_MOCK,
  16. NO_MOCK_REASON,
  17. patch
  18. )
  19. # Import Salt libs
  20. import salt.returners.pgjsonb as pgjsonb
  21. log = logging.getLogger(__name__)
  22. @skipIf(NO_MOCK, NO_MOCK_REASON)
  23. class PGJsonbCleanOldJobsTestCase(TestCase, LoaderModuleMockMixin):
  24. '''
  25. Tests for the local_cache.clean_old_jobs function.
  26. '''
  27. def setup_loader_modules(self):
  28. return {pgjsonb: {'__opts__': {'keep_jobs': 1, 'archive_jobs': 0}}}
  29. def test_clean_old_jobs_purge(self):
  30. '''
  31. Tests that the function returns None when no jid_root is found.
  32. '''
  33. connect_mock = MagicMock()
  34. with patch.object(pgjsonb, '_get_serv', connect_mock):
  35. with patch.dict(pgjsonb.__salt__, {'config.option': MagicMock()}):
  36. self.assertEqual(pgjsonb.clean_old_jobs(), None)
  37. def test_clean_old_jobs_archive(self):
  38. '''
  39. Tests that the function returns None when no jid_root is found.
  40. '''
  41. connect_mock = MagicMock()
  42. with patch.object(pgjsonb, '_get_serv', connect_mock):
  43. with patch.dict(pgjsonb.__salt__, {'config.option': MagicMock()}):
  44. with patch.dict(pgjsonb.__opts__, {'archive_jobs': 1}):
  45. self.assertEqual(pgjsonb.clean_old_jobs(), None)