Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some tests for ordered sets to verify that they are unique by slug & locale #389

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions home/tests/import-export-data/ordered_content_same_name.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Name,Profile Fields,Page Slugs,Time,Unit,Before Or After,Contact Field,Slug,Locale
Test Set,"gender:male, relationship:in_a_relationship","first_time_user, first_time_user, first_time_user","2, 3, 4","days, months, years","before, before, after",edd,Test_Set,en
Test Set,"gender:male, relationship:in_a_relationship",first_time_user,2,days,before,edd,test_set_2,en
3 changes: 3 additions & 0 deletions home/tests/import-export-data/ordered_content_same_slug.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Name,Profile Fields,Page Slugs,Time,Unit,Before Or After,Contact Field,Slug,Locale
Test Set,"gender:male, relationship:in_a_relationship","first_time_user, first_time_user, first_time_user","2, 3, 4","days, months, years","before, before, after",edd,Test_Set,en
Test Set,"gender:male, relationship:in_a_relationship",first_time_user,2,days,before,edd,test_set,en
45 changes: 45 additions & 0 deletions home/tests/test_content_import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,51 @@ def test_import_ordered_content_sets_incorrect_locale_error(

assert e.value.message == ["Locale pt does not exist."]

def test_import_ordered_content_sets_duplicate_name(
self, csv_impexp: ImportExport
) -> None:
"""
Importing CSV for ordered content sets with a duplicate name but unique slugs
should not throw an error.
"""
csv_impexp.import_file("contentpage_required_fields.csv")

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

ordered_sets = OrderedContentSet.objects.all()
assert len(ordered_sets) == 2

def test_import_ordered_content_sets_duplicate_slug(
self, csv_impexp: ImportExport
) -> None:
"""
Importing CSV for ordered content sets with a duplicate name but unique slugs
should not throw an error.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here we have duplicate names and slugs, and it seems like the action is to only choose one of them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I would expect the last one in the file to take effect because we don't do a full file scan up front to see if there are duplicates in the file.

If we only had non-unique names and 2 sets with the same name then it's anyone's guess which one would be updated.

I'll update the comment.

"""
csv_impexp.import_file("contentpage_required_fields.csv")

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

ordered_sets = OrderedContentSet.objects.all()
assert len(ordered_sets) == 1

ordered_set = ordered_sets[0]
assert ordered_set.name == "Test Set"
assert ordered_set.slug == "test_set"
assert ordered_set.locale.language_code == "en"
assert unwagtail(ordered_set.profile_fields) == [
("gender", "male"),
("relationship", "in_a_relationship"),
]

pages = unwagtail(ordered_set.pages)
assert len(pages) == 1

page = pages[0][1]
assert page["contentpage"].slug == "first_time_user"

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