import: Import AlertWord table.

This commit is contained in:
Steve Howell
2020-07-16 14:11:34 +00:00
committed by Tim Abbott
parent 318c55e030
commit 2374e25b94
2 changed files with 19 additions and 0 deletions

View File

@@ -33,6 +33,7 @@ from zerver.lib.timestamp import datetime_to_timestamp
from zerver.lib.upload import BadImageError, guess_type, random_name, sanitize_name
from zerver.lib.utils import generate_api_key, process_list_in_batches
from 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) -> Realm
huddle.recipient = recipient
huddle.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')

View File

@@ -33,6 +33,7 @@ from zerver.lib.upload import (
)
from zerver.lib.utils import query_chunker
from 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 userhotspot
def get_user_hotspots(r: str) -> Set[str]:
user_profile = UserProfile.objects.get(realm=r, short_name='hamlet')