Skip to content

Commit

Permalink
test: fix some tests and remove deprecated option
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgarel committed Aug 27, 2024
1 parent bb49c82 commit 91a0929
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 92 deletions.
10 changes: 0 additions & 10 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,16 +361,6 @@ class FieldConfig(BaseModel):
)
),
] = None
add_taxonomy_synonyms: Annotated[
bool,
Field(
description=cd_(
"""if True, add all synonyms of the taxonomy values to the index.
The flag is ignored if the field type is not `taxonomy`.
"""
)
),
] = True

@model_validator(mode="after")
def bucket_agg_should_be_used_for_keyword_and_numeric_types_only(self):
Expand Down
13 changes: 1 addition & 12 deletions tests/unit/test__import.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,19 +325,8 @@ def test_gen_documents(default_config):
assert isinstance(last_indexed_datetime, str)
assert datetime.datetime.fromisoformat(last_indexed_datetime) > start_datetime
assert "categories" in document["_source"]
categories = {
lang: set(names)
for lang, names in document["_source"].pop("categories").items()
}
assert categories == {
"de": {"Getränke"},
"en": {"Beverages", "Drinks"},
"es": {"Bebidas"},
"fr": {"Boissons"},
"it": {"Bevande"},
"nl": {"Drank", "Dranken"},
}
assert document["_source"] == {
"categories": ["en:beverages"],
"categories_tags": ["en:beverages"],
"code": ids[i],
}
Expand Down
87 changes: 17 additions & 70 deletions tests/unit/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"pt-BR": "pt-BR",
"pt": "pt-PT",
"main": "MAIN",
"other": ["VN", "ID"],
},
),
# Same, but without main language
Expand All @@ -49,17 +48,15 @@ def test_process_text_lang_field(data, input_field, split, expected):
lang_separator = "_"
split_separator = ","
supported_langs = {"fr", "it", "pt-BR", "pt"}
assert (
process_text_lang_field(
data=data,
input_field=input_field,
split=split,
lang_separator=lang_separator,
split_separator=split_separator,
supported_langs=supported_langs,
)
== expected
result = process_text_lang_field(
data=data,
input_field=input_field,
split=split,
lang_separator=lang_separator,
split_separator=split_separator,
supported_langs=supported_langs,
)
assert result == expected


taxonomy_config = TaxonomyConfig(
Expand All @@ -75,7 +72,7 @@ def test_process_text_lang_field(data, input_field, split, expected):


@pytest.mark.parametrize(
"data, field, taxonomy_config, taxonomy_langs, expected",
"data, field, taxonomy_config, expected",
[
(
{
Expand All @@ -90,60 +87,15 @@ def test_process_text_lang_field(data, input_field, split, expected):
name="categories",
input_field="categories_tags",
split=True,
add_taxonomy_synonyms=True,
taxonomy_name="category",
),
taxonomy_config,
{"en"},
{
"fr": [
"Boissons",
"alcool",
"alcools",
"boisson alcoolisée",
"Boissons alcoolisées",
"Edamame",
],
"it": ["Bevande", "Bevande alcoliche", "Edamame"],
"en": [
"Drinks",
"Beverages",
"Alcoholic beverages",
"drinks with alcohol",
"alcohols",
"Alcoholic drinks",
"Edamame",
],
"original": "Boissons,Boissons alcoolisées,Edamame",
},
),
# Same, but without synonyms
(
{
"taxonomy_langs": ["fr", "it"],
"categories_tags": "en:beverages,en:alcoholic-beverages",
},
FieldConfig(
type=FieldType.taxonomy,
name="categories",
input_field="categories_tags",
split=True,
add_taxonomy_synonyms=False,
taxonomy_name="category",
),
taxonomy_config,
{"en"},
{
"fr": [
"Boissons",
"Boissons alcoolisées",
],
"it": ["Bevande", "Bevande alcoliche"],
"en": [
"Beverages",
"Alcoholic beverages",
],
},
[
"en:beverages",
"en:alcoholic-beverages",
"en:not-in-taxonomy",
"en:edamame",
],
),
# The field is missing here, we should return None
(
Expand All @@ -153,28 +105,23 @@ def test_process_text_lang_field(data, input_field, split, expected):
name="categories",
input_field="categories_tags",
split=True,
add_taxonomy_synonyms=False,
taxonomy_name="category",
),
taxonomy_config,
{"en"},
None,
),
],
)
def test_process_taxonomy_field(data, field, taxonomy_config, taxonomy_langs, expected):
def test_process_taxonomy_field(data, field, taxonomy_config, expected):
split_separator = ","
output = process_taxonomy_field(
data=data,
field=field,
taxonomy_config=taxonomy_config,
split_separator=split_separator,
taxonomy_langs=taxonomy_langs,
)

if expected is None:
assert output is None
else:
assert set(output.keys()) == set(expected.keys())
for key in expected.keys():
assert set(output[key]) == set(expected[key])
assert set(output) == set(expected)
2 changes: 2 additions & 0 deletions tests/unit/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@ def load_elasticsearch_query_result(id_: str):
],
)
def test_build_search_query(
# parameters
id_: str,
q: str,
langs: set[str],
size: int,
page: int,
sort_by: str | None,
facets: list[str] | None,
# fixtures
update_results: bool,
default_config: IndexConfig,
default_filter_query_builder: FullTextQueryBuilder,
Expand Down

0 comments on commit 91a0929

Please sign in to comment.