Use stream ids in various tests.

This commit prepares us to introduce a StreamLite class. For
these tests, we don't care about the actual contents of the
Stream, just the right stream is there.
This commit is contained in:
Steve Howell
2017-09-17 10:53:38 -07:00
committed by Tim Abbott
parent c1d7fc6e80
commit 12e65eb21c
7 changed files with 19 additions and 19 deletions

View File

@@ -118,12 +118,12 @@ class TestRealmAuditLog(ZulipTestCase):
subscription_creation_logs = RealmAuditLog.objects.filter(event_type='subscription_created', subscription_creation_logs = RealmAuditLog.objects.filter(event_type='subscription_created',
event_time__gte=now) event_time__gte=now)
self.assertEqual(subscription_creation_logs.count(), 1) self.assertEqual(subscription_creation_logs.count(), 1)
self.assertEqual(subscription_creation_logs[0].modified_stream, stream[0]) self.assertEqual(subscription_creation_logs[0].modified_stream.id, stream[0].id)
self.assertEqual(subscription_creation_logs[0].modified_user, user[0]) self.assertEqual(subscription_creation_logs[0].modified_user, user[0])
bulk_remove_subscriptions(user, stream) bulk_remove_subscriptions(user, stream)
subscription_deactivation_logs = RealmAuditLog.objects.filter(event_type='subscription_deactivated', subscription_deactivation_logs = RealmAuditLog.objects.filter(event_type='subscription_deactivated',
event_time__gte=now) event_time__gte=now)
self.assertEqual(subscription_deactivation_logs.count(), 1) self.assertEqual(subscription_deactivation_logs.count(), 1)
self.assertEqual(subscription_deactivation_logs[0].modified_stream, stream[0]) self.assertEqual(subscription_deactivation_logs[0].modified_stream.id, stream[0].id)
self.assertEqual(subscription_deactivation_logs[0].modified_user, user[0]) self.assertEqual(subscription_deactivation_logs[0].modified_user, user[0])

View File

@@ -353,7 +353,7 @@ class HomeTest(ZulipTestCase):
# type: () -> None # type: () -> None
email = self.example_email("hamlet") email = self.example_email("hamlet")
realm = get_realm('zulip') realm = get_realm('zulip')
realm.notifications_stream = get_stream('Denmark', realm) realm.notifications_stream_id = get_stream('Denmark', realm).id
realm.save() realm.save()
self.login(email) self.login(email)
result = self._get_home_page() result = self._get_home_page()

View File

