Skip to content

Commit 0dfd8c8

Browse files
CH-149 Add unit tests for the added utility
1 parent b291842 commit 0dfd8c8

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

tools/deployment-cli-tools/tests/test_utils.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,65 @@ def test_find_dockerfile_paths():
8787
assert len(dockerfiles) == 2
8888
assert next(d for d in dockerfiles if d.endswith("myapp")), "Must find the Dockerfile in the root directory"
8989
assert next(d for d in dockerfiles if d.endswith("myapp/tasks/mytask")), "Must find the Dockerfile in the tasks directory"
90+
91+
92+
class TestReplaceInDict:
93+
def test_does_not_replace_in_keys(_):
94+
src_dict = {
95+
'foo': 1,
96+
'bar': 2,
97+
'baz': 3,
98+
'foobar': 4,
99+
}
100+
101+
new_dict = replace_in_dict(src_dict, 'foo', 'xxx')
102+
103+
assert new_dict.keys() == src_dict.keys()
104+
105+
def test_replaces_in_values(_):
106+
src_dict = {
107+
'a': 'foo',
108+
'b': 'bar',
109+
'c': 'baz',
110+
'd': 3,
111+
'e': 'foobar',
112+
}
113+
114+
new_dict = replace_in_dict(src_dict, 'foo', 'xxx')
115+
116+
assert new_dict == {
117+
'a': 'xxx',
118+
'b': 'bar',
119+
'c': 'baz',
120+
'd': 3,
121+
'e': 'xxxbar',
122+
}
123+
124+
def test_replaces_in_values_within_lists(_):
125+
src_dict = {
126+
'a': ['foo', 'bar', 'baz', 3, 'foobar'],
127+
}
128+
129+
new_dict = replace_in_dict(src_dict, 'foo', 'xxx')
130+
131+
assert new_dict['a'] == ['xxx', 'bar', 'baz', 3, 'xxxbar']
132+
133+
134+
def test_replaces_in_values_within_nested_dict(_):
135+
src_dict = {
136+
'a': {
137+
'a': 'foo',
138+
'b': 'bar',
139+
'c': 'foobar',
140+
'e': ['foo', 'bar', 'foobar'],
141+
},
142+
}
143+
144+
new_dict = replace_in_dict(src_dict, 'foo', 'xxx')
145+
146+
assert new_dict['a'] == {
147+
'a': 'xxx',
148+
'b': 'bar',
149+
'c': 'xxxbar',
150+
'e': ['xxx', 'bar', 'xxxbar']
151+
}

0 commit comments

Comments
 (0)