def setUp(self): self.replier = Replier(TestParser(), TEST_USER, TEST_PASS, TEST_SUB, TEST_USER_AGENT, TEST_LIMIT) self.bots_comment = CommentMock(TEST_USER, []) self.other_comment = CommentMock('Siegmeyer', ['Gwyn, Gwyndolin, Gwynevere']) self.blacklist_comment = CommentMock('test_user', []) self.already_replied = CommentMock('Solaire', [TEST_USER, 'Crestfallen', 'Andre'])
class TestSetupBlacklist(unittest.TestCase): def setUp(self): self.replier = Replier(TestParser(), TEST_USER, TEST_PASS, TEST_SUB, TEST_USER_AGENT, TEST_LIMIT) def test_blacklist_contains_current_user(self): self.assertIn(TEST_USER.lower(), self.replier._setup_blacklist("BLACKLIST.txt")) def test_blacklist_only_contains_user_if_no_file(self): self.assertEqual([TEST_USER.lower()], self.replier._setup_blacklist("blah"))
def main(): bot = Replier( Parser(), s.user, s.password, 'all', debug=True ) bot.start()
def setUp(self): self.replier = Replier(TestParser(), TEST_USER, TEST_PASS, TEST_SUB, TEST_USER_AGENT, TEST_LIMIT) self.comments = [ CommentMock('Laurentius'), CommentMock('Tarkus', [], "TAAAAARRRRKUUUUSSS!!"), CommentMock('Logan', [], 'Big Hats are Best Hats'), CommentMock('Giant Dad', [], 'Git Gud'), CommentMock('Sif'), CommentMock(TEST_USER) ]
class TestStart(unittest.TestCase): def setUp(self): self.replier = Replier(TestParser(), TEST_USER, TEST_PASS, TEST_SUB, TEST_USER_AGENT, TEST_LIMIT) @mock.patch.object(Replier, "_login") @mock.patch.object(praw.helpers, "comment_stream") @mock.patch.object(Replier, "_main_loop") def test_start(self, mock_loop, mock_stream, mock_login): self.replier.start() mock_loop.assert_called_with(mock_stream.return_value) mock_stream.assert_called_with(self.replier.r, self.replier.subreddits, self.replier.limit) mock_login.assert_called_with()
class TestSetupBlacklist(unittest.TestCase): def setUp(self): self.replier = Replier(TestParser(), TEST_USER, TEST_PASS, TEST_SUB, TEST_USER_AGENT, TEST_LIMIT) def test_blacklist_contains_current_user(self): self.assertIn(TEST_USER.lower(), self.replier._setup_blacklist('BLACKLIST.txt')) def test_blacklist_only_contains_user_if_no_file(self): self.assertEqual([TEST_USER.lower()], self.replier._setup_blacklist('blah'))
class TestStart(unittest.TestCase): def setUp(self): self.replier = Replier(TestParser(), TEST_USER, TEST_PASS, TEST_SUB, TEST_USER_AGENT, TEST_LIMIT) @mock.patch.object(Replier, '_login') @mock.patch.object(praw.helpers, 'comment_stream') @mock.patch.object(Replier, '_main_loop') def test_start(self, mock_loop, mock_stream, mock_login): self.replier.start() mock_loop.assert_called_with(mock_stream.return_value) mock_stream.assert_called_with(self.replier.r, self.replier.subreddits, self.replier.limit) mock_login.assert_called_with()
class TestMakeComment(unittest.TestCase): def setUp(self): self.replier = Replier(TestParser(), TEST_USER, TEST_PASS, TEST_SUB, TEST_USER_AGENT, TEST_LIMIT) self.comment = CommentMock("Ornstein", [], "Pikachu") @mock.patch.object(CommentMock, "reply") def test_non_debug_reply(self, reply_mock): self.replier._make_comment(self.comment, "Pikachu") reply_mock.assert_called_with("Pikachu") @mock.patch.object(CommentMock, "reply") def test_debug_reply(self, reply_mock): self.replier.debug = True self.replier._make_comment(self.comment, "Pikachu") self.assertFalse(reply_mock.called)
class TestMakeComment(unittest.TestCase): def setUp(self): self.replier = Replier(TestParser(), TEST_USER, TEST_PASS, TEST_SUB, TEST_USER_AGENT, TEST_LIMIT) self.comment = CommentMock('Ornstein', [], 'Pikachu') @mock.patch.object(CommentMock, 'reply') def test_non_debug_reply(self, reply_mock): self.replier._make_comment(self.comment, 'Pikachu') reply_mock.assert_called_with('Pikachu') @mock.patch.object(CommentMock, 'reply') def test_debug_reply(self, reply_mock): self.replier.debug = True self.replier._make_comment(self.comment, 'Pikachu') self.assertFalse(reply_mock.called)
def setUp(self): self.replier = Replier(TestParser(), TEST_USER, TEST_PASS, TEST_SUB, TEST_USER_AGENT, TEST_LIMIT) self.comments = [ CommentMock("Laurentius"), CommentMock("Tarkus", [], "TAAAAARRRRKUUUUSSS!!"), CommentMock("Logan", [], "Big Hats are Best Hats"), CommentMock("Giant Dad", [], "Git Gud"), CommentMock("Sif"), CommentMock(TEST_USER), ]
class TestSearchComments(unittest.TestCase): def setUp(self): self.replier = Replier(TestParser(), TEST_USER, TEST_PASS, TEST_SUB, TEST_USER_AGENT, TEST_LIMIT) self.comments = [ CommentMock("Laurentius"), CommentMock("Tarkus", [], "TAAAAARRRRKUUUUSSS!!"), CommentMock("Logan", [], "Big Hats are Best Hats"), CommentMock("Giant Dad", [], "Git Gud"), CommentMock("Sif"), CommentMock(TEST_USER), ] def test_searching(self): """ Basic test for comments being replied to. Keep in mind that it's your responsibility to test your own replier """ self.replier._search_comments(self.comments) self.assertEqual(self.replier.comments_replied_to, 2)
class TestSearchComments(unittest.TestCase): def setUp(self): self.replier = Replier(TestParser(), TEST_USER, TEST_PASS, TEST_SUB, TEST_USER_AGENT, TEST_LIMIT) self.comments = [ CommentMock('Laurentius'), CommentMock('Tarkus', [], "TAAAAARRRRKUUUUSSS!!"), CommentMock('Logan', [], 'Big Hats are Best Hats'), CommentMock('Giant Dad', [], 'Git Gud'), CommentMock('Sif'), CommentMock(TEST_USER) ] def test_searching(self): ''' Basic test for comments being replied to. Keep in mind that it's your responsibility to test your own replier ''' self.replier._search_comments(self.comments) self.assertEqual(self.replier.comments_replied_to, 2)
class TestShouldReply(unittest.TestCase): def setUp(self): self.replier = Replier(TestParser(), TEST_USER, TEST_PASS, TEST_SUB, TEST_USER_AGENT, TEST_LIMIT) self.bots_comment = CommentMock(TEST_USER, []) self.other_comment = CommentMock("Siegmeyer", ["Gwyn, Gwyndolin, Gwynevere"]) self.blacklist_comment = CommentMock("test_user", []) self.already_replied = CommentMock("Solaire", [TEST_USER, "Crestfallen", "Andre"]) def test_should_not_reply_to_self(self): self.replier._should_reply(self.bots_comment) self.assertFalse(self.replier._should_reply(self.bots_comment)) def test_should_not_reply_to_blacklist(self): self.assertFalse(self.replier._should_reply(self.blacklist_comment)) def test_should_not_reply_to_same_comment_twice(self): self.assertFalse(self.replier._should_reply(self.already_replied)) def test_should_reply_to_others(self): self.assertTrue(self.replier._should_reply(self.other_comment))
class TestShouldReply(unittest.TestCase): def setUp(self): self.replier = Replier(TestParser(), TEST_USER, TEST_PASS, TEST_SUB, TEST_USER_AGENT, TEST_LIMIT) self.bots_comment = CommentMock(TEST_USER, []) self.other_comment = CommentMock('Siegmeyer', ['Gwyn, Gwyndolin, Gwynevere']) self.blacklist_comment = CommentMock('test_user', []) self.already_replied = CommentMock('Solaire', [TEST_USER, 'Crestfallen', 'Andre']) def test_should_not_reply_to_self(self): self.replier._should_reply(self.bots_comment) self.assertFalse(self.replier._should_reply(self.bots_comment)) def test_should_not_reply_to_blacklist(self): self.assertFalse(self.replier._should_reply(self.blacklist_comment)) def test_should_not_reply_to_same_comment_twice(self): self.assertFalse(self.replier._should_reply(self.already_replied)) def test_should_reply_to_others(self): self.assertTrue(self.replier._should_reply(self.other_comment))
def setUp(self): self.replier = Replier(TestParser(), TEST_USER, TEST_PASS, TEST_SUB, TEST_USER_AGENT, TEST_LIMIT) self.comment = CommentMock("Ornstein", [], "Pikachu")
def setUp(self): self.replier = Replier(TestParser(), TEST_USER, TEST_PASS, TEST_SUB, TEST_USER_AGENT, TEST_LIMIT)
def setUp(self): self.replier = Replier(TestParser(), TEST_USER, TEST_PASS, TEST_SUB, TEST_USER_AGENT, TEST_LIMIT) self.comment = CommentMock('Ornstein', [], 'Pikachu')
def setUp(self): self.replier = Replier(TestParser(), TEST_USER, TEST_PASS, TEST_SUB, TEST_USER_AGENT, TEST_LIMIT) self.bots_comment = CommentMock(TEST_USER, []) self.other_comment = CommentMock("Siegmeyer", ["Gwyn, Gwyndolin, Gwynevere"]) self.blacklist_comment = CommentMock("test_user", []) self.already_replied = CommentMock("Solaire", [TEST_USER, "Crestfallen", "Andre"])