From 1f21b7437c6a6a43b8b1bab4b963a5c3fad0f612 Mon Sep 17 00:00:00 2001 From: Mateusz Mandera Date: Sun, 10 Nov 2024 00:07:19 +0100 Subject: [PATCH] test_import_export: Don't hard-code ZULIP_VERSION in fixtures. Otherwise, these tests fail if ZULIP_VERSION is different locally from what's hard-coded. Use a placeholder instead and replace dynamically in a helper function. --- .../extra_migrations_error.txt | 4 ++-- .../unapplied_migrations_error.txt | 4 ++-- zerver/tests/test_import_export.py | 17 +++++++++++------ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/zerver/tests/fixtures/import_fixtures/check_migrations_errors/extra_migrations_error.txt b/zerver/tests/fixtures/import_fixtures/check_migrations_errors/extra_migrations_error.txt index f3d9fb7481..2fea357067 100644 --- a/zerver/tests/fixtures/import_fixtures/check_migrations_errors/extra_migrations_error.txt +++ b/zerver/tests/fixtures/import_fixtures/check_migrations_errors/extra_migrations_error.txt @@ -1,6 +1,6 @@ Export was generated on a different Zulip version. -Export=10.0-dev+git -Server=10.0-dev+git +Export={version_placeholder} +Server={version_placeholder} Database formats differ between the exported realm and this server. Printing migrations that differ between the versions: diff --git a/zerver/tests/fixtures/import_fixtures/check_migrations_errors/unapplied_migrations_error.txt b/zerver/tests/fixtures/import_fixtures/check_migrations_errors/unapplied_migrations_error.txt index c00cec3229..b0f6e810e7 100644 --- a/zerver/tests/fixtures/import_fixtures/check_migrations_errors/unapplied_migrations_error.txt +++ b/zerver/tests/fixtures/import_fixtures/check_migrations_errors/unapplied_migrations_error.txt @@ -1,6 +1,6 @@ Export was generated on a different Zulip version. -Export=10.0-dev+git -Server=10.0-dev+git +Export={version_placeholder} +Server={version_placeholder} Database formats differ between the exported realm and this server. Printing migrations that differ between the versions: diff --git a/zerver/tests/test_import_export.py b/zerver/tests/test_import_export.py index d0910a3dcd..4f3df78009 100644 --- a/zerver/tests/test_import_export.py +++ b/zerver/tests/test_import_export.py @@ -348,6 +348,11 @@ class ExportFile(ZulipTestCase): ) return fixture + def get_applied_migrations_error_message(self, fixture_name: str) -> str: + fixture = self.fixture_data(fixture_name, "import_fixtures/check_migrations_errors") + fixture = fixture.format(version_placeholder=ZULIP_VERSION) + return fixture.strip() + def verify_migration_status_json(self) -> None: # This function asserts that the generated migration_status.json # is structurally familiar for it to be used for assertion at @@ -2060,9 +2065,9 @@ class RealmImportExportTest(ExportFile): ) do_import_realm(get_output_dir(), "test-zulip") - expected_error_message = self.fixture_data( - "unapplied_migrations_error.txt", "import_fixtures/check_migrations_errors" - ).strip() + expected_error_message = self.get_applied_migrations_error_message( + "unapplied_migrations_error.txt" + ) error_message = str(e.exception).strip() self.assertEqual(expected_error_message, error_message) @@ -2085,9 +2090,9 @@ class RealmImportExportTest(ExportFile): export_type=RealmExport.EXPORT_FULL_WITH_CONSENT, ) do_import_realm(get_output_dir(), "test-zulip") - expected_error_message = self.fixture_data( - "extra_migrations_error.txt", "import_fixtures/check_migrations_errors" - ).strip() + expected_error_message = self.get_applied_migrations_error_message( + "extra_migrations_error.txt" + ) error_message = str(e.exception).strip() self.assertEqual(expected_error_message, error_message)