Esempio n. 1
0
 def test_recompile_request(self):
     # Create the comment that will be recompiled.
     body = ("+/u/{user} python 3\n\n    x = input()\n    print(x)"
             "\n\n".format(user=self.user))
     original = self.Comment(body=body, reddit_session=self.r)
     self.r._get_sub_comment = original
     # Message that makes the recompile request.
     body = "--recompile {link}".format(link=original.permalink)
     new = self.Message(body=body, reddit_session=self.r)
     with patch('{}.cb.compile'.format(__name__)) as mock_compile:
         mock_compile.return_value = {
             'cmpinfo': '',
             'error': 'OK',
             'input': "Hello World",
             'langId': 116,
             'link': '',
             'langName': "Python 3",
             'output': "Hello World\n",
             'public': True,
             'result': 15,
             'signal': 0,
             'source': "x = input()\nprint(x)",
             'status': 0,
             'stderr': "",
         }
         cb.process_unread(new, self.r)
     self.assertTrue(original._replied_to)
Esempio n. 2
0
 def test_recompile_edit(self):
     # Ensure that if there is an existing reply from a bot on a 
     # comment that is being recompiled, the existing reply is 
     # editing instead of making a new comment.
     def compile(*args, **kwargs):
         return {
             'cmpinfo': '', 'error': 'OK', 'input': "Hello World",
             'langId': 116, 'link': '', 'langName': "Python 3",
             'output': "Test\n", 'public': True, 'result': 15,
             'signal': 0, 'source': "print(\"Test\")", 'status': 0,
             'stderr': "",
         }
         
     cb.compile = compile
     existing_reply = self.Comment(author=self.Author(self.user))
     body = ("+/u/{user} python 3\n\n    print(\"test\")\n\n"
            "\n\n".format(user=self.user))
     
     replies = [existing_reply]
     original = self.Comment(body=body, reddit_session=self.r, 
                             replies=replies)
     self.r._get_sub_comment = original
     
     body = "--recompile {link}".format(link=original.permalink)
     new = self.Message(body=body, reddit_session=self.r)
     cb.process_unread(new, self.r)
     self.assertTrue(existing_reply._edited)
     self.assertIn("Output:\n\n    Test", existing_reply._edit_text)
     self.assertFalse(original._replied_to)
Esempio n. 3
0
    def test_recompile_edit(self):
        """Ensure that if there is an existing reply from a bot on a
        comment that is being recompiled, the existing reply is
        editing instead of making a new comment.
        """
        body = ("+/u/{user} python 3\n\n    print(\"test\")\n\n"
               "\n\n".format(user=self.user))
        existing_reply = self.Comment(author=self.Author(self.user))
        replies = [
            self.Comment(author=self.Author('OneCommenter')),
            existing_reply,
            self.Comment(author=self.Author('AnotherCommenter'))
        ]
        original = self.Comment(body=body, reddit_session=self.r,
                                replies=replies)
        self.r._get_sub_comment = original

        body = "--recompile {link}".format(link=original.permalink)
        new = self.Message(body=body, reddit_session=self.r)

        with patch('{}.cb.compile'.format(__name__)) as mock_compile:
            mock_compile.return_value = {
                'cmpinfo': '', 'error': 'OK', 'input': "Hello World",
                'langId': 116, 'link': '', 'langName': "Python 3",
                'output': "Test\n", 'public': True, 'result': 15,
                'signal': 0, 'source': "print(\"Test\")", 'status': 0,
                'stderr': "",
            }
            cb.process_unread(new, self.r)
        self.assertTrue(existing_reply._edited)
        self.assertIn("Output:\n\n    Test", existing_reply._edit_text)
        self.assertFalse(original._replied_to)
Esempio n. 4
0
    def test_process_reply(self):
        def compile(*args, **kwargs):
            return {
                'cmpinfo': '',
                'error': 'OK',
                'input': "Hello World",
                'langId': 116,
                'link': '',
                'langName': "Python 3",
                'output': "Hello World\n",
                'public': True,
                'result': 15,
                'signal': 0,
                'source': "x = input()\nprint(x)",
                'status': 0,
                'stderr': "",
            }

        cb.compile = compile
        body = ("+/u/{user} python 3\n\n    x = input()\n    print(x)"
                "\n\n".format(user=self.user))
        new = self.Comment(body=body, reddit_session=self.r)
        cb.process_unread(new, self.r)
        self.assertTrue(new._replied_to)
        self.assertIn("Output:\n\n    Hello World", new._reply_text)
