test_pgjsonb.py 1.6 KB

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