def test_done(self, mock_reddit):
        mock_reddit.comment = MagicMock(name='comment',
                                        return_value=self.comment)

        process_comment(self.comment.id)
        # TODO: more to come when actual functionality is built-out

        mock_reddit.comment.assert_any_call(self.comment.id)
    def test_misspelled_done(self, mock_reddit, mock_signature):
        mock_reddit.comment = MagicMock(name='comment',
                                        return_value=self.comment)

        self.comment.body = 'deno'
        process_comment(self.comment.id)
        # TODO: more to come when actual functionality is built-out

        mock_reddit.comment.assert_any_call(self.comment.id)
    def test_override_as_anon(self, mock_reddit):
        mock_reddit.comment = MagicMock(name='comment',
                                        return_value=self.comment)

        self.comment.body = '!override'
        # TODO: Test exception being thrown because unprivileged user???
        process_comment(self.comment.id)
        # TODO: more to come when actual functionality is built-out

        mock_reddit.comment.assert_any_call(self.comment.id)
    def test_other_bot_commented(self, mod_intervention, mock_reddit,
                                 mock_signature):
        mock_reddit.comment = MagicMock(name='comment',
                                        return_value=self.comment)

        self.comment.author = generate_redditor(username='******')
        process_comment(self.comment.id)

        assert_no_tasks_called()
        mock_reddit.comment.assert_called_with(self.comment.id)
        mod_intervention.assert_not_called()
    def test_import_tasks(self, mod_intervention, mock_reddit, mock_signature):
        mock_reddit.comment = MagicMock(name='comment',
                                        return_value=self.comment)

        process_comment(self.comment.id)

        for mod_task in ['claim_post']:
            mock_signature.assert_any_call(
                f'tor_worker.role_moderator.tasks.{mod_task}')
        for anon_task in ['accept_code_of_conduct', 'unhandled_comment']:
            mock_signature.assert_any_call(
                f'tor_worker.role_anyone.tasks.{anon_task}')
    def test_refuse(self, mod_intervention, mock_reddit, mock_signature):
        mock_reddit.comment = MagicMock(name='comment',
                                        return_value=self.comment)

        self.comment.body = 'Nah, screw it. I can do it later'
        process_comment(self.comment.id)

        signature('tor_worker.role_anyone.tasks.unhandled_comment').delay \
            .assert_called_once()
        assert_only_tasks_called(
            'tor_worker.role_anyone.tasks.unhandled_comment',
        )
        mock_reddit.comment.assert_called_with(self.comment.id)
        mod_intervention.assert_called_once()
    def test_disagree(self, mod_intervention, mock_reddit, mock_signature):
        mock_reddit.comment = MagicMock(name='comment',
                                        return_value=self.comment)

        self.comment.body = 'Nah, go screw yourself.'
        process_comment(self.comment.id)

        signature('tor_worker.role_anyone.tasks.unhandled_comment').delay \
            .assert_called_once_with(comment_id=self.comment.id,
                                     body=self.comment.body)
        assert_only_tasks_called(
            'tor_worker.role_anyone.tasks.unhandled_comment'
        )
        mock_reddit.comment.assert_called_with(self.comment.id)
        mod_intervention.assert_called_once()
    def test_weird_response(self, mock_reddit, mock_signature):
        mock_reddit.comment = MagicMock(name='comment',
                                        return_value=self.comment)

        self.comment.body = "adsflkj232oiqqw123lk1209uasd;"
        process_comment(self.comment.id)
        # TODO: more to come when actual functionality is built-out

        signature('tor_worker.role_anyone.tasks.unhandled_comment').delay \
            .assert_called_once()

        assert_only_tasks_called(
            'tor_worker.role_anyone.tasks.unhandled_comment',
        )
        mock_reddit.comment.assert_any_call(self.comment.id)
    def test_claim(self, mod_intervention, mock_reddit, mock_signature):
        mock_reddit.comment = MagicMock(name='comment',
                                        return_value=self.comment)

        self.comment.body = 'I claim this land in the name of France!'
        process_comment(self.comment.id)

        signature('tor_worker.role_moderator.tasks.claim_post').delay \
            .assert_called_once_with(self.comment.id)

        assert_only_tasks_called(
            'tor_worker.role_moderator.tasks.claim_post',
        )
        mock_reddit.comment.assert_called_with(self.comment.id)
        mod_intervention.assert_called_once()
    def test_agree(self, mod_intervention, mock_reddit, mock_signature):
        mock_reddit.comment = MagicMock(name='comment',
                                        return_value=self.comment)

        self.comment.body = 'I accept the consequences'
        process_comment(self.comment.id)

        mock_reddit.comment.assert_called_with(self.comment.id)

        signature('tor_worker.role_anyone.tasks.accept_code_of_conduct').delay \
            .assert_called_once_with(self.comment.author.name)
        signature('tor_worker.role_moderator.tasks.claim_post').delay \
            .assert_called_once_with(self.comment.id, verify=False,
                                     first_claim=True)

        assert_only_tasks_called(
            'tor_worker.role_anyone.tasks.accept_code_of_conduct',
            'tor_worker.role_moderator.tasks.claim_post',
        )
        mod_intervention.assert_called_once()