@@ -140,3 +140,113 @@ def testBmSteppedBreak2(self):
140
140
e .exception .errType ,
141
141
BmValidationError .BmValErrType .LOW_LOCAL_GAP
142
142
)
143
+
144
+ @skip_commit_slider_devtest
145
+ def testForsubstitutionRule (self ):
146
+ from utils .helpers import applySubstitutionRules
147
+ cfg = {
148
+ "serviceConfig" : {
149
+ "previousKey" : "previousValue"
150
+ },
151
+ "wrongDst" : "{commitHash1} is unchanged" ,
152
+ "dst" : {
153
+ "complex" : {
154
+ "path" : [
155
+ "{commitHash1} is natural number" ,
156
+ "{commitHash2} is natural number" ,
157
+ "{commitHash1} is {commitHash2}"
158
+ ]
159
+ }
160
+ },
161
+ "src" : {
162
+ "complex" : {
163
+ "path" : {
164
+ "one" : "1" ,
165
+ "two" : "2"
166
+ }
167
+ }
168
+ }
169
+ }
170
+ rules = [
171
+ {
172
+ "name" : "testRule1" ,
173
+ "enabled" : True ,
174
+ "type" : "map" ,
175
+ "placeholder" : "commitHash1" ,
176
+ "from" : "$.src.complex.path" ,
177
+ "to" : "$.dst.complex.path"
178
+ },
179
+ {
180
+ "name" : "testRule2" ,
181
+ "enabled" : True ,
182
+ "type" : "map" ,
183
+ "placeholder" : "commitHash2" ,
184
+ "from" : "$.src.complex.path" ,
185
+ "to" : "$.dst.complex.path"
186
+ }
187
+ ]
188
+ def applyByRef (cfg : map , rules : list , substitution : str ):
189
+ applySubstitutionRules (cfg , rules , substitution )
190
+
191
+ applyByRef (cfg , rules , "one" )
192
+
193
+ # assert first substitution
194
+ self .assertEqual (
195
+ cfg ["dst" ]["complex" ]["path" ][0 ],
196
+ "1 is natural number"
197
+ )
198
+ self .assertEqual (
199
+ cfg ["dst" ]["complex" ]["path" ][1 ],
200
+ "1 is natural number"
201
+ )
202
+ self .assertEqual (
203
+ cfg ["dst" ]["complex" ]["path" ][2 ],
204
+ "1 is 1"
205
+ )
206
+ self .assertEqual (
207
+ cfg ["wrongDst" ],
208
+ "{commitHash1} is unchanged"
209
+ )
210
+
211
+ applyByRef (cfg , rules , "two" )
212
+
213
+ # assert second substitution
214
+ self .assertEqual (
215
+ cfg ["dst" ]["complex" ]["path" ][0 ],
216
+ "2 is natural number"
217
+ )
218
+ self .assertEqual (
219
+ cfg ["dst" ]["complex" ]["path" ][1 ],
220
+ "2 is natural number"
221
+ )
222
+ self .assertEqual (
223
+ cfg ["dst" ]["complex" ]["path" ][2 ],
224
+ "2 is 2"
225
+ )
226
+ self .assertEqual (
227
+ cfg ["wrongDst" ],
228
+ "{commitHash1} is unchanged"
229
+ )
230
+
231
+ @skip_commit_slider_devtest
232
+ def testForDeepUpdate (self ):
233
+ from utils .helpers import deepMapUpdate
234
+ cfg = {
235
+ "another" : {
236
+ "path" : "not updated"
237
+ },
238
+ "path" : {
239
+ "to" : {
240
+ "placeholder" : "not updated"
241
+ }
242
+ }
243
+ }
244
+ cfg = deepMapUpdate (cfg , ["path" , "to" , "placeholder" ], "updated" )
245
+ self .assertEqual (
246
+ cfg ["path" ]["to" ]["placeholder" ],
247
+ "updated"
248
+ )
249
+ self .assertEqual (
250
+ cfg ["another" ]["path" ],
251
+ "not updated"
252
+ )
0 commit comments