Skip to content

Commit d82eda5

Browse files
author
Pijush Chakraborty
committed
Updating bug-bash script
1 parent 049de23 commit d82eda5

File tree

1 file changed

+37
-30
lines changed

1 file changed

+37
-30
lines changed

bug-bash.py

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,74 @@
1+
import json
12
import firebase_admin
23
from firebase_admin import credentials
34
from firebase_admin import remote_config
45
import asyncio
56

67
# Evaluate the template and manually assert the config
78
def test_evaluations(template):
8-
# [Bug Bash 101] Custom Signals
9-
# Evaluate template - pass custom signals
10-
# Update the custom signals being passed in evaluate to test how variations of the
9+
# Custom Signals
1110
# signals cause changes to the config evaluation.
1211
config = template.evaluate(
1312
# Update custom vars
1413
{
15-
'custom_key_str': 'custom_val_str',
16-
'version_key': '12.1.3.-1'
14+
'randomization_id': 'random',
15+
'custom_str': 'custom_val'
1716
}
1817
)
1918

20-
# [Bug Bash 101] Verify Evaluation
21-
# Update the following print statements to verify if config is being created properly.
2219
# Print default config values
23-
print('[Default Config] default_key_str: ', config.get_string('default_key_str'))
24-
print('[Default Config] default_key_number: ', config.get_int('default_key_number'))
20+
print('[Default Config] default_key_str: ', config.get_string('rc_test_y'))
2521

2622
# Verify evaluated config
27-
print('[Evluated Config] Config values:', config.get_string('rc_testx'))
23+
print('[Evluated Config] Config values:', config.get_string('rc_test_x'))
2824

2925
# Verify value and source for configs
30-
print('Value Source:', config.get_value_source('test_server'))
26+
print('Value Source:', config.get_value_source('rc_test_x'))
3127

3228
print('----------------')
3329

30+
def fetchServerTemplateAndStoreTemplate(default_app, default_config):
31+
# Create initial template
32+
template = remote_config.init_server_template(app=default_app, default_config=default_config)
33+
34+
# Load the template from the backend
35+
asyncio.run(template.load())
36+
37+
template_json = template.to_json()
38+
39+
f = open("template.json", "w")
40+
json.dump(template_json,f)
41+
f.close()
42+
43+
return template
44+
45+
def initializeTempalteFromLocalStorage(default_app, default_config):
46+
# Verify template initialization from saved JSON
47+
f = open("template.json", "r")
48+
template_json = json.load(f)
49+
return remote_config.init_server_template(app=default_app,
50+
default_config=default_config,
51+
template_data_json=template_json)
52+
53+
3454
def bug_bash():
35-
# [Bug Bash 101] Credentials
3655
# Load creds for authentication - Update the json key from the one downloaded from the console.
3756
cred = credentials.Certificate('credentials.json')
3857
default_app = firebase_admin.initialize_app(cred)
3958

40-
# [Bug Bash 101] Default Config
41-
# Create default template for initializing ServerTemplate
42-
# For bug bash, update the default config to any config that you want to initialize
43-
# the app with. The configs will be cached and might get updated during evaluation of the template.
59+
# Default config with default values used to initialize template
4460
default_config = {
45-
'rc_test_3': 'default_val_str',
46-
'rc_testx': 'val_str'
61+
'rc_test_x': 'rc_default_x',
62+
'rc_test_y': 'rc_default_y'
4763
}
4864

49-
# Create initial template
50-
template = remote_config.init_server_template(app=default_app, default_config=default_config)
65+
# template = fetchServerTemplateAndStoreTemplate(default_app,default_config)
5166

52-
# Load the template from the backend
53-
asyncio.run(template.load())
67+
template = initializeTempalteFromLocalStorage(default_app,default_config)
5468

69+
# Evaluate Template
5570
test_evaluations(template)
56-
57-
# Verify template initialization from saved JSON
58-
template_json = template.to_json()
59-
template_v2 = remote_config.init_server_template(app=default_app,
60-
default_config=default_config,
61-
template_data_json=template_json)
6271

63-
test_evaluations(template_v2)
64-
6572
bug_bash()
6673

6774

0 commit comments

Comments
 (0)