Skip to content

Commit

Permalink
Merge branch 'minor-import-export-test-cleanups'
Browse files Browse the repository at this point in the history
  • Loading branch information
jerith committed Dec 14, 2023
2 parents 11f11de + 05c1181 commit 4b25e4d
Showing 1 changed file with 39 additions and 28 deletions.
67 changes: 39 additions & 28 deletions home/tests/test_content_import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def enable_web(page: DbDict) -> DbDict:


@dataclass
class ImportExportFixture:
class ImportExport:
admin_client: Any
importer: str
format: str
Expand Down Expand Up @@ -550,8 +550,8 @@ def csvs2dicts(self, src_bytes: bytes, dst_bytes: bytes) -> ExpDictsPair:


@pytest.fixture(params=["old", "new"])
def csv_impexp(request: Any, admin_client: Any) -> ImportExportFixture:
return ImportExportFixture(admin_client, request.param, "csv")
def csv_impexp(request: Any, admin_client: Any) -> ImportExport:
return ImportExport(admin_client, request.param, "csv")


@pytest.mark.django_db
Expand All @@ -564,7 +564,7 @@ class TestImportExportRoundtrip:
container for related tests.
"""

def test_roundtrip_simple(self, csv_impexp: ImportExportFixture) -> None:
def test_simple(self, csv_impexp: ImportExport) -> None:
"""
Importing a simple CSV file and then exporting it produces a duplicate
of the original file.
Expand All @@ -584,7 +584,7 @@ def test_roundtrip_simple(self, csv_impexp: ImportExportFixture) -> None:
src, dst = csv_impexp.csvs2dicts(csv_bytes, content)
assert dst == src

def test_roundtrip_less_simple(self, csv_impexp: ImportExportFixture) -> None:
def test_less_simple(self, csv_impexp: ImportExport) -> None:
"""
Importing a less simple CSV file and then exporting it produces a
duplicate of the original file.
Expand All @@ -602,7 +602,7 @@ def test_roundtrip_less_simple(self, csv_impexp: ImportExportFixture) -> None:
src, dst = csv_impexp.csvs2dicts(csv_bytes, content)
assert dst == src

def test_roundtrip_multiple_messages(self, csv_impexp: ImportExportFixture) -> None:
def test_multiple_messages(self, csv_impexp: ImportExport) -> None:
"""
Importing a CSV file containing multiple messages of each type for a
page and then exporting it produces a duplicate of the original file.
Expand All @@ -615,7 +615,7 @@ def test_roundtrip_multiple_messages(self, csv_impexp: ImportExportFixture) -> N
src, dst = csv_impexp.csvs2dicts(csv_bytes, content)
assert dst == src

def test_roundtrip_translations_sep(self, csv_impexp: ImportExportFixture) -> None:
def test_translations_sep(self, csv_impexp: ImportExport) -> None:
"""
Importing a CSV file split into separate parts per locale and then
exporting it produces a duplicate of the original file.
Expand All @@ -638,7 +638,7 @@ def test_roundtrip_translations_sep(self, csv_impexp: ImportExportFixture) -> No
src, dst = csv_impexp.csvs2dicts(csv_bytes, content)
assert dst == src

def test_roundtrip_default_locale(self, csv_impexp: ImportExportFixture) -> None:
def test_default_locale(self, csv_impexp: ImportExport) -> None:
"""
Importing a CSV file with multiple languages and specifying a locale
and then exporting it produces a duplicate of the original file but
Expand All @@ -661,7 +661,7 @@ def test_roundtrip_default_locale(self, csv_impexp: ImportExportFixture) -> None
src, dst = csv_impexp.csvs2dicts(csv_bytes, content)
assert dst == src

