From f7e18cfc527a135f73380f638195f943cce0819a Mon Sep 17 00:00:00 2001 From: yashlamba Date: Mon, 19 Feb 2024 16:39:10 +0100 Subject: [PATCH] tests: add tests for filter_dict_keys --- tests/test_dictutils.py | 21 ++++++++++++++++++++- tests/test_resolver.py | 6 +++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/tests/test_dictutils.py b/tests/test_dictutils.py index 7e7c8ab6..c276e902 100644 --- a/tests/test_dictutils.py +++ b/tests/test_dictutils.py @@ -12,7 +12,12 @@ import pytest -from invenio_records.dictutils import clear_none, dict_lookup, dict_merge +from invenio_records.dictutils import ( + clear_none, + dict_lookup, + dict_merge, + filter_dict_keys, +) def test_clear_none(): @@ -78,3 +83,17 @@ def test_dict_merge(): "foo2": "bar2", "metadata": {"field1": 3, "field2": "test"}, } + + +def test_filter_dict_keys(): + """Test filter dict keys.""" + source = { + "foo1": {"bar1": 1, "bar2": 2}, + "foo2": 1, + "foo3": {"bar1": {"foo4": 0}, "bar2": 1, "bar3": 2}, + "foo4": {}, + } + + assert filter_dict_keys( + source, ["foo1.bar1", "foo2", "foo3.bar1.foo4", "foo3.bar3"] + ) == {"foo1": {"bar1": 1}, "foo2": 1, "foo3": {"bar1": {"foo4": 0}, "bar3": 2}} diff --git a/tests/test_resolver.py b/tests/test_resolver.py index 2f1d61ba..be2df9d4 100644 --- a/tests/test_resolver.py +++ b/tests/test_resolver.py @@ -41,9 +41,9 @@ def local_ref_resolver_store_factory(): @pytest.fixture(scope="module") def app_config(app_config): - app_config[ - "RECORDS_REFRESOLVER_CLS" - ] = "invenio_records.resolver.InvenioRefResolver" + app_config["RECORDS_REFRESOLVER_CLS"] = ( + "invenio_records.resolver.InvenioRefResolver" + ) app_config["RECORDS_REFRESOLVER_STORE"] = local_ref_resolver_store_factory() return app_config