inveniosoftware / invenio-vocabularies

Invenio module for managing vocabularies.
https://invenio-vocabularies.readthedocs.io
MIT License
2 stars 42 forks source link

mappings: add dynamic template for i18n titles and descriptions #247

Closed ppanero closed 1 year ago

ppanero commented 1 year ago
ppanero commented 1 year ago

@slint unfortunately there is nothing like that at the moment. I could add it, but that is extra work that I'm not sure it fits on the current sprint. At the moment we are testing this indirectly, if you pass a normal string here https://github.com/inveniosoftware/invenio-vocabularies/blob/25ba54bbaee5fd89794067b2c34c6bea20e7fc16/tests/conftest.py#L134 it should fail. I could may do that test, but it feels ad-hoc (note that we have this type of dynamic templates also in rdm-records)

slint commented 1 year ago

Fine with me, was curious because ES mapping errors/mismatches are usually going under the radar, but if there's code that works with the functionality it should be good :)

ppanero commented 1 year ago

@slint sample run:

Normal run

@pytest.fixture(scope="module")
def example_data():
    """Example data for records."""
    return {
    ...
        },
        "description": {
            "en": "Publications",
            "da": "Publikationer",
        },
    ...
    }

tests/resources/test_resources_l10n.py::test_get PASSED

Not a dict, this would fail even without dynamic template. The check is dict vs no dict.

@pytest.fixture(scope="module")
def example_data():
    """Example data for records."""
    return {
        ...
        "description": "Publications",
        ...
    }

ERROR tests/resources/test_resources_l10n.py::test_get - marshmallow.exceptions.ValidationError: {'description': ['Not a valid mapping type.']}

Not a string, this is enforced by the template. However, we can only check that is a string we cannot check that is indexed as search_as_you_type

@pytest.fixture(scope="module")
def example_data():
    """Example data for records."""
    return {
        ...
        "description": {
            "en": 123,
        },
        ...
    }

ERROR tests/resources/test_resources_l10n.py::test_get - marshmallow.exceptions.ValidationError: {'description': defaultdict(<class 'dict'>, {'en': {'value': ['Not a valid string.']}})}