Esempio n. 5
0
 def test_recompile_user_permissions(self):
     # Ensure users aren't allowed to make recompile requests of behalf
     # of other users.
     original = self.Comment(reddit_session=self.r,
                             author=self.Author("Author-1"))
     self.r._get_sub_comment = original
     body = "--recompile {link}".format(link=original.permalink)
     new = self.Message(body=body, reddit_session=self.r,
                        author=self.Author("Author-2"))
     cb.process_unread(new, self.r)
     self.assertFalse(original._replied_to)
     self.assertTrue(new._replied_to)
Esempio n. 6
0
 def test_recompile_user_permissions(self):
     # Ensure users aren't allowed to make recompile requests of behalf
     # of other users.
     original = self.Comment(reddit_session=self.r,
                             author=self.Author("Author-1"))
     self.r._get_sub_comment = original
     body = "--recompile {link}".format(link=original.permalink)
     new = self.Message(body=body,
                        reddit_session=self.r,
                        author=self.Author("Author-2"))
     cb.process_unread(new, self.r)
     self.assertFalse(original._replied_to)
     self.assertTrue(new._replied_to)
Esempio n. 7
0
 def test_process_reply(self):
     body = ("+/u/{user} python 3\n\n    x = input()\n    print(x)"
             "\n\n".format(user=self.user))
     new = self.Comment(body=body, reddit_session=self.r)
     with patch('{}.cb.compile'.format(__name__)) as mock_compile:
         mock_compile.return_value = {
             'cmpinfo': '', 'error': 'OK', 'input': "Hello World",
             'langId': 116, 'link': '', 'langName': "Python 3",
             'output': "Hello World\n", 'public': True, 'result': 15,
             'signal': 0, 'source': "x = input()\nprint(x)", 'status': 0,
             'stderr': "",
         }
         cb.process_unread(new, self.r)
     self.assertTrue(new._replied_to)
     self.assertIn("Output:\n\n    Hello World", new._reply_text)
Esempio n. 8
0
 def test_process_reply(self):
 
     def compile(*args, **kwargs):
         return {
             'cmpinfo': '', 'error': 'OK', 'input': "Hello World",
             'langId': 116, 'link': '', 'langName': "Python 3",
             'output': "Hello World\n", 'public': True, 'result': 15,
             'signal': 0, 'source': "x = input()\nprint(x)", 'status': 0,
             'stderr': "",
         }
     
     cb.compile = compile
     body = ("+/u/{user} python 3\n\n    x = input()\n    print(x)"
             "\n\n".format(user=self.user))
     new = self.Comment(body=body, reddit_session=self.r)
     cb.process_unread(new, self.r)
     self.assertTrue(new._replied_to)
     self.assertIn("Output:\n\n    Hello World", new._reply_text)
Esempio n. 9
0
 def test_recompile_request(self):
     # Create the comment that will be recompiled.
     body = ("+/u/{user} python 3\n\n    x = input()\n    print(x)"
             "\n\n".format(user=self.user))
     original = self.Comment(body=body, reddit_session=self.r)
     self.r._get_sub_comment = original
     # Message that makes the recompile request.
     body = "--recompile {link}".format(link=original.permalink)
     new = self.Message(body=body, reddit_session=self.r)
     with patch('{}.cb.compile'.format(__name__)) as mock_compile:
         mock_compile.return_value = {
             'cmpinfo': '', 'error': 'OK', 'input': "Hello World",
             'langId': 116, 'link': '', 'langName': "Python 3",
             'output': "Hello World\n", 'public': True, 'result': 15,
             'signal': 0, 'source': "x = input()\nprint(x)", 'status': 0,
             'stderr': "",
         }
         cb.process_unread(new, self.r)
     self.assertTrue(original._replied_to)
