1
0

test_csvpillar.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # -*- coding: utf-8 -*-
  2. """test for pillar csvpillar.py"""
  3. # Import python libs
  4. from __future__ import absolute_import, print_function, unicode_literals
  5. # Import Salt Libs
  6. import salt.pillar.csvpillar as csvpillar
  7. from tests.support.mock import mock_open, patch
  8. # Import Salt Testing libs
  9. from tests.support.unit import TestCase
  10. class CSVPillarTestCase(TestCase):
  11. def test_001_load_utf8_csv(self):
  12. fake_csv = "id,foo,bar\r\nminion1,foo1,bar1"
  13. fake_dict = {"id": "minion1", "foo": "foo1", "bar": "bar1"}
  14. fopen_mock = mock_open(fake_csv)
  15. with patch("salt.utils.files.fopen", fopen_mock):
  16. result = csvpillar.ext_pillar(
  17. mid="minion1",
  18. pillar=None,
  19. path="/fake/path/file.csv",
  20. idkey="id",
  21. namespace=None,
  22. )
  23. self.assertDictEqual(fake_dict, result)
  24. def test_002_load_utf8_csv_namespc(self):
  25. fake_csv = "id,foo,bar\r\nminion1,foo1,bar1"
  26. fake_dict = {"baz": {"id": "minion1", "foo": "foo1", "bar": "bar1"}}
  27. fopen_mock = mock_open(fake_csv)
  28. with patch("salt.utils.files.fopen", fopen_mock):
  29. result = csvpillar.ext_pillar(
  30. mid="minion1",
  31. pillar=None,
  32. path="/fake/path/file.csv",
  33. idkey="id",
  34. namespace="baz",
  35. )
  36. self.assertDictEqual(fake_dict, result)