|
| 1 | +import json |
1 | 2 | import firebase_admin |
2 | 3 | from firebase_admin import credentials |
3 | 4 | from firebase_admin import remote_config |
4 | 5 | import asyncio |
5 | 6 |
|
6 | 7 | # Evaluate the template and manually assert the config |
7 | 8 | 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 |
11 | 10 | # signals cause changes to the config evaluation. |
12 | 11 | config = template.evaluate( |
13 | 12 | # Update custom vars |
14 | 13 | { |
15 | | - 'custom_key_str': 'custom_val_str', |
16 | | - 'version_key': '12.1.3.-1' |
| 14 | + 'randomization_id': 'random', |
| 15 | + 'custom_str': 'custom_val' |
17 | 16 | } |
18 | 17 | ) |
19 | 18 |
|
20 | | - # [Bug Bash 101] Verify Evaluation |
21 | | - # Update the following print statements to verify if config is being created properly. |
22 | 19 | # 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')) |
25 | 21 |
|
26 | 22 | # 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')) |
28 | 24 |
|
29 | 25 | # 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')) |
31 | 27 |
|
32 | 28 | print('----------------') |
33 | 29 |
|
| 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 | + |
34 | 54 | def bug_bash(): |
35 | | - # [Bug Bash 101] Credentials |
36 | 55 | # Load creds for authentication - Update the json key from the one downloaded from the console. |
37 | 56 | cred = credentials.Certificate('credentials.json') |
38 | 57 | default_app = firebase_admin.initialize_app(cred) |
39 | 58 |
|
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 |
44 | 60 | 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' |
47 | 63 | } |
48 | 64 |
|
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) |
51 | 66 |
|
52 | | - # Load the template from the backend |
53 | | - asyncio.run(template.load()) |
| 67 | + template = initializeTempalteFromLocalStorage(default_app,default_config) |
54 | 68 |
|
| 69 | + # Evaluate Template |
55 | 70 | 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) |
62 | 71 |
|
63 | | - test_evaluations(template_v2) |
64 | | - |
65 | 72 | bug_bash() |
66 | 73 |
|
67 | 74 |
|
|
0 commit comments