1
0

test_zypp_plugins.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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
  9. from tests.support.mock import (
  10. MagicMock,
  11. patch,
  12. )
  13. import os
  14. import imp
  15. import sys
  16. from zypp_plugin import BogusIO
  17. if sys.version_info >= (3,):
  18. BUILTINS_OPEN = 'builtins.open'
  19. else:
  20. BUILTINS_OPEN = '__builtin__.open'
  21. ZYPPNOTIFY_FILE = os.path.sep.join(
  22. os.path.dirname(__file__).split(os.path.sep)[:-2] +
  23. ['scripts', 'suse', 'zypper', 'plugins', 'commit', 'zyppnotify']
  24. )
  25. class ZyppPluginsTestCase(TestCase):
  26. '''
  27. Test shipped libzypp plugins.
  28. '''
  29. def test_drift_detector(self):
  30. '''
  31. Test drift detector for a correct cookie file.
  32. Returns:
  33. '''
  34. zyppnotify = imp.load_source('zyppnotify', ZYPPNOTIFY_FILE)
  35. drift = zyppnotify.DriftDetector()
  36. drift._get_mtime = MagicMock(return_value=123)
  37. drift._get_checksum = MagicMock(return_value='deadbeef')
  38. bogus_io = BogusIO()
  39. with patch(BUILTINS_OPEN, bogus_io):
  40. drift.PLUGINEND(None, None)
  41. self.assertEqual(str(bogus_io), 'deadbeef 123\n')
  42. self.assertEqual(bogus_io.mode, 'w')
  43. self.assertEqual(bogus_io.path, '/var/cache/salt/minion/rpmdb.cookie')