Skip to content

Commit

Permalink
Add some tests for ordered sets to verify that they are unique by slu…
Browse files Browse the repository at this point in the history
…g & locale
  • Loading branch information
Gerrit Vermeulen committed Nov 26, 2024
1 parent e11ce6d commit cecbd91
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
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.
"""
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

0 comments on commit cecbd91

Please sign in to comment.