Repository navigation
fix(remoteconfig): compare custom signals whose value is 0 or empty; don't build values from a missing parameter value #994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
70354c1
8c46293
e8bdac4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -301,6 +301,40 @@ def test_evaluate_default_when_no_default_value(self): | |||||
| server_config = server_template.evaluate() | ||||||
| assert server_config.get_string('default_value') == default_config.get('default_value') | ||||||
|
|
||||||
| def test_evaluate_conditional_value_without_explicit_value(self): | ||||||
| app = firebase_admin.get_app() | ||||||
| default_config = {'dog_type': 'shiba'} | ||||||
| template_data = SERVER_REMOTE_CONFIG_RESPONSE | ||||||
| template_data['conditions'] = [{'name': 'is_true', 'condition': {'true': {}}}] | ||||||
| template_data['parameters'] = { | ||||||
| 'dog_type': { | ||||||
| 'conditionalValues': {'is_true': {'useInAppDefault': False}} | ||||||
| } | ||||||
| } | ||||||
| server_template = remote_config.init_server_template( | ||||||
| app=app, | ||||||
| default_config=default_config, | ||||||
| template_data_json=json.dumps(template_data) | ||||||
| ) | ||||||
| server_config = server_template.evaluate() | ||||||
| assert server_config.get_string('dog_type') == default_config.get('dog_type') | ||||||
|
|
||||||
| def test_evaluate_default_value_without_explicit_value(self): | ||||||
| app = firebase_admin.get_app() | ||||||
| default_config = {'dog_type': 'shiba'} | ||||||
| template_data = SERVER_REMOTE_CONFIG_RESPONSE | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assigning
Suggested change
|
||||||
| template_data['parameters'] = { | ||||||
| 'dog_type': {'defaultValue': {'useInAppDefault': False}} | ||||||
| } | ||||||
| server_template = remote_config.init_server_template( | ||||||
| app=app, | ||||||
| default_config=default_config, | ||||||
| template_data_json=json.dumps(template_data) | ||||||
| ) | ||||||
| server_config = server_template.evaluate() | ||||||
| assert server_config.get_string('dog_type') == '' | ||||||
| assert server_config.get_int('dog_type') == 0 | ||||||
|
|
||||||
| def test_evaluate_default_when_in_default(self): | ||||||
| app = firebase_admin.get_app() | ||||||
| template_data = SERVER_REMOTE_CONFIG_RESPONSE | ||||||
|
|
@@ -819,6 +853,58 @@ def test_evaluate_custom_signal_semantic_version(self, | |||||
| server_config = server_template.evaluate(context) | ||||||
| assert server_config.get_boolean('is_enabled') == parameter_value | ||||||
|
|
||||||
| @pytest.mark.parametrize( | ||||||
| 'custom_signal_operator, target_custom_signal_values, context_value', | ||||||
| [ | ||||||
| (CustomSignalOperator.STRING_CONTAINS.value, ['0'], 0), | ||||||
| (CustomSignalOperator.NUMERIC_EQUAL.value, ['0'], 0), | ||||||
| (CustomSignalOperator.NUMERIC_GREATER_EQUAL.value, ['0'], 0), | ||||||
| (CustomSignalOperator.SEMANTIC_VERSION_EQUAL.value, ['0.0.0'], 0), | ||||||
| (CustomSignalOperator.STRING_EXACTLY_MATCHES.value, [''], ''), | ||||||
| ]) | ||||||
| def test_evaluate_custom_signal_with_falsy_value(self, | ||||||
| custom_signal_operator, | ||||||
| target_custom_signal_values, | ||||||
| context_value): | ||||||
| app = firebase_admin.get_app() | ||||||
| condition = { | ||||||
| 'name': 'is_true', | ||||||
| 'condition': { | ||||||
| 'orCondition': { | ||||||
| 'conditions': [{ | ||||||
| 'andCondition': { | ||||||
| 'conditions': [{ | ||||||
| 'customSignal': { | ||||||
| 'customSignalOperator': custom_signal_operator, | ||||||
| 'customSignalKey': 'signal_key', | ||||||
| 'targetCustomSignalValues': target_custom_signal_values | ||||||
| } | ||||||
| }], | ||||||
| } | ||||||
| }] | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| template_data = { | ||||||
| 'conditions': [condition], | ||||||
| 'parameters': { | ||||||
| 'is_enabled': { | ||||||
| 'defaultValue': {'value': 'false'}, | ||||||
| 'conditionalValues': {'is_true': {'value': 'true'}} | ||||||
| }, | ||||||
| }, | ||||||
| 'parameterGroups': '', | ||||||
| 'version': '', | ||||||
| 'etag': '123' | ||||||
| } | ||||||
| server_template = remote_config.init_server_template( | ||||||
| app=app, | ||||||
| default_config={}, | ||||||
| template_data_json=json.dumps(template_data) | ||||||
| ) | ||||||
| server_config = server_template.evaluate({'signal_key': context_value}) | ||||||
| assert server_config.get_boolean('is_enabled') | ||||||
|
|
||||||
|
|
||||||
| class MockAdapter(testutils.MockAdapter): | ||||||
| """A Mock HTTP Adapter that provides Firebase Remote Config responses with ETag in header.""" | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assigning
SERVER_REMOTE_CONFIG_RESPONSEdirectly totemplate_dataand then modifying its keys (liketemplate_data['conditions']andtemplate_data['parameters']) mutates the global shared dictionarySERVER_REMOTE_CONFIG_RESPONSE. This can lead to test pollution and flaky tests because subsequent tests will receive the mutated dictionary. Use.copy()to create a shallow copy of the dictionary before modifying it.