This commit is contained in:
Alexis Métaireau 2015-09-17 16:54:23 +02:00
Родитель f1dcf506f1
Коммит bfd307c35e
3 изменённых файлов: 35 добавлений и 0 удалений

3
dev-requirements.txt Normal file
Просмотреть файл

@ -0,0 +1,3 @@
mock
unittest2
pytest

0
tests/__init__.py Normal file
Просмотреть файл

32
tests/test_sops.py Normal file
Просмотреть файл

@ -0,0 +1,32 @@
import unittest2
import mock
import sops
from sys import version_info
if version_info.major == 2:
import __builtin__ as builtins # pylint:disable=import-error
else:
import builtins # pylint:disable=import-error
class TreeTest(unittest2.TestCase):
def test_json_loader_is_used_on_json_filetype(self):
# XXX put some real json here.
m = mock.mock_open(read_data='"content"')
with mock.patch.object(builtins, 'open', m):
assert sops.load_tree('path', 'json') == "content"
def test_yaml_loader_is_used_on_yaml_filetype(self):
# XXX put some real yaml here.
m = mock.mock_open(read_data='"content"')
with mock.patch.object(builtins, 'open', m):
assert sops.load_tree('path', 'yaml') == "content"
@mock.patch('sops.json.load')
def test_example_with_a_mocked_call(self, json_mock):
m = mock.mock_open(read_data='"content"')
with mock.patch.object(builtins, 'open', m):
sops.load_tree('path', 'json')
json_mock.assert_called_with(m())