def test_roundtrip_translated_locale(self, csv_impexp: ImportExportFixture) -> None:
def test_translated_locale(self, csv_impexp: ImportExport) -> None:
"""
Importing a CSV file with multiple languages and specifying a locale
and then exporting it produces a duplicate of the original file but
Expand All @@ -684,7 +684,7 @@ def test_roundtrip_translated_locale(self, csv_impexp: ImportExportFixture) -> N
src, dst = csv_impexp.csvs2dicts(csv_bytes, content)
assert dst == src

def test_roundtrip_all_locales(self, csv_impexp: ImportExportFixture) -> None:
def test_all_locales(self, csv_impexp: ImportExport) -> None:
"""
Importing a CSV file containing translations and then exporting it
produces a duplicate of the original file.
Expand All @@ -703,7 +703,7 @@ def test_roundtrip_all_locales(self, csv_impexp: ImportExportFixture) -> None:
src, dst = csv_impexp.csvs2dicts(csv_bytes, content)
assert dst == src

def test_roundtrip_all_locales_split(self, csv_impexp: ImportExportFixture) -> None:
def test_all_locales_split(self, csv_impexp: ImportExport) -> None:
"""
Importing a CSV file split into separate parts per locale and then
exporting it produces a duplicate of the original file.
Expand All @@ -725,7 +725,18 @@ def test_roundtrip_all_locales_split(self, csv_impexp: ImportExportFixture) -> N
src, dst = csv_impexp.csvs2dicts(csv_bytes, content)
assert dst == src

def test_import_error(self, csv_impexp: ImportExportFixture) -> None:

@pytest.mark.django_db
class TestImportExport:
"""
Text various import and export scenarios that aren't specifically round
trips.
NOTE: This is not a Django (or even unittest) TestCase. It's just a
container for related tests.
"""

def test_import_error(self, csv_impexp: ImportExport) -> None:
"""
Importing an invalid CSV file leaves the db as-is.
Expand All @@ -746,9 +757,9 @@ def test_import_error(self, csv_impexp: ImportExportFixture) -> None:

# "old-xlsx" has at least three bugs, so we don't bother testing it.
@pytest.fixture(params=["old-csv", "new-csv", "new-xlsx"])
def impexp(request: Any, admin_client: Any) -> ImportExportFixture:
def impexp(request: Any, admin_client: Any) -> ImportExport:
importer, format = request.param.split("-")
return ImportExportFixture(admin_client, importer, format)
return ImportExport(admin_client, importer, format)


@pytest.fixture()
Expand All @@ -773,7 +784,7 @@ class TestExportImportRoundtrip:
container for related tests.
"""

def test_simple(self, impexp: ImportExportFixture) -> None:
def test_simple(self, impexp: ImportExport) -> None:
"""
Exporting and then importing leaves the db in the same state it was
before, except for page_ids, timestamps, and body item ids.
Expand Down Expand Up @@ -821,7 +832,7 @@ def test_simple(self, impexp: ImportExportFixture) -> None:
imported = impexp.get_page_json()
assert imported == orig

def test_web_content(self, impexp: ImportExportFixture) -> None:
def test_web_content(self, impexp: ImportExport) -> None:
"""
ContentPages with web content are preserved across export/import.
Expand All @@ -843,7 +854,7 @@ def test_web_content(self, impexp: ImportExportFixture) -> None:
imported = impexp.get_page_json()
assert imported == orig

def test_multiple_messages(self, impexp: ImportExportFixture) -> None:
def test_multiple_messages(self, impexp: ImportExport) -> None:
"""
ContentPages with multiple message blocks are preserved across
export/import.
Expand Down Expand Up @@ -877,7 +888,7 @@ def test_multiple_messages(self, impexp: ImportExportFixture) -> None:
assert imported == orig

@pytest.mark.xfail(reason="Image imports are currently broken.")
def test_images(self, impexp: ImportExportFixture) -> None:
def test_images(self, impexp: ImportExport) -> None:
"""
ContentPages with images in multiple message types are preserved across
export/import.
Expand Down Expand Up @@ -908,7 +919,7 @@ def test_images(self, impexp: ImportExportFixture) -> None:
imported = impexp.get_page_json()
assert imported == orig

def test_variations(self, impexp: ImportExportFixture) -> None:
def test_variations(self, impexp: ImportExport) -> None:
"""
ContentPages with variation messages (and buttons and next prompts) are
preserved across export/import.
Expand Down Expand Up @@ -960,7 +971,7 @@ def test_variations(self, impexp: ImportExportFixture) -> None:
imported = impexp.get_page_json()
assert imported == orig

