Ejemplo n.º 1
0
    def test_Forward_PM_Answer(self):
        r = MagicMock()
        msg = MagicMock()
        msg.subreddit = None
        msg.author.name = credentials.admin_username
        msg.id = 'msgid2'
        msg.distinguished = None
        msg.subject = 're: #msgid1 /u/user: "******"'
        msg.body = 'body'
        pmUserCache = { }

        helper = MagicMock()
        helper.parseText = MagicMock(return_value=([], 'text'))

        oldMsg = MagicMock()
        r.inbox.message = MagicMock(return_value=oldMsg)

        # test
        hsbot.answerPM(r, msg, pmUserCache, helper)

        self.assertTrue(msg.author.name not in pmUserCache, "don't admin")

        expected = [call.inbox.message('msgid1')]
        self.assertEqual(r.method_calls, expected, 'reddit call')

        expected = [call.message('msgid1')]
        self.assertEqual(r.inbox.method_calls, expected, 'get old msg')

        expected = [call.reply('body')]
        self.assertEqual(oldMsg.method_calls, expected, 'reply old')

        expected = [call.reply('answer forwarded')]
        self.assertEqual(msg.method_calls, expected, 'reply new')

        self.assertEqual(helper.method_calls, [], 'no helper calls')
Ejemplo n.º 2
0
    def test_Forward_PM_Answer(self):
        r = MagicMock()
        msg = MagicMock()
        msg.subreddit = None
        msg.author.name = credentials.admin_username
        msg.id = 'msgid2'
        msg.distinguished = None
        msg.subject = 're: #msgid1 /u/user: "******"'
        msg.body = 'body'
        pmUserCache = {}

        helper = MagicMock()
        helper.parseText = MagicMock(return_value=([], 'text'))

        oldMsg = MagicMock()
        r.inbox.message = MagicMock(return_value=oldMsg)

        # test
        hsbot.answerPM(r, msg, pmUserCache, helper)

        self.assertTrue(msg.author.name not in pmUserCache, "don't admin")

        expected = [call.inbox.message('msgid1')]
        self.assertEqual(r.method_calls, expected, 'reddit call')

        expected = [call.message('msgid1')]
        self.assertEqual(r.inbox.method_calls, expected, 'get old msg')

        expected = [call.reply('body')]
        self.assertEqual(oldMsg.method_calls, expected, 'reply old')

        expected = [call.reply('answer forwarded')]
        self.assertEqual(msg.method_calls, expected, 'reply new')

        self.assertEqual(helper.method_calls, [], 'no helper calls')
Ejemplo n.º 3
0
    def test_AnswerMail_Success(self):
        r = MagicMock()

        msg = MagicMock()
        msg.subreddit = None
        msg.author.name = 'user'
        msg.id = 'msgids'
        msg.distinguished = None
        msg.subject = 'sub'
        msg.body = 'body'
        pmUserCache = { }

        helper = MagicMock()
        helper.parseText = MagicMock(return_value=(['card'], 'text'))

        # test
        hsbot.answerPM(r, msg, pmUserCache, helper)

        self.assertTrue('user' in pmUserCache, 'user added to cache')

        self.assertEqual(r.method_calls, [], 'no reddit calls')
        expected = [call.parseText('sub body')]
        self.assertEqual(helper.method_calls, expected, 'parseText')
        expected = [call.reply('text')]
        self.assertEqual(msg.method_calls, expected, 'reply')
Ejemplo n.º 4
0
    def test_AnswerMail_Success(self):
        r = MagicMock()

        msg = MagicMock()
        msg.subreddit = None
        msg.author.name = 'user'
        msg.id = 'msgids'
        msg.distinguished = None
        msg.subject = 'sub'
        msg.body = 'body'
        pmUserCache = {}

        helper = MagicMock()
        helper.parseText = MagicMock(return_value=(['card'], 'text'))

        # test
        hsbot.answerPM(r, msg, pmUserCache, helper)

        self.assertTrue('user' in pmUserCache, 'user added to cache')

        self.assertEqual(r.method_calls, [], 'no reddit calls')
        expected = [call.parseText('sub body')]
        self.assertEqual(helper.method_calls, expected, 'parseText')
        expected = [call.reply('text')]
        self.assertEqual(msg.method_calls, expected, 'reply')