summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorPatrick Cloke <clokep@users.noreply.github.com>2023-02-03 11:48:13 -0500
committerGitHub <noreply@github.com>2023-02-03 16:48:13 +0000
commitf0cae26d58f6f907236112be5f4eaecc376b1304 (patch)
treec2ab46d8e743b262e186fc661571d922ad34759c /tests
parentSupport the backwards compatibility features in MSC3952. (#14958) (diff)
downloadsynapse-f0cae26d58f6f907236112be5f4eaecc376b1304.tar.xz
Add a docstring & tests for _flatten_dict. (#14981)
Diffstat (limited to 'tests')
-rw-r--r--tests/push/test_push_rule_evaluator.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/tests/push/test_push_rule_evaluator.py b/tests/push/test_push_rule_evaluator.py
index 81661e181b..7c430c4ecb 100644
--- a/tests/push/test_push_rule_evaluator.py
+++ b/tests/push/test_push_rule_evaluator.py
@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Dict, List, Optional, Set, Union, cast
+from typing import Any, Dict, List, Optional, Set, Union, cast
 
 import frozendict
 
@@ -37,6 +37,30 @@ from tests import unittest
 from tests.test_utils.event_injection import create_event, inject_member_event
 
 
+class FlattenDictTestCase(unittest.TestCase):
+    def test_simple(self) -> None:
+        """Test a dictionary that isn't modified."""
+        input = {"foo": "abc"}
+        self.assertEqual(input, _flatten_dict(input))
+
+    def test_nested(self) -> None:
+        """Nested dictionaries become dotted paths."""
+        input = {"foo": {"bar": "abc"}}
+        self.assertEqual({"foo.bar": "abc"}, _flatten_dict(input))
+
+    def test_non_string(self) -> None:
+        """Non-string items are dropped."""
+        input: Dict[str, Any] = {
+            "woo": "woo",
+            "foo": True,
+            "bar": 1,
+            "baz": None,
+            "fuzz": [],
+            "boo": {},
+        }
+        self.assertEqual({"woo": "woo"}, _flatten_dict(input))
+
+
 class PushRuleEvaluatorTestCase(unittest.TestCase):
     def _get_evaluator(
         self,