def test_footer(self):
     footer = MailFooter.monitored('*****@*****.**', 'http://test1.com',
                                   'http://test2.com')
     assert '[email protected] is subscribed to http://test1.com' in footer
     assert 'admin can change settings at http://test2.com' in footer
     footer = MailFooter.standard(M.Notification())
     assert 'Sent from sourceforge.net because you indicated interest in' in footer
Пример #2
0
 def test_send_direct(self, sendmail):
     c.user = M.User.query.get(username='******')
     wiki = c.project.app_instance('wiki')
     page = WM.Page.query.get(app_config_id=wiki.config._id)
     notification = M.Notification(
         _id='_id',
         ref=page.ref,
         from_address='from_address',
         reply_to_address='reply_to_address',
         in_reply_to='in_reply_to',
         references=['a'],
         subject='subject',
         text='text',
     )
     notification.footer = lambda: ' footer'
     notification.send_direct(c.user._id)
     sendmail.post.assert_called_once_with(
         destinations=[str(c.user._id)],
         fromaddr='from_address',
         reply_to='reply_to_address',
         subject='subject',
         message_id='_id',
         in_reply_to='in_reply_to',
         references=['a'],
         sender='*****@*****.**',
         text='text footer',
     )
Пример #3
0
 def test_footer(self):
     footer = MailFooter.monitored('*****@*****.**', 'http://test1.com',
                                   'http://test2.com')
     assert '[email protected] is subscribed to http://test1.com' in footer
     assert 'admin can change settings at http://test2.com' in footer
     footer = MailFooter.standard(M.Notification())
     self.assertIn('Sent from localhost because you indicated interest',
                   footer)
Пример #4
0
 def test(self):
     n = M.Notification(app_config_id=ObjectId(),
                        neighborhood_id=ObjectId(),
                        project_id=ObjectId(),
                        tool_name='blah')
     session(n).flush(n)
     assert_equal(M.Notification.query.find().count(), 1)
     self.run_script(['--back-days', '7'])
     assert_equal(M.Notification.query.find().count(), 1)
     self.run_script(['--back-days', '0'])
     assert_equal(M.Notification.query.find().count(), 0)
Пример #5
0
 def test_send_direct_disabled_user(self):
     user = M.User.by_username('test-admin')
     thd = M.Thread.query.get(ref_id=self.pg.index_id())
     notification = M.Notification()
     notification.ref_id = thd.index_id()
     user.disabled = True
     ThreadLocalORMSession.flush_all()
     notification.send_direct(user._id)
     count = M.MonQTask.query.find(
         dict(task_name='allura.tasks.mail_tasks.sendmail',
              state='ready')).count()
     assert_equal(count, 0)
     user.disabled = False
     ThreadLocalORMSession.flush_all()
     notification.send_direct(user._id)
     count = M.MonQTask.query.find(
         dict(task_name='allura.tasks.mail_tasks.sendmail',
              state='ready')).count()
     assert_equal(count, 1)
Пример #6
0
 def test_send_direct_no_access(self, sendmail):
     c.user = M.User.query.get(username='******')
     wiki = c.project.app_instance('wiki')
     page = WM.Page.query.get(app_config_id=wiki.config._id)
     page.parent_security_context().acl = []
     ThreadLocalORMSession.flush_all()
     ThreadLocalORMSession.close_all()
     notification = M.Notification(
         _id='_id',
         ref=page.ref,
         from_address='from_address',
         reply_to_address='reply_to_address',
         in_reply_to='in_reply_to',
         subject='subject',
         text='text',
     )
     notification.footer = lambda: ' footer'
     notification.send_direct(c.user._id)
     assert_equal(sendmail.post.call_count, 0)
Пример #7
0
    def test_send_direct_wrong_project_context(self, sendmail):
        """
        Test that Notification.send_direct() works as expected even
        if c.project is wrong.

        This can happen when a notify task is triggered on project A (thus
        setting c.project to A) and then calls Mailbox.fire_ready() which fires
        pending Notifications on any waiting Mailbox, regardless of project,
        but doesn't update c.project.
        """
        project1 = c.project
        project2 = M.Project.query.get(shortname='test2')
        assert_equal(project1.shortname, 'test')
        c.user = M.User.query.get(username='******')
        wiki = project1.app_instance('wiki')
        page = WM.Page.query.get(app_config_id=wiki.config._id)
        notification = M.Notification(
            _id='_id',
            ref=page.ref,
            from_address='from_address',
            reply_to_address='reply_to_address',
            in_reply_to='in_reply_to',
            references=['a'],
            subject='subject',
            text='text',
        )
        notification.footer = lambda: ' footer'
        c.project = project2
        notification.send_direct(c.user._id)
        sendmail.post.assert_called_once_with(
            destinations=[str(c.user._id)],
            fromaddr='from_address',
            reply_to='reply_to_address',
            subject='subject',
            message_id='_id',
            in_reply_to='in_reply_to',
            references=['a'],
            sender='*****@*****.**',
            text='text footer',
            metalink=None,
        )