Skip to content

Commit

Permalink
Merge branch 'main' into add-length-validation-on-interactive-message
Browse files Browse the repository at this point in the history
  • Loading branch information
Hlamallama committed Feb 26, 2025
2 parents 823548d + aefe90e commit 2f34d27
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[run]
omit = */tests/*
relative_files = true
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@ jobs:
if: success() || failure() && steps.install-deps.outcome == 'success'
run: |
poetry run pytest -vv
- name: Coverage comment
id: coverage_comment
uses: py-cov-action/python-coverage-comment-action@v3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Helper texts for some ordered content sets
- CMS Forms Flexible imports and Better Error Handling
- Contentpage warnings for media_link field
- Test coverage report
- Changed Assessments to CMS Forms
- Validation for high_inflection, medium_inflection and score field on CMS Forms
- Validation for interactive messages
Expand Down
7 changes: 7 additions & 0 deletions home/import_ordered_content_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ def _add_pages(
f"Content page not found for slug '{page.page_slug}' in locale '{locale}'",
index,
)
if (not page.page_slug or page.page_slug == "-") and (
page.time or page.unit or page.before_or_after or page.contact_field
):
raise ImportException(
"You are attempting to import an ordered content set with page details, but no page slug.",
index,
)

# FIXME: collect errors across all fields
def _validate_ordered_set_using_form(
Expand Down
2 changes: 2 additions & 0 deletions home/tests/import-export-data/bad_ordered_set.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Name,Profile Fields,Page Slugs,Time,Unit,Before Or After,Contact Field,Slug,Locale
Ordered,,,12,minutes,before,,Slug,en
2 changes: 2 additions & 0 deletions home/tests/import-export-data/simple_ordered_set.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Name,Profile Fields,Page Slugs,Time,Unit,Before Or After,Contact Field,Slug,Locale
Ordered,,,,,,,Slug,en
33 changes: 33 additions & 0 deletions home/tests/test_content_import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,23 @@ def test_import_ordered_content_sets_no_page_error(
"Content page not found for slug 'first_time_user' in locale 'English'"
]

def test_import_ordered_content_sets_missing_slug(
self, csv_impexp: ImportExport
) -> None:
"""
Importing CSV for ordered content sets that has a page slug, but no
Unit/Time/EDD/Before_or_After/Contact field, should result in a
error message
"""
with pytest.raises(ImportException) as e:
content = csv_impexp.read_bytes("bad_ordered_set.csv")
csv_impexp.import_ordered_sets(content)

assert e.value.row_num == 2
assert e.value.message == [
"You are attempting to import an ordered content set with page details, but no page slug."
]

def test_import_ordered_content_sets_no_locale_error(
self, csv_impexp: ImportExport
) -> None:
Expand Down Expand Up @@ -1425,6 +1442,22 @@ def test_import_ordered_content_sets_duplicate_slug(
page = pages[0][1]
assert page["contentpage"].slug == "first_time_user"

def test_import_simple_ordered_sets_csv(self, csv_impexp: ImportExport) -> None:
"""
Importing a CSV file with ordered content sets without any contentpage should not break
"""

content = csv_impexp.read_bytes("simple_ordered_set.csv")
csv_impexp.import_ordered_sets(content)

en = Locale.objects.get(language_code="en")

ordered_set = OrderedContentSet.objects.filter(slug="slug", locale=en).first()

assert ordered_set.name == "Ordered"
pages = unwagtail(ordered_set.pages)
assert len(pages) == 0

def test_import_ordered_sets_csv(self, csv_impexp: ImportExport) -> None:
"""
Importing a CSV file with ordered content sets should not break
Expand Down

0 comments on commit 2f34d27

Please sign in to comment.