Skip to content

Commit

Permalink
extract search related test from quality matrix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MRuecklCC committed Aug 26, 2022
1 parent 85c6e9e commit 504f51c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/app/elastic/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from elasticsearch_dsl.response import Response

from app.core.config import ELASTIC_INDEX
from app.core.constants import OER_LICENSES
from app.core.logging import logger
from app.elastic.attributes import ElasticResourceAttribute
from app.elastic.dsl import qterm
Expand Down Expand Up @@ -190,7 +191,7 @@ def __init__(self, index=ELASTIC_INDEX, **kwargs):

def oer_filter(self) -> MaterialSearch:
"""Return a new search with an added filter to only return OER materials."""
return self.filter(Terms(**{ElasticResourceAttribute.LICENSES.keyword: ["CC_0", "PDM", "CC_BY", "CC_BY_SA"]}))
return self.filter(Terms(**{ElasticResourceAttribute.LICENSES.keyword: OER_LICENSES}))

def collection_filter(self, collection_id: UUID, transitive: bool) -> MaterialSearch:
"""
Expand Down
16 changes: 0 additions & 16 deletions tests/quality_matrix/test_quality_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,22 +209,6 @@ def test_create_properties_search():
assert create_properties_search().to_dict() == expected_search


def test_add_base_match_filters():
excpectation = {
"query": {
"bool": {
"filter": [
{"term": {"permissions.Read.keyword": "GROUP_EVERYONE"}},
{"term": {"properties.cm:edu_metadataset.keyword": "mds_oeh"}},
{"term": {"nodeRef.storeRef.protocol": "workspace"}},
]
}
}
}

assert Search().base_filters().to_dict() == excpectation


def test_missing_fields_zero_division_error():
with pytest.raises(ZeroDivisionError):
missing_fields({"doc_count": 0}, 0, "dummy_source")
Expand Down
18 changes: 18 additions & 0 deletions tests/test_elastic_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from app.elastic.search import MaterialSearch


def test_material_search():
excpectation = {
"query": {
"bool": {
"filter": [
{"term": {"permissions.Read.keyword": "GROUP_EVERYONE"}},
{"term": {"properties.cm:edu_metadataset.keyword": "mds_oeh"}},
{"term": {"nodeRef.storeRef.protocol": "workspace"}},
{"term": {"type": "ccm:io"}},
]
}
}
}

assert MaterialSearch().to_dict() == excpectation

0 comments on commit 504f51c

Please sign in to comment.