1
0

test_zypp_plugins.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: Bo Maryniuk <bo@suse.de>
  4. '''
  5. # Import Python Libs
  6. from __future__ import absolute_import
  7. # Import Salt Testing Libs
  8. from tests.support.unit import TestCase, skipIf
  9. from tests.support.mock import (
  10. MagicMock,
  11. patch,
  12. NO_MOCK,
  13. NO_MOCK_REASON
  14. )
  15. import os
  16. import imp
  17. import sys
  18. from zypp_plugin import BogusIO
  19. if sys.version_info >= (3,):
  20. BUILTINS_OPEN = 'builtins.open'
  21. else:
  22. BUILTINS_OPEN = '__builtin__.open'
  23. ZYPPNOTIFY_FILE = os.path.sep.join(
  24. os.path.dirname(__file__).split(os.path.sep)[:-2] +
  25. ['scripts', 'suse', 'zypper', 'plugins', 'commit', 'zyppnotify']
  26. )
  27. @skipIf(NO_MOCK, NO_MOCK_REASON)
  28. class ZyppPluginsTestCase(TestCase):
  29. '''
  30. Test shipped libzypp plugins.
  31. '''
  32. def test_drift_detector(self):
  33. '''
  34. Test drift detector for a correct cookie file.
  35. Returns:
  36. '''
  37. zyppnotify = imp.load_source('zyppnotify', ZYPPNOTIFY_FILE)
  38. drift = zyppnotify.DriftDetector()
  39. drift._get_mtime = MagicMock(return_value=123)
  40. drift._get_checksum = MagicMock(return_value='deadbeef')
  41. bogus_io = BogusIO()
  42. with patch(BUILTINS_OPEN, bogus_io):
  43. drift.PLUGINEND(None, None)
  44. self.assertEqual(str(bogus_io), 'deadbeef 123\n')
  45. self.assertEqual(bogus_io.mode, 'w')
  46. self.assertEqual(bogus_io.path, '/var/cache/salt/minion/rpmdb.cookie')