Skip to content

Commit

Permalink
Fix no-translation-key test and report CPI validation errors as well
Browse files Browse the repository at this point in the history
  • Loading branch information
jerith committed Jan 22, 2024
1 parent fedb74a commit 0d1ee74
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
8 changes: 6 additions & 2 deletions home/import_content_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,12 @@ def create_content_page_index_from_row(self, row: "ContentRow") -> None:
if row.translation_tag or locale != self.default_locale():
index.translation_key = row.translation_tag
locale = self.locale_from_display_name(row.locale)
with contextlib.suppress(NodeAlreadySaved):
self.home_page(locale).add_child(instance=index)
try:
with contextlib.suppress(NodeAlreadySaved):
self.home_page(locale).add_child(instance=index)
except ValidationError as err:
# FIXME: Find a better way to represent this.
raise ImportException(f"Validation error: {err}")

index.save_revision().publish()

Expand Down
15 changes: 12 additions & 3 deletions home/tests/test_content_import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import pytest
from django.core import serializers # type: ignore
from django.core.exceptions import ValidationError # type: ignore
from django.core.files.images import ImageFile # type: ignore
from openpyxl import load_workbook
from pytest_django.fixtures import SettingsWrapper
Expand Down Expand Up @@ -821,13 +820,23 @@ def test_no_translation_key_nondefault(self, newcsv_impexp: ImportExport) -> Non
HomePage.add_root(locale=pt, title="Home (pt)", slug="home-pt")

# A ContentPageIndex without a translation key fails
with pytest.raises(ValidationError):
with pytest.raises(ImportException) as e:
newcsv_impexp.import_file("no-translation-key-cpi.csv")

assert e.value.row_num == 4
# FIXME: Find a better way to represent this.
assert "translation_key" in e.value.message
assert "“” is not a valid UUID." in e.value.message

# A ContentPage without a translation key fails
with pytest.raises(ValidationError):
with pytest.raises(ImportException) as e:
newcsv_impexp.import_file("no-translation-key-cp.csv")

assert e.value.row_num == 5
# FIXME: Find a better way to represent this.
assert "translation_key" in e.value.message
assert "“” is not a valid UUID." in e.value.message

def test_invalid_locale_name(self, newcsv_impexp: ImportExport) -> None:
"""
Importing pages with invalid locale names should raise an error that results
Expand Down

0 comments on commit 0d1ee74

Please sign in to comment.