Skip to content

Commit

Permalink
import: Import MutedTopic.
Browse files Browse the repository at this point in the history
  • Loading branch information
rheaparekh authored and timabbott committed Jul 23, 2018
1 parent 6eab644 commit f444e5b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
10 changes: 9 additions & 1 deletion zerver/lib/import_realm.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
UserPresence, UserActivity, UserActivityInterval, Reaction, \
CustomProfileField, CustomProfileFieldValue, RealmAuditLog, \
Attachment, get_system_bot, email_to_username, get_huddle_hash, \
UserHotspot
UserHotspot, MutedTopic

# Code from here is the realm import code path

Expand Down Expand Up @@ -63,6 +63,7 @@
'realmauditlog': {},
'recipient_to_huddle_map': {},
'userhotspot': {},
'mutedtopic': {},
} # type: Dict[str, Dict[int, int]]

id_map_to_list = {
Expand Down Expand Up @@ -678,6 +679,13 @@ def do_import_realm(import_dir: Path, subdomain: str) -> Realm:
update_model_ids(UserHotspot, data, 'zerver_userhotspot', 'userhotspot')
bulk_import_model(data, UserHotspot, 'zerver_userhotspot')

if 'zerver_mutedtopic' in data:
re_map_foreign_keys(data, 'zerver_mutedtopic', 'user_profile', related_table='user_profile')
re_map_foreign_keys(data, 'zerver_mutedtopic', 'stream', related_table='stream')
re_map_foreign_keys(data, 'zerver_mutedtopic', 'recipient', related_table='recipient')
update_model_ids(MutedTopic, data, 'zerver_mutedtopic', 'mutedtopic')
bulk_import_model(data, MutedTopic, 'zerver_mutedtopic')

fix_datetime_fields(data, 'zerver_userpresence')
re_map_foreign_keys(data, 'zerver_userpresence', 'user_profile', related_table="user_profile")
re_map_foreign_keys(data, 'zerver_userpresence', 'client', related_table='client')
Expand Down
27 changes: 26 additions & 1 deletion zerver/tests/test_import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
use_s3_backend,
)

from zerver.lib.topic_mutes import (
add_topic_mute,
)

from zerver.lib.test_runner import slow

from zerver.models import (
Expand All @@ -58,7 +62,9 @@
RealmAuditLog,
Huddle,
UserHotspot,
MutedTopic,
get_active_streams,
get_stream,
get_stream_recipient,
get_personal_recipient,
get_huddle_hash,
Expand Down Expand Up @@ -484,10 +490,20 @@ def test_import_realm(self) -> None:
)

# data to test import of hotspots
sample_user = self.example_user('hamlet')

UserHotspot.objects.create(
user=self.example_user('hamlet'), hotspot='intro_streams'
user=sample_user, hotspot='intro_streams'
)

# data to test import of muted topic
stream = get_stream(u'Verona', original_realm)
add_topic_mute(
user_profile=sample_user,
stream_id=stream.id,
recipient_id=get_stream_recipient(stream.id).id,
topic_name=u'Verona2')

self._export_realm(original_realm)

with patch('logging.info'):
Expand Down Expand Up @@ -628,6 +644,15 @@ def get_user_hotspots(r: str) -> Set[str]:

assert_realm_values(get_user_hotspots)

# test muted topics
def get_muted_topics(r: Realm) -> Set[str]:
user_profile = UserProfile.objects.get(realm=r, short_name='hamlet')
muted_topics = MutedTopic.objects.filter(user_profile=user_profile)
topic_names = {muted_topic.topic_name for muted_topic in muted_topics}
return topic_names

assert_realm_values(get_muted_topics)

# test messages
def get_stream_messages(r: Realm) -> Message:
recipient = get_recipient_stream(r)
Expand Down

0 comments on commit f444e5b

Please sign in to comment.