-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52747 from que5o/fix-csvpillar-read
Fix csvpillar.py read file as binary
- Loading branch information
Showing
2 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# -*- coding: utf-8 -*- | ||
'''test for pillar csvpillar.py''' | ||
|
||
# Import python libs | ||
from __future__ import absolute_import, print_function, unicode_literals | ||
|
||
# Import Salt Testing libs | ||
from tests.support.unit import TestCase, skipIf | ||
from tests.support.mock import patch, mock_open, NO_MOCK, NO_MOCK_REASON | ||
|
||
# Import Salt Libs | ||
import salt.pillar.csvpillar as csvpillar | ||
|
||
|
||
@skipIf(NO_MOCK, NO_MOCK_REASON) | ||
class CSVPillarTestCase(TestCase): | ||
def test_001_load_utf8_csv(self): | ||
fake_csv = "id,foo,bar\r\nminion1,foo1,bar1" | ||
fake_dict = {'id': 'minion1', 'foo': 'foo1', 'bar': 'bar1'} | ||
fopen_mock = mock_open(fake_csv) | ||
with patch('salt.utils.files.fopen', fopen_mock): | ||
result = csvpillar.ext_pillar(mid='minion1', pillar=None, | ||
path="/fake/path/file.csv", idkey="id", namespace=None) | ||
self.assertDictEqual(fake_dict, result) | ||
|
||
def test_002_load_utf8_csv_namespc(self): | ||
fake_csv = "id,foo,bar\r\nminion1,foo1,bar1" | ||
fake_dict = {'baz': {'id': 'minion1', 'foo': 'foo1', 'bar': 'bar1'}} | ||
fopen_mock = mock_open(fake_csv) | ||
with patch('salt.utils.files.fopen', fopen_mock): | ||
result = csvpillar.ext_pillar(mid='minion1', pillar=None, | ||
path="/fake/path/file.csv", idkey="id", namespace='baz') | ||
self.assertDictEqual(fake_dict, result) |