Пример #1
0
    def test_send_system_message(self):
        """Test sending a system message"""
        user = mommy.make(User)

        # pylint: disable=line-too-long
        with patch('open_connect.connectmessages.tasks.send_immediate_notification') as mock:
            tasks.send_system_message(user, self.subject, self.message)

        self.assertTrue(UserThread.objects.filter(
            user=user,
            thread__first_message__sender__email='*****@*****.**',
            thread__subject=self.subject,
            thread__thread_type='direct',
            thread__closed=True
            ).exists())

        notification = Notification.objects.get(recipient=user)
        self.assertEqual(notification.message.text, self.message)

        # Confirm that the `system_message` and `system_thread` properties on
        # the Message and Thread model work.
        self.assertTrue(notification.message.is_system_message)
        self.assertTrue(notification.message.thread.is_system_thread)

        mock.delay.assert_called_once_with(notification.pk)
Пример #2
0
    def test_send_system_message_no_notification(self):
        """
        Test sending a system message to a user that has disabled notifications
        """
        user = mommy.make(User, group_notification_period='none')

        # pylint: disable=line-too-long
        with patch('open_connect.connectmessages.tasks.send_immediate_notification') as mock:
            tasks.send_system_message(user, self.subject, self.message)

        self.assertFalse(mock.delay.called)
Пример #3
0
    def test_systemthread(self):
        """Test the thread serialization method for a system message"""
        # The sqlite test runner doesn't run south migrations, so create the
        # user here if it doesn't exist
        USER_MODEL.objects.get_or_create(
            email='*****@*****.**',
            defaults={
                'username': '******',
                'is_active': True,
                'is_superuser': True
            })
        recipient = self.create_user()
        send_system_message(recipient, 'Subject Here', 'Content Here')
        thread = Thread.public.by_user(recipient).first()

        message = thread.first_message
        chicago = pytz.timezone('US/Central')
        self.assertDictItemsEqualUnordered(
            thread.serializable(), {
                'id':
                thread.pk,
                'total_messages':
                '1',
                'subject':
                thread.subject,
                'snippet':
                unicode(message.snippet),
                'json_url':
                str(reverse('thread_details_json', args=[thread.pk])),
                'read':
                False,
                'group':
                u'',
                'group_url':
                '',
                'group_id':
                None,
                'type':
                'direct',
                'unread_messages':
                1,
                'category':
                u'',
                'reply_url':
                reverse('create_direct_message_reply', args=[thread.pk]),
                'unsubscribe_url':
                thread.get_unsubscribe_url(),
                'is_system_thread':
                True,
                'userthread_status':
                'active',
                'latest_message_at':
                str(thread.latest_message.created_at.astimezone(chicago))
            })
Пример #4
0
    def test_send_system_message_user_pk(self):
        """Test sending a system message by passing in a user's primary key"""
        user = mommy.make(User)

        # pylint: disable=line-too-long
        with patch('open_connect.connectmessages.tasks.send_immediate_notification') as mock:
            tasks.send_system_message(user.pk, self.subject, self.message)

        self.assertTrue(UserThread.objects.filter(
            user=user,
            thread__first_message__sender__email='*****@*****.**',
            thread__subject=self.subject,
            thread__thread_type='direct',
            thread__closed=True
            ).exists())

        notification = Notification.objects.get(recipient=user)
        mock.delay.assert_called_once_with(notification.pk)
Пример #5
0
    def test_systemthread(self):
        """Test the thread serialization method for a system message"""
        # The sqlite test runner doesn't run south migrations, so create the
        # user here if it doesn't exist
        USER_MODEL.objects.get_or_create(
            email='*****@*****.**', defaults={
                'username': '******',
                'is_active': True,
                'is_superuser': True
            }
        )
        recipient = self.create_user()
        send_system_message(recipient, 'Subject Here', 'Content Here')
        thread = Thread.public.by_user(recipient).first()

        message = thread.first_message
        chicago = pytz.timezone('US/Central')
        self.assertDictItemsEqualUnordered(
            thread.serializable(),
            {
                'id': thread.pk,
                'total_messages': '1',
                'subject': thread.subject,
                'snippet': unicode(message.snippet),
                'json_url': str(
                    reverse('thread_details_json', args=[thread.pk])),
                'read': False,
                'group': u'',
                'group_url': '',
                'group_id': None,
                'type': 'direct',
                'unread_messages': 1,
                'category': u'',
                'reply_url': reverse(
                    'create_direct_message_reply', args=[thread.pk]),
                'unsubscribe_url': thread.get_unsubscribe_url(),
                'is_system_thread': True,
                'userthread_status': 'active',
                'latest_message_at':
                    str(thread.latest_message.created_at.astimezone(chicago))
            }
        )