test_csvpillar.py 1.3 KB

123456789101112131415161718192021222324252627282930313233
  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 Testing libs
  6. from tests.support.unit import TestCase
  7. from tests.support.mock import patch, mock_open
  8. # Import Salt Libs
  9. import salt.pillar.csvpillar as csvpillar
  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(mid='minion1', pillar=None,
  17. path="/fake/path/file.csv", idkey="id", namespace=None)
  18. self.assertDictEqual(fake_dict, result)
  19. def test_002_load_utf8_csv_namespc(self):
  20. fake_csv = "id,foo,bar\r\nminion1,foo1,bar1"
  21. fake_dict = {'baz': {'id': 'minion1', 'foo': 'foo1', 'bar': 'bar1'}}
  22. fopen_mock = mock_open(fake_csv)
  23. with patch('salt.utils.files.fopen', fopen_mock):
  24. result = csvpillar.ext_pillar(mid='minion1', pillar=None,
  25. path="/fake/path/file.csv", idkey="id", namespace='baz')
  26. self.assertDictEqual(fake_dict, result)