mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	Fix building subscribe buttons for realms with a notification stream
Add a test sending new stream notifications to realms with a notification stream and fix a bug in building the subscribe button markdown. (imported from commit 37985d8c0603ae206bef34b9522231c00bc8c572)
This commit is contained in:
		@@ -2043,7 +2043,7 @@ class SubscriptionAPITest(AuthedTestCase):
 | 
				
			|||||||
                add_streams, self.streams, self.test_email, self.streams + add_streams)
 | 
					                add_streams, self.streams, self.test_email, self.streams + add_streams)
 | 
				
			||||||
        self.assertEqual(len(events), 1)
 | 
					        self.assertEqual(len(events), 1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_successful_subscriptions_notifies(self):
 | 
					    def test_successful_subscriptions_notifies_pm(self):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        Calling /json/subscriptions/add should notify when a new stream is created.
 | 
					        Calling /json/subscriptions/add should notify when a new stream is created.
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
@@ -2063,6 +2063,7 @@ class SubscriptionAPITest(AuthedTestCase):
 | 
				
			|||||||
        self.assert_json_success(result)
 | 
					        self.assert_json_success(result)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        msg = Message.objects.latest('id')
 | 
					        msg = Message.objects.latest('id')
 | 
				
			||||||
 | 
					        self.assertEqual(msg.recipient.type_id, Recipient.PERSONAL)
 | 
				
			||||||
        self.assertEqual(msg.sender_id,
 | 
					        self.assertEqual(msg.sender_id,
 | 
				
			||||||
                         get_user_profile_by_email('notification-bot@zulip.com').id)
 | 
					                         get_user_profile_by_email('notification-bot@zulip.com').id)
 | 
				
			||||||
        expected_msg = "Hi there!  %s just created a new stream '%s'. " \
 | 
					        expected_msg = "Hi there!  %s just created a new stream '%s'. " \
 | 
				
			||||||
@@ -2071,6 +2072,44 @@ class SubscriptionAPITest(AuthedTestCase):
 | 
				
			|||||||
                                                          invite_streams[0])
 | 
					                                                          invite_streams[0])
 | 
				
			||||||
        self.assertEqual(msg.content, expected_msg)
 | 
					        self.assertEqual(msg.content, expected_msg)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_successful_subscriptions_notifies_stream(self):
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        Calling /json/subscriptions/add should notify when a new stream is created.
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        invitee = "iago@zulip.com"
 | 
				
			||||||
 | 
					        invitee_full_name = 'Iago'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        current_stream = self.get_streams(invitee)[0]
 | 
				
			||||||
 | 
					        invite_streams = self.make_random_stream_names(current_stream)[:1]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        notifications_stream = Stream.objects.get(name=current_stream, realm=self.realm)
 | 
				
			||||||
 | 
					        self.realm.notifications_stream = notifications_stream
 | 
				
			||||||
 | 
					        self.realm.save()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Delete the UserProfile from the cache so the realm change will be
 | 
				
			||||||
 | 
					        # picked up
 | 
				
			||||||
 | 
					        cache.cache_delete(cache.user_profile_by_email_cache_key(invitee))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        result = self.common_subscribe_to_streams(
 | 
				
			||||||
 | 
					            invitee,
 | 
				
			||||||
 | 
					            invite_streams,
 | 
				
			||||||
 | 
					            extra_post_data=dict(
 | 
				
			||||||
 | 
					                announce='true',
 | 
				
			||||||
 | 
					                principals='["%s"]' % (self.user_profile.email,)
 | 
				
			||||||
 | 
					            ),
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					        self.assert_json_success(result)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        msg = Message.objects.latest('id')
 | 
				
			||||||
 | 
					        self.assertEqual(msg.recipient.type_id, Recipient.STREAM)
 | 
				
			||||||
 | 
					        self.assertEqual(msg.sender_id,
 | 
				
			||||||
 | 
					                         get_user_profile_by_email('notification-bot@zulip.com').id)
 | 
				
			||||||
 | 
					        expected_msg = "%s just created a new stream `%s`. " \
 | 
				
			||||||
 | 
					                       "!_stream_subscribe_button(%s)" % (invitee_full_name,
 | 
				
			||||||
 | 
					                                                          invite_streams[0],
 | 
				
			||||||
 | 
					                                                          invite_streams[0])
 | 
				
			||||||
 | 
					        self.assertEqual(msg.content, expected_msg)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_successful_subscriptions_notifies_with_escaping(self):
 | 
					    def test_successful_subscriptions_notifies_with_escaping(self):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        Calling /json/subscriptions/add should notify when a new stream is created.
 | 
					        Calling /json/subscriptions/add should notify when a new stream is created.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1242,7 +1242,7 @@ def add_subscriptions_backend(request, user_profile,
 | 
				
			|||||||
            else:
 | 
					            else:
 | 
				
			||||||
                stream_msg = "a new stream `%s`" % (created_streams[0].name)
 | 
					                stream_msg = "a new stream `%s`" % (created_streams[0].name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            stream_buttons = ' '.join(stream_button(s.name for s in created_streams))
 | 
					            stream_buttons = ' '.join(stream_button(s.name) for s in created_streams)
 | 
				
			||||||
            msg = ("%s just created %s. %s" % (user_profile.full_name,
 | 
					            msg = ("%s just created %s. %s" % (user_profile.full_name,
 | 
				
			||||||
                                                stream_msg, stream_buttons))
 | 
					                                                stream_msg, stream_buttons))
 | 
				
			||||||
            notifications.append(internal_prep_message(settings.NOTIFICATION_BOT,
 | 
					            notifications.append(internal_prep_message(settings.NOTIFICATION_BOT,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user