From b30417a2f7ddac2067daf1e5d5fffda27d35592e Mon Sep 17 00:00:00 2001 From: Robert Meissner Date: Mon, 18 Jul 2022 15:10:05 +0200 Subject: [PATCH] KBMBF-452: #37 Show ratio of oer-content WIP: Fixing license --- src/app/api/collections/missing_materials.py | 22 +++++++++---------- .../unit_tests/crud/test_missing_materials.py | 14 ++++++++++-- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/app/api/collections/missing_materials.py b/src/app/api/collections/missing_materials.py index 42d9249..bcf1057 100644 --- a/src/app/api/collections/missing_materials.py +++ b/src/app/api/collections/missing_materials.py @@ -207,26 +207,26 @@ def missing_attributes_search( ) -> Search: missing_attribute_filter = {"filter": type_filter[ResourceType.MATERIAL]} + should_filter = { + "should": [ + qmatch(**{"collections.path": node_id}), + qmatch(**{"collections.nodeRef.id": node_id}), + ] + } if missing_attribute == LearningMaterialAttribute.LICENSES.path: license_query = query_missing_material_license().to_dict()["bool"] - missing_attribute_filter.update(**license_query) - + should_filter["should"] += [Q(query) for query in license_query["should"]] + license_query.pop("should") query = { "minimum_should_match": 1, - "should": [ - qmatch(**{"path": node_id}), - qmatch(**{"nodeRef.id": node_id}), - query_missing_material_license(), - ], + **should_filter, **license_query, + **missing_attribute_filter, } else: query = { "minimum_should_match": 1, - "should": [ - qmatch(**{"collections.path": node_id}), - qmatch(**{"collections.nodeRef.id": node_id}), - ], + **should_filter, "must_not": Q("wildcard", **{missing_attribute: {"value": "*"}}), **missing_attribute_filter, } diff --git a/tests/unit_tests/crud/test_missing_materials.py b/tests/unit_tests/crud/test_missing_materials.py index 9718986..c99368d 100644 --- a/tests/unit_tests/crud/test_missing_materials.py +++ b/tests/unit_tests/crud/test_missing_materials.py @@ -57,7 +57,7 @@ def test_missing_materials_search(): def test_missing_materials_search_license(): dummy_uuid = uuid.uuid4() - dummy_attribute = "properties.commonlicense_key" + dummy_attribute = "properties.ccm:commonlicense_key" dummy_missing_attribute = missing_attribute_filter[4].value dummy_maximum_size = 3 search = missing_attributes_search( @@ -77,9 +77,19 @@ def test_missing_materials_search_license(): "should": [ {"match": {"collections.path": dummy_uuid}}, {"match": {"collections.nodeRef.id": dummy_uuid}}, + { + "terms": { + dummy_attribute + + ".keyword": [ + "UNTERRICHTS_UND_LEHRMEDIEN", + "NONE", + "", + ] + } + }, + {"bool": {"must_not": [{"exists": {"field": dummy_attribute}}]}}, ], "minimum_should_match": 1, - "must_not": [{"wildcard": {dummy_attribute: {"value": "*"}}}], } }, "from": 0,