def test_tags_and_related(self, impexp: ImportExportFixture) -> None:
def test_tags_and_related(self, impexp: ImportExport) -> None:
"""
ContentPages with tags and related pages are preserved across
export/import.
Expand Down Expand Up @@ -1005,7 +1016,7 @@ def test_tags_and_related(self, impexp: ImportExportFixture) -> None:
imported = impexp.get_page_json()
assert imported == orig

def test_triggers_and_quick_replies(self, impexp: ImportExportFixture) -> None:
def test_triggers_and_quick_replies(self, impexp: ImportExport) -> None:
"""
ContentPages with triggers and quick replies are preserved across
export/import.
Expand Down Expand Up @@ -1043,7 +1054,7 @@ def test_triggers_and_quick_replies(self, impexp: ImportExportFixture) -> None:
imported = impexp.get_page_json()
assert imported == orig

def test_whatsapp_template(self, impexp: ImportExportFixture) -> None:
def test_whatsapp_template(self, impexp: ImportExport) -> None:
"""
ContentPages that are whatsapp templates are preserved across
export/import.
Expand All @@ -1069,7 +1080,7 @@ def test_whatsapp_template(self, impexp: ImportExportFixture) -> None:
imported = impexp.get_page_json()
assert imported == orig

def test_translations(self, impexp: ImportExportFixture) -> None:
def test_translations(self, impexp: ImportExport) -> None:
"""
ContentPages in multiple languages (with unique-per-locale slugs and
titles) are preserved across export/import.
Expand Down Expand Up @@ -1149,7 +1160,7 @@ def test_translations(self, impexp: ImportExportFixture) -> None:
imported = impexp.get_page_json()
assert imported == orig

def test_translations_sep(self, impexp: ImportExportFixture) -> None:
def test_translations_sep(self, impexp: ImportExport) -> None:
"""
ContentPages in multiple languages (with globally-unique slugs and titles) are
preserved across export/import with each language imported separately.
Expand Down Expand Up @@ -1222,7 +1233,7 @@ def test_translations_sep(self, impexp: ImportExportFixture) -> None:
imported = impexp.get_page_json()
assert imported == orig

def test_translations_split(self, impexp: ImportExportFixture) -> None:
def test_translations_split(self, impexp: ImportExport) -> None:
"""
ContentPages in multiple languages (with unique-per-locale slugs and
titles) are preserved across export/import with each language imported
Expand Down Expand Up @@ -1299,7 +1310,7 @@ def test_translations_split(self, impexp: ImportExportFixture) -> None:
imported = impexp.get_page_json()
assert imported == orig

def test_translations_en(self, impexp: ImportExportFixture) -> None:
def test_translations_en(self, impexp: ImportExport) -> None:
"""
ContentPages in multiple languages are that are imported with a locale
specified have pages in that locale preserved and all other locales are
Expand Down Expand Up @@ -1374,7 +1385,7 @@ def test_translations_en(self, impexp: ImportExportFixture) -> None:
imported = impexp.get_page_json()
assert imported == orig_en

def test_example_values(self, impexp: ImportExportFixture) -> None:
def test_example_values(self, impexp: ImportExport) -> None:
"""
ContentPages with example values in whatsapp messages are preserved
across export/import.
Expand Down Expand Up @@ -1411,7 +1422,7 @@ def test_example_values(self, impexp: ImportExportFixture) -> None:
imported = impexp.get_page_json()
assert imported == orig

def test_export_missing_related_page(self, impexp: ImportExportFixture) -> None:
def test_export_missing_related_page(self, impexp: ImportExport) -> None:
"""
If a page has a related page that no longer exists, the missing related
page is skipped during export.
Expand Down

0 comments on commit 4b25e4d

Please sign in to comment.