1
0

test_etcd_db.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. """
  2. Test case for the etcd SDB module
  3. """
  4. import logging
  5. import salt.sdb.etcd_db as etcd_db
  6. import salt.utils.etcd_util as etcd_util
  7. from tests.support.mixins import LoaderModuleMockMixin
  8. from tests.support.mock import MagicMock, call, create_autospec, patch
  9. from tests.support.unit import TestCase
  10. log = logging.getLogger(__name__)
  11. class TestEtcdSDB(LoaderModuleMockMixin, TestCase):
  12. """
  13. Test case for the etcd_db SDB module
  14. """
  15. def setup_loader_modules(self):
  16. return {
  17. etcd_db: {
  18. "__opts__": {
  19. "myetcd": {
  20. "url": "http://127.0.0.1",
  21. "auth": {"token": "test", "method": "token"},
  22. }
  23. }
  24. }
  25. }
  26. def setUp(self):
  27. self.instance = create_autospec(etcd_util.EtcdClient)
  28. self.EtcdClientMock = MagicMock()
  29. self.EtcdClientMock.return_value = self.instance
  30. def tearDown(self):
  31. del self.instance
  32. del self.EtcdClientMock
  33. def test_set(self):
  34. """
  35. Test salt.sdb.etcd_db.set function
  36. """
  37. with patch("salt.sdb.etcd_db._get_conn", self.EtcdClientMock):
  38. etcd_db.set_("sdb://myetcd/path/to/foo/bar", "super awesome")
  39. self.assertEqual(
  40. self.instance.set.call_args_list,
  41. [call("sdb://myetcd/path/to/foo/bar", "super awesome")],
  42. )
  43. self.assertEqual(
  44. self.instance.get.call_args_list, [call("sdb://myetcd/path/to/foo/bar")],
  45. )
  46. def test_get(self):
  47. """
  48. Test salt.sdb.etcd_db.get function
  49. """
  50. with patch("salt.sdb.etcd_db._get_conn", self.EtcdClientMock):
  51. etcd_db.get("sdb://myetcd/path/to/foo/bar")
  52. self.assertEqual(
  53. self.instance.get.call_args_list, [call("sdb://myetcd/path/to/foo/bar")],
  54. )