Esempio n. 10
0
    def test_recompile_edit(self):
        """Ensure that if there is an existing reply from a bot on a
        comment that is being recompiled, the existing reply is
        editing instead of making a new comment.
        """
        body = ("+/u/{user} python 3\n\n    print(\"test\")\n\n"
                "\n\n".format(user=self.user))
        existing_reply = self.Comment(author=self.Author(self.user))
        replies = [
            self.Comment(author=self.Author('OneCommenter')), existing_reply,
            self.Comment(author=self.Author('AnotherCommenter'))
        ]
        original = self.Comment(body=body,
                                reddit_session=self.r,
                                replies=replies)
        self.r._get_sub_comment = original

        body = "--recompile {link}".format(link=original.permalink)
        new = self.Message(body=body, reddit_session=self.r)

        with patch('{}.cb.compile'.format(__name__)) as mock_compile:
            mock_compile.return_value = {
                'cmpinfo': '',
                'error': 'OK',
                'input': "Hello World",
                'langId': 116,
                'link': '',
                'langName': "Python 3",
                'output': "Test\n",
                'public': True,
                'result': 15,
                'signal': 0,
                'source': "print(\"Test\")",
                'status': 0,
                'stderr': "",
            }
            cb.process_unread(new, self.r)
        self.assertTrue(existing_reply._edited)
        self.assertIn("Output:\n\n    Test", existing_reply._edit_text)
        self.assertFalse(original._replied_to)
Esempio n. 11
0
    def test_recompile_edit(self):
        # Ensure that if there is an existing reply from a bot on a
        # comment that is being recompiled, the existing reply is
        # editing instead of making a new comment.
        def compile(*args, **kwargs):
            return {
                'cmpinfo': '',
                'error': 'OK',
                'input': "Hello World",
                'langId': 116,
                'link': '',
                'langName': "Python 3",
                'output': "Test\n",
                'public': True,
                'result': 15,
                'signal': 0,
                'source': "print(\"Test\")",
                'status': 0,
                'stderr': "",
            }

        cb.compile = compile
        existing_reply = self.Comment(author=self.Author(self.user))
        body = ("+/u/{user} python 3\n\n    print(\"test\")\n\n"
                "\n\n".format(user=self.user))

        replies = [existing_reply]
        original = self.Comment(body=body,
                                reddit_session=self.r,
                                replies=replies)
        self.r._get_sub_comment = original

        body = "--recompile {link}".format(link=original.permalink)
        new = self.Message(body=body, reddit_session=self.r)
        cb.process_unread(new, self.r)
        self.assertTrue(existing_reply._edited)
        self.assertIn("Output:\n\n    Test", existing_reply._edit_text)
        self.assertFalse(original._replied_to)
Esempio n. 12
0
 def test_process_reply(self):
     body = ("+/u/{user} python 3\n\n    x = input()\n    print(x)"
             "\n\n".format(user=self.user))
     new = self.Comment(body=body, reddit_session=self.r)
     with patch('{}.cb.compile'.format(__name__)) as mock_compile:
         mock_compile.return_value = {
             'cmpinfo': '',
             'error': 'OK',
             'input': "Hello World",
             'langId': 116,
             'link': '',
             'langName': "Python 3",
             'output': "Hello World\n",
             'public': True,
             'result': 15,
             'signal': 0,
             'source': "x = input()\nprint(x)",
             'status': 0,
             'stderr': "",
         }
         cb.process_unread(new, self.r)
     self.assertTrue(new._replied_to)
     self.assertIn("Output:\n\n    Hello World", new._reply_text)
Esempio n. 13
0
 def test_banned_filter(self):
     cb.BANNED_USERS.add("Banned-User-01")
     new = self.Comment(author=self.Author(name="Banned-User-01"))
     cb.process_unread(new, self.r)
     self.assertFalse(new._replied_to)
Esempio n. 14
0
 def test_help_request(self):
     new = self.Message(body="--help", reddit_session=self.r)
     cb.process_unread(new, self.r)
     self.assertTrue(self.r._sent_message)
     self.assertIn(cb.HELP_TEXT, self.r._message_text)
Esempio n. 15
0
 def test_banned_filter(self):
     cb.BANNED_USERS.add("Banned-User-01")
     new = self.Comment(author=self.Author(name="Banned-User-01"))
     cb.process_unread(new, self.r)
     self.assertFalse(new._replied_to)
Esempio n. 16
0
 def test_help_request(self):
     new = self.Message(body="--help", reddit_session=self.r)
     cb.process_unread(new, self.r)
     self.assertTrue(self.r._sent_message)
     self.assertIn(cb.HELP_TEXT, self.r._message_text)