def test_Forward_PM(self): r = MagicMock() msg = MagicMock() msg.subreddit = None msg.author.name = 'user' msg.id = 'msgidpm' msg.distinguished = None msg.subject = 'sub' msg.body = 'body' pmUserCache = { } helper = MagicMock() helper.parseText = MagicMock(return_value=([], '')) redMsg = MagicMock() r.redditor = MagicMock(return_value=redMsg) # test hsbot.answerPM(r, msg, pmUserCache, helper) self.assertTrue('user' in pmUserCache, 'user added to cache') expected = [call.redditor(credentials.admin_username)] self.assertEqual(r.method_calls, expected, 'get redditor') expected = [call.message('#msgidpm /u/user: "******"', msg.body)] self.assertEqual(redMsg.method_calls, expected, 'set message') expected = [call.parseText('sub body')] self.assertEqual(helper.method_calls, expected, 'parseText') self.assertEqual(msg.method_calls, [], 'no reply')
def test_Forward_PM(self): r = MagicMock() msg = MagicMock() msg.subreddit = None msg.author.name = 'user' msg.id = 'msgidpm' msg.distinguished = None msg.subject = 'sub' msg.body = 'body' pmUserCache = {} helper = MagicMock() helper.parseText = MagicMock(return_value=([], '')) redMsg = MagicMock() r.redditor = MagicMock(return_value=redMsg) # test hsbot.answerPM(r, msg, pmUserCache, helper) self.assertTrue('user' in pmUserCache, 'user added to cache') expected = [call.redditor(credentials.admin_username)] self.assertEqual(r.method_calls, expected, 'get redditor') expected = [call.message('#msgidpm /u/user: "******"', msg.body)] self.assertEqual(redMsg.method_calls, expected, 'set message') expected = [call.parseText('sub body')] self.assertEqual(helper.method_calls, expected, 'parseText') self.assertEqual(msg.method_calls, [], 'no reply')
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')
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')