test_pgjsonb.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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
  13. from tests.support.mock import (
  14. MagicMock,
  15. patch
  16. )
  17. # Import Salt libs
  18. import salt.returners.pgjsonb as pgjsonb
  19. log = logging.getLogger(__name__)
  20. class PGJsonbCleanOldJobsTestCase(TestCase, LoaderModuleMockMixin):
  21. '''
  22. Tests for the local_cache.clean_old_jobs function.
  23. '''
  24. def setup_loader_modules(self):
  25. return {pgjsonb: {'__opts__': {'keep_jobs': 1, 'archive_jobs': 0}}}
  26. def test_clean_old_jobs_purge(self):
  27. '''
  28. Tests that the function returns None when no jid_root is found.
  29. '''
  30. connect_mock = MagicMock()
  31. with patch.object(pgjsonb, '_get_serv', connect_mock):
  32. with patch.dict(pgjsonb.__salt__, {'config.option': MagicMock()}):
  33. self.assertEqual(pgjsonb.clean_old_jobs(), None)
  34. def test_clean_old_jobs_archive(self):
  35. '''
  36. Tests that the function returns None when no jid_root is found.
  37. '''
  38. connect_mock = MagicMock()
  39. with patch.object(pgjsonb, '_get_serv', connect_mock):
  40. with patch.dict(pgjsonb.__salt__, {'config.option': MagicMock()}):
  41. with patch.dict(pgjsonb.__opts__, {'archive_jobs': 1}):
  42. self.assertEqual(pgjsonb.clean_old_jobs(), None)