-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtests.py
More file actions
executable file
·50 lines (39 loc) · 1.37 KB
/
tests.py
File metadata and controls
executable file
·50 lines (39 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
import os
import sys
from unittest import TestCase
from credentials_replacer.replacer import render_with_credentials
if sys.version_info[0] == 3:
from unittest.mock import patch
elif sys.version_info[0] == 2:
from mock import patch
class TestReplacer(TestCase):
"""A test case for replacer"""
def setUp(self):
"""Make test file
Create file which has ``file_path`` path with content with jinja2
placeholders
"""
self.file_path = 'tmp/test.json'
template = '{"cred1": "{{ TEST_CRED1 }}", "cred2": "{{ TEST_CRED2 }}"}'
os.makedirs('tmp')
with open(self.file_path, 'w') as f:
f.write(template)
def tearDown(self):
"""Remove temporary created file"""
os.unlink(self.file_path)
os.rmdir('tmp')
@patch('credentials_replacer.replacer.listSecrets', return_value=[
{
'name': 'TEST_CRED1',
},
{
'name': 'TEST_CRED2',
},
])
@patch('credentials_replacer.replacer.getSecret',
side_effect=['test_value1', 'test_value2'])
def test_credentials_render(self, _1, _2):
"""Ensure that credentials obtained and template renders correctly"""
self.assertEqual(render_with_credentials(self.file_path),
'{"cred1": "test_value1", "cred2": "test_value2"}')