@@ -888,7 +888,7 @@ class MessagePOSTTest(ZulipTestCase):
""" """
user_profile = self.example_user('hamlet') user_profile = self.example_user('hamlet')
email = user_profile.email email = user_profile.email
user_profile.default_sending_stream = get_stream('Verona', user_profile.realm) user_profile.default_sending_stream_id = get_stream('Verona', user_profile.realm).id
user_profile.save() user_profile.save()
result = self.client_post("/api/v1/messages", {"type": "stream", result = self.client_post("/api/v1/messages", {"type": "stream",
"client": "test suite", "client": "test suite",

View File

@@ -136,7 +136,7 @@ class TestNotifyNewUser(ZulipTestCase):
# type: () -> None # type: () -> None
new_user = self.example_user('cordelia') new_user = self.example_user('cordelia')
stream = self.make_stream('announce') stream = self.make_stream('announce')
new_user.realm.notifications_stream = stream new_user.realm.notifications_stream_id = stream.id
new_user.realm.save() new_user.realm.save()
new_user = self.example_user('cordelia') new_user = self.example_user('cordelia')
notify_new_user(new_user) notify_new_user(new_user)

View File

@@ -206,11 +206,11 @@ class RealmTest(ZulipTestCase):
# type: () -> None # type: () -> None
realm = get_realm("zulip") realm = get_realm("zulip")
verona = get_stream("verona", realm) verona = get_stream("verona", realm)
realm.notifications_stream = verona realm.notifications_stream_id = verona.id
realm.save() realm.save()
notifications_stream = realm.get_notifications_stream() notifications_stream = realm.get_notifications_stream()
self.assertEqual(notifications_stream, verona) self.assertEqual(notifications_stream.id, verona.id)
do_deactivate_stream(notifications_stream) do_deactivate_stream(notifications_stream)
self.assertIsNone(realm.get_notifications_stream()) self.assertIsNone(realm.get_notifications_stream())

View File

@@ -525,7 +525,7 @@ class InviteUserTest(ZulipTestCase):
""" """
realm = get_realm('zulip') realm = get_realm('zulip')
notifications_stream = get_stream('Verona', realm) notifications_stream = get_stream('Verona', realm)
realm.notifications_stream = notifications_stream realm.notifications_stream_id = notifications_stream.id
realm.save() realm.save()
self.login(self.example_email("hamlet")) self.login(self.example_email("hamlet"))
@@ -535,8 +535,8 @@ class InviteUserTest(ZulipTestCase):
self.check_sent_emails([invitee]) self.check_sent_emails([invitee])
prereg_user = get_prereg_user_by_email(invitee) prereg_user = get_prereg_user_by_email(invitee)
streams = list(prereg_user.streams.all()) stream_ids = [stream.id for stream in prereg_user.streams.all()]
self.assertTrue(notifications_stream in streams) self.assertTrue(notifications_stream.id in stream_ids)
def test_invite_user_signup_initial_history(self): def test_invite_user_signup_initial_history(self):
# type: () -> None # type: () -> None

View File

@@ -212,18 +212,18 @@ class StreamAdminTest(ZulipTestCase):
# type: () -> None # type: () -> None
stream = self.make_stream('new_stream') stream = self.make_stream('new_stream')
do_add_default_stream(stream) do_add_default_stream(stream)
self.assertEqual(1, DefaultStream.objects.filter(stream=stream).count()) self.assertEqual(1, DefaultStream.objects.filter(stream_id=stream.id).count())
do_deactivate_stream(stream) do_deactivate_stream(stream)
self.assertEqual(0, DefaultStream.objects.filter(stream=stream).count()) self.assertEqual(0, DefaultStream.objects.filter(stream_id=stream.id).count())
def test_vacate_private_stream_removes_default_stream(self): def test_vacate_private_stream_removes_default_stream(self):
# type: () -> None # type: () -> None
stream = self.make_stream('new_stream', invite_only=True) stream = self.make_stream('new_stream', invite_only=True)
self.subscribe(self.example_user("hamlet"), stream.name) self.subscribe(self.example_user("hamlet"), stream.name)
do_add_default_stream(stream) do_add_default_stream(stream)
self.assertEqual(1, DefaultStream.objects.filter(stream=stream).count()) self.assertEqual(1, DefaultStream.objects.filter(stream_id=stream.id).count())
self.unsubscribe(self.example_user("hamlet"), stream.name) self.unsubscribe(self.example_user("hamlet"), stream.name)
self.assertEqual(0, DefaultStream.objects.filter(stream=stream).count()) self.assertEqual(0, DefaultStream.objects.filter(stream_id=stream.id).count())
# Fetch stream again from database. # Fetch stream again from database.
stream = Stream.objects.get(id=stream.id) stream = Stream.objects.get(id=stream.id)
self.assertTrue(stream.deactivated) self.assertTrue(stream.deactivated)
@@ -1392,7 +1392,7 @@ class SubscriptionAPITest(ZulipTestCase):
'announce': 'true', 'announce': 'true',
} }
notifications_stream = get_stream(self.streams[0], self.test_realm) notifications_stream = get_stream(self.streams[0], self.test_realm)
self.test_realm.notifications_stream = notifications_stream self.test_realm.notifications_stream_id = notifications_stream.id
self.test_realm.save() self.test_realm.save()
# Delete the UserProfile from the cache so the realm change will be # Delete the UserProfile from the cache so the realm change will be
@@ -1435,7 +1435,7 @@ class SubscriptionAPITest(ZulipTestCase):
invite_streams = self.make_random_stream_names([current_stream])[:1] invite_streams = self.make_random_stream_names([current_stream])[:1]
notifications_stream = get_stream(current_stream, self.test_realm) notifications_stream = get_stream(current_stream, self.test_realm)
self.test_realm.notifications_stream = notifications_stream self.test_realm.notifications_stream_id = notifications_stream.id
self.test_realm.save() self.test_realm.save()
# Delete the UserProfile from the cache so the realm change will be # Delete the UserProfile from the cache so the realm change will be
@@ -1508,7 +1508,7 @@ class SubscriptionAPITest(ZulipTestCase):
current_stream = self.get_streams(invitee, self.test_realm)[0] current_stream = self.get_streams(invitee, self.test_realm)[0]
notifications_stream = get_stream(current_stream, self.test_realm) notifications_stream = get_stream(current_stream, self.test_realm)
self.test_realm.notifications_stream = notifications_stream self.test_realm.notifications_stream_id = notifications_stream.id
self.test_realm.save() self.test_realm.save()
invite_streams = ['strange ) \\ test'] invite_streams = ['strange ) \\ test']
@@ -2690,11 +2690,11 @@ class AccessStreamTest(ZulipTestCase):
# Hamlet can access the private stream # Hamlet can access the private stream
(stream_ret, rec_ret, sub_ret) = access_stream_by_id(hamlet, stream.id) (stream_ret, rec_ret, sub_ret) = access_stream_by_id(hamlet, stream.id)
self.assertEqual(stream, stream_ret) self.assertEqual(stream.id, stream_ret.id)
self.assertEqual(sub_ret.recipient, rec_ret) self.assertEqual(sub_ret.recipient, rec_ret)
self.assertEqual(sub_ret.recipient.type_id, stream.id) self.assertEqual(sub_ret.recipient.type_id, stream.id)
(stream_ret2, rec_ret2, sub_ret2) = access_stream_by_name(hamlet, stream.name) (stream_ret2, rec_ret2, sub_ret2) = access_stream_by_name(hamlet, stream.name)
self.assertEqual(stream_ret, stream_ret2) self.assertEqual(stream_ret.id, stream_ret2.id)
self.assertEqual(sub_ret, sub_ret2) self.assertEqual(sub_ret, sub_ret2)
self.assertEqual(rec_ret, rec_ret2) self.assertEqual(rec_ret, rec_ret2)