Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
import: Import AlertWord table.
Steve Howell2374e25b9419
diff --git a/zerver/lib/import_realm.py b/zerver/lib/import_realm.pyindex 787926fde29..4f3cf5b4fe5 100644--- a/zerver/lib/import_realm.py+++ b/zerver/lib/import_realm.py@@ -33,6 +33,7 @@ from zerver.lib.timestamp import datetime_to_timestampfrom zerver.lib.upload import BadImageError, guess_type, random_name, sanitize_namefrom zerver.lib.utils import generate_api_key, process_list_in_batchesfrom zerver.models import (+ AlertWord,Attachment,BotConfigData,BotStorageData,@@ -83,6 +84,7 @@ realm_tables = [("zerver_defaultstream", DefaultStream, "defaultstream"),# Code reviewers: give these tables extra scrutiny, as we need to# make sure to reload related tables AFTER we re-map the ids.ID_MAP: Dict[str, Dict[int, int]] = {+ 'alertword': {},'client': {},'user_profile': {},'huddle': {},@@ -942,6 +944,12 @@ def do_import_realm(import_dir: Path, subdomain: str, processes: int=1) -> Realmhuddle.recipient = recipienthuddle.save(update_fields=["recipient"])+ if 'zerver_alertword' in data:+ re_map_foreign_keys(data, 'zerver_alertword', 'user_profile', related_table='user_profile')+ re_map_foreign_keys(data, 'zerver_alertword', 'realm', related_table='realm')+ update_model_ids(AlertWord, data, 'alertword')+ bulk_import_model(data, AlertWord)+if 'zerver_userhotspot' in data:fix_datetime_fields(data, 'zerver_userhotspot')re_map_foreign_keys(data, 'zerver_userhotspot', 'user', related_table='user_profile')diff --git a/zerver/tests/test_import_export.py b/zerver/tests/test_import_export.pyindex 459582009b8..d4584cdafdb 100644--- a/zerver/tests/test_import_export.py+++ b/zerver/tests/test_import_export.py@@ -33,6 +33,7 @@ from zerver.lib.upload import ()from zerver.lib.utils import query_chunkerfrom zerver.models import (+ AlertWord,Attachment,BotConfigData,BotStorageData,@@ -857,6 +858,16 @@ class ImportExportTest(ZulipTestCase):assert_realm_values(get_huddle_message)self.assertEqual(get_huddle_message(imported_realm), 'test huddle message')+ # test alertword+ def get_alertwords(r: Realm) -> Set[str]:+ return {+ rec.word+ for rec in+ AlertWord.objects.filter(realm_id=r.id)+ }++ assert_realm_values(get_alertwords)+# test userhotspotdef get_user_hotspots(r: str) -> Set[str]:user_profile = UserProfile.objects.get(realm=r, short_name='hamlet')