21
21
CustomSignalOperator ,
22
22
PercentConditionOperator ,
23
23
_REMOTE_CONFIG_ATTRIBUTE ,
24
- _RemoteConfigService ,
25
- ServerTemplateData )
24
+ _RemoteConfigService )
26
25
from firebase_admin import remote_config , _utils
27
26
from tests import testutils
28
27
@@ -121,12 +120,12 @@ def test_evaluate_or_and_true_condition_true(self):
121
120
},
122
121
'parameterGroups' : '' ,
123
122
'version' : '' ,
124
- 'etag' : '123 '
123
+ 'etag' : 'etag '
125
124
}
126
125
server_template = remote_config .init_server_template (
127
126
app = app ,
128
127
default_config = default_config ,
129
- template_data = ServerTemplateData ( 'etag' , template_data )
128
+ template_data_json = json . dumps ( template_data )
130
129
)
131
130
132
131
server_config = server_template .evaluate ()
@@ -165,12 +164,12 @@ def test_evaluate_or_and_false_condition_false(self):
165
164
},
166
165
'parameterGroups' : '' ,
167
166
'version' : '' ,
168
- 'etag' : '123 '
167
+ 'etag' : 'etag '
169
168
}
170
169
server_template = remote_config .init_server_template (
171
170
app = app ,
172
171
default_config = default_config ,
173
- template_data = ServerTemplateData ( 'etag' , template_data )
172
+ template_data_json = json . dumps ( template_data )
174
173
)
175
174
176
175
server_config = server_template .evaluate ()
@@ -196,12 +195,12 @@ def test_evaluate_non_or_condition(self):
196
195
},
197
196
'parameterGroups' : '' ,
198
197
'version' : '' ,
199
- 'etag' : '123 '
198
+ 'etag' : 'etag '
200
199
}
201
200
server_template = remote_config .init_server_template (
202
201
app = app ,
203
202
default_config = default_config ,
204
- template_data = ServerTemplateData ( 'etag' , template_data )
203
+ template_data_json = json . dumps ( template_data )
205
204
)
206
205
207
206
server_config = server_template .evaluate ()
@@ -262,12 +261,12 @@ def test_evaluate_return_conditional_values_honor_order(self):
262
261
},
263
262
'parameterGroups' :'' ,
264
263
'version' :'' ,
265
- 'etag' : '123 '
264
+ 'etag' : 'etag '
266
265
}
267
266
server_template = remote_config .init_server_template (
268
267
app = app ,
269
268
default_config = default_config ,
270
- template_data = ServerTemplateData ( 'etag' , template_data )
269
+ template_data_json = json . dumps ( template_data )
271
270
)
272
271
server_config = server_template .evaluate ()
273
272
assert server_config .get_string ('dog_type' ) == 'corgi'
@@ -280,7 +279,7 @@ def test_evaluate_default_when_no_param(self):
280
279
server_template = remote_config .init_server_template (
281
280
app = app ,
282
281
default_config = default_config ,
283
- template_data = ServerTemplateData ( 'etag' , template_data )
282
+ template_data_json = json . dumps ( template_data )
284
283
)
285
284
server_config = server_template .evaluate ()
286
285
assert server_config .get_boolean ('promo_enabled' ) == default_config .get ('promo_enabled' )
@@ -296,7 +295,7 @@ def test_evaluate_default_when_no_default_value(self):
296
295
server_template = remote_config .init_server_template (
297
296
app = app ,
298
297
default_config = default_config ,
299
- template_data = ServerTemplateData ( 'etag' , template_data )
298
+ template_data_json = json . dumps ( template_data )
300
299
)
301
300
server_config = server_template .evaluate ()
302
301
assert server_config .get_string ('default_value' ) == default_config .get ('default_value' )
@@ -313,7 +312,7 @@ def test_evaluate_default_when_in_default(self):
313
312
server_template = remote_config .init_server_template (
314
313
app = app ,
315
314
default_config = default_config ,
316
- template_data = ServerTemplateData ( 'etag' , template_data )
315
+ template_data_json = json . dumps ( template_data )
317
316
)
318
317
server_config = server_template .evaluate ()
319
318
assert server_config .get_string ('inapp_default' ) == default_config .get ('inapp_default' )
@@ -328,7 +327,7 @@ def test_evaluate_default_when_defined(self):
328
327
server_template = remote_config .init_server_template (
329
328
app = app ,
330
329
default_config = default_config ,
331
- template_data = ServerTemplateData ( 'etag' , template_data )
330
+ template_data_json = json . dumps ( template_data )
332
331
)
333
332
server_config = server_template .evaluate ()
334
333
assert server_config .get_string ('dog_type' ) == 'shiba'
@@ -342,7 +341,7 @@ def test_evaluate_return_numeric_value(self):
342
341
server_template = remote_config .init_server_template (
343
342
app = app ,
344
343
default_config = default_config ,
345
- template_data = ServerTemplateData ( 'etag' , template_data )
344
+ template_data_json = json . dumps ( template_data )
346
345
)
347
346
server_config = server_template .evaluate ()
348
347
assert server_config .get_int ('dog_age' ) == int (default_config .get ('dog_age' ))
@@ -356,7 +355,7 @@ def test_evaluate_return_boolean_value(self):
356
355
server_template = remote_config .init_server_template (
357
356
app = app ,
358
357
default_config = default_config ,
359
- template_data = ServerTemplateData ( 'etag' , template_data )
358
+ template_data_json = json . dumps ( template_data )
360
359
)
361
360
server_config = server_template .evaluate ()
362
361
assert server_config .get_boolean ('dog_is_cute' )
@@ -398,7 +397,7 @@ def test_evaluate_unknown_operator_to_false(self):
398
397
server_template = remote_config .init_server_template (
399
398
app = app ,
400
399
default_config = default_config ,
401
- template_data = ServerTemplateData ( 'etag' , template_data )
400
+ template_data_json = json . dumps ( template_data )
402
401
)
403
402
server_config = server_template .evaluate (context )
404
403
assert not server_config .get_boolean ('is_enabled' )
@@ -442,7 +441,7 @@ def test_evaluate_less_or_equal_to_max_to_true(self):
442
441
server_template = remote_config .init_server_template (
443
442
app = app ,
444
443
default_config = default_config ,
445
- template_data = ServerTemplateData ( 'etag' , template_data )
444
+ template_data_json = json . dumps ( template_data )
446
445
)
447
446
server_config = server_template .evaluate (context )
448
447
assert server_config .get_boolean ('is_enabled' )
@@ -485,7 +484,7 @@ def test_evaluate_undefined_micropercent_to_false(self):
485
484
server_template = remote_config .init_server_template (
486
485
app = app ,
487
486
default_config = default_config ,
488
- template_data = ServerTemplateData ( 'etag' , template_data )
487
+ template_data_json = json . dumps ( template_data )
489
488
)
490
489
server_config = server_template .evaluate (context )
491
490
assert not server_config .get_boolean ('is_enabled' )
@@ -528,7 +527,7 @@ def test_evaluate_undefined_micropercentrange_to_false(self):
528
527
server_template = remote_config .init_server_template (
529
528
app = app ,
530
529
default_config = default_config ,
531
- template_data = ServerTemplateData ( 'etag' , template_data )
530
+ template_data_json = json . dumps ( template_data )
532
531
)
533
532
server_config = server_template .evaluate (context )
534
533
assert not server_config .get_boolean ('is_enabled' )
@@ -575,7 +574,7 @@ def test_evaluate_between_min_max_to_true(self):
575
574
server_template = remote_config .init_server_template (
576
575
app = app ,
577
576
default_config = default_config ,
578
- template_data = ServerTemplateData ( 'etag' , template_data )
577
+ template_data_json = json . dumps ( template_data )
579
578
)
580
579
server_config = server_template .evaluate (context )
581
580
assert server_config .get_boolean ('is_enabled' )
@@ -622,7 +621,7 @@ def test_evaluate_between_equal_bounds_to_false(self):
622
621
server_template = remote_config .init_server_template (
623
622
app = app ,
624
623
default_config = default_config ,
625
- template_data = ServerTemplateData ( 'etag' , template_data )
624
+ template_data_json = json . dumps ( template_data )
626
625
)
627
626
server_config = server_template .evaluate (context )
628
627
assert not server_config .get_boolean ('is_enabled' )
@@ -750,7 +749,7 @@ def evaluate_random_assignments(self, condition, num_of_assignments, mock_app, d
750
749
server_template = remote_config .init_server_template (
751
750
app = mock_app ,
752
751
default_config = default_config ,
753
- template_data = ServerTemplateData ( 'etag' , template_data )
752
+ template_data_json = json . dumps ( template_data )
754
753
)
755
754
756
755
for _ in range (num_of_assignments ):
@@ -814,7 +813,7 @@ def test_evaluate_custom_signal_semantic_version(self,
814
813
server_template = remote_config .init_server_template (
815
814
app = app ,
816
815
default_config = default_config ,
817
- template_data = ServerTemplateData ( 'etag' , template_data )
816
+ template_data_json = json . dumps ( template_data )
818
817
)
819
818
server_config = server_template .evaluate (context )
820
819
assert server_config .get_boolean ('is_enabled' ) == parameter_value
@@ -917,7 +916,7 @@ def test_init_server_template(self):
917
916
template = remote_config .init_server_template (
918
917
app = app ,
919
918
default_config = {'default_test' : 'default_value' },
920
- template_data = ServerTemplateData ( 'etag' , template_data )
919
+ template_data_json = json . dumps ( template_data )
921
920
)
922
921
923
922
config = template .evaluate ()
@@ -949,3 +948,36 @@ async def test_get_server_template(self):
949
948
950
949
config = template .evaluate ()
951
950
assert config .get_string ('test_key' ) == 'test_value'
951
+
952
+ @pytest .mark .asyncio
953
+ async def test_server_template_to_json (self ):
954
+ app = firebase_admin .get_app ()
955
+ rc_instance = _utils .get_app_service (app ,
956
+ _REMOTE_CONFIG_ATTRIBUTE , _RemoteConfigService )
957
+
958
+ recorder = []
959
+ response = json .dumps ({
960
+ 'parameters' : {
961
+ 'test_key' : {
962
+ 'defaultValue' : {'value' : 'test_value' },
963
+ 'conditionalValues' : {}
964
+ }
965
+ },
966
+ 'conditions' : [],
967
+ 'version' : 'test'
968
+ })
969
+
970
+ expected_template_json = '{"parameters": {' \
971
+ '"test_key": {' \
972
+ '"defaultValue": {' \
973
+ '"value": "test_value"}, ' \
974
+ '"conditionalValues": {}}}, "conditions": [], ' \
975
+ '"version": "test", "etag": "etag"}'
976
+
977
+ rc_instance ._client .session .mount (
978
+ 'https://firebaseremoteconfig.googleapis.com' ,
979
+ MockAdapter (response , 200 , recorder ))
980
+ template = await remote_config .get_server_template (app = app )
981
+
982
+ template_json = template .to_json ()
983
+ assert template_json == expected_template_json
0 commit comments