snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
This commit is contained in:
68
zerver/tests/test_migrations.py
Normal file
68
zerver/tests/test_migrations.py
Normal file
@@ -0,0 +1,68 @@
|
||||
# These are tests for Zulip's database migrations. System documented at:
|
||||
# https://zulip.readthedocs.io/en/latest/subsystems/schema-migrations.html
|
||||
#
|
||||
# You can also read
|
||||
# https://www.caktusgroup.com/blog/2016/02/02/writing-unit-tests-django-migrations/
|
||||
# to get a tutorial on the framework that inspired this feature.
|
||||
from django.db.migrations.state import StateApps
|
||||
from typing_extensions import override
|
||||
|
||||
from zerver.lib.test_classes import MigrationsTestCase
|
||||
|
||||
# Important note: These tests are very expensive, and details of
|
||||
# Django's database transaction model mean it does not super work to
|
||||
# have a lot of migrations tested in this file at once; so we usually
|
||||
# delete the old migration tests when adding a new one, so this file
|
||||
# always has a single migration test in it as an example.
|
||||
#
|
||||
# The error you get with multiple similar tests doing migrations on
|
||||
# the same table is this (table name may vary):
|
||||
#
|
||||
# django.db.utils.OperationalError: cannot ALTER TABLE
|
||||
# "zerver_subscription" because it has pending trigger events
|
||||
|
||||
|
||||
class FixDeletedUserEmail(MigrationsTestCase):
|
||||
migrate_from = "0804_backfill_user_created_audit_logs"
|
||||
migrate_to = "0805_fix_deleteduser_email"
|
||||
|
||||
@override
|
||||
def setUpBeforeMigration(self, apps: StateApps) -> None:
|
||||
Realm = apps.get_model("zerver", "Realm")
|
||||
UserProfile = apps.get_model("zerver", "UserProfile")
|
||||
realm = Realm.objects.get(string_id="zulip")
|
||||
|
||||
# Simulate a user deleted before the fix in 208c0c303405,
|
||||
# after 0439_fix_deleteduser_email repaired delivery_email.
|
||||
deleted_user = UserProfile.objects.get(realm=realm, delivery_email="hamlet@zulip.com")
|
||||
UserProfile.objects.filter(id=deleted_user.id).update(
|
||||
is_active=False,
|
||||
email=f"deleteduser{deleted_user.id}@https://zulip.testserver",
|
||||
delivery_email=f"deleteduser{deleted_user.id}@zulip.testserver",
|
||||
)
|
||||
self.deleted_user_id = deleted_user.id
|
||||
|
||||
# A normal active user, as a control.
|
||||
control_user = UserProfile.objects.get(realm=realm, delivery_email="cordelia@zulip.com")
|
||||
self.control_user_id = control_user.id
|
||||
self.control_user_email = control_user.email
|
||||
|
||||
# A deactivated user with a valid email, as a control for the
|
||||
# is_active=False part of the migration's filter.
|
||||
deactivated_user = UserProfile.objects.get(realm=realm, delivery_email="othello@zulip.com")
|
||||
UserProfile.objects.filter(id=deactivated_user.id).update(is_active=False)
|
||||
self.deactivated_user_id = deactivated_user.id
|
||||
self.deactivated_user_email = deactivated_user.email
|
||||
|
||||
def test_deleted_user_email_fixed(self) -> None:
|
||||
UserProfile = self.apps.get_model("zerver", "UserProfile")
|
||||
|
||||
deleted_user = UserProfile.objects.get(id=self.deleted_user_id)
|
||||
self.assertEqual(deleted_user.email, f"deleteduser{deleted_user.id}@zulip.testserver")
|
||||
self.assertEqual(deleted_user.email, deleted_user.delivery_email)
|
||||
|
||||
control_user = UserProfile.objects.get(id=self.control_user_id)
|
||||
self.assertEqual(control_user.email, self.control_user_email)
|
||||
|
||||
deactivated_user = UserProfile.objects.get(id=self.deactivated_user_id)
|
||||
self.assertEqual(deactivated_user.email, self.deactivated_user_email)
|
||||
Reference in New Issue
Block a user