|
15 | 15 | Internal utils tests.
|
16 | 16 | """
|
17 | 17 | from os import environ, path
|
18 |
| -from firebase_functions.private.util import firebase_config, microsecond_timestamp_conversion, nanoseconds_timestamp_conversion, is_precision_timestamp, normalize_path |
| 18 | +from firebase_functions.private.util import firebase_config, microsecond_timestamp_conversion, nanoseconds_timestamp_conversion, is_precision_timestamp, normalize_path, deep_merge |
19 | 19 | import datetime as _dt
|
20 | 20 |
|
21 | 21 | test_bucket = "python-functions-testing.appspot.com"
|
@@ -121,3 +121,27 @@ def test_normalize_document_path():
|
121 | 121 | test_path2 = "test/document"
|
122 | 122 | assert normalize_path(test_path2) == "test/document", (
|
123 | 123 | "Failure, path should not be changed if it is already normalized.")
|
| 124 | + |
| 125 | + |
| 126 | +def test_toplevel_keys(): |
| 127 | + dict1 = {'baz': {'answer': 42, 'qux': 'quux'}, 'foo': 'bar'} |
| 128 | + dict2 = {'baz': {'answer': 33}} |
| 129 | + result = deep_merge(dict1, dict2) |
| 130 | + assert 'foo' in result |
| 131 | + assert 'baz' in result |
| 132 | + |
| 133 | + |
| 134 | +def test_nested_merge(): |
| 135 | + dict1 = {'baz': {'answer': 42, 'qux': 'quux'}, 'foo': 'bar'} |
| 136 | + dict2 = {'baz': {'answer': 33}} |
| 137 | + result = deep_merge(dict1, dict2) |
| 138 | + assert result['baz']['answer'] == 33 |
| 139 | + assert result['baz']['qux'] == 'quux' |
| 140 | + |
| 141 | + |
| 142 | +def test_does_not_modify_originals(): |
| 143 | + dict1 = {'baz': {'answer': 42, 'qux': 'quux'}, 'foo': 'bar'} |
| 144 | + dict2 = {'baz': {'answer': 33}} |
| 145 | + deep_merge(dict1, dict2) |
| 146 | + assert dict1['baz']['answer'] == 42 |
| 147 | + assert dict2['baz']['answer'] == 33 |
0 commit comments