Ejemplo n.º 1
0
    def test_validation_failed(self):
        factory = RequestFactory()

        request = factory.post(
            '/path',
            dict(
                token='token',
                team_id='team_id',
                team_domain='team_domain',
                enterprise_id='enterprise_id',
                enterprise_name='enterprise_name',
                channel_id='channel_id',
                channel_name='channel_name',
                user_id='user_id',
                user_name='user_name',
                command='command',
                text='text',
                response_url='responseurl',
                trigger_id='trigger_id',
            ))

        with mock.patch('slack_utils.decorators.verify_request',
                        return_value=True):
            view = CommandView()
            with mock.patch.object(
                    view, 'handle_command',
                    return_value=HttpResponse()) as handle_command_mock:
                resp = view.post(request)

        self.assertEqual(resp.status_code, 400)
        self.assertFalse(handle_command_mock.called)
Ejemplo n.º 2
0
    def test_slash_command_without_text(self):
        factory = RequestFactory()
        request = factory.post(
            "/path",
            dict(
                token="token",
                team_id="team_id",
                team_domain="team_domain",
                enterprise_id="enterprise_id",
                enterprise_name="enterprise_name",
                channel_id="channel_id",
                channel_name="channel_name",
                user_id="user_id",
                user_name="user_name",
                command="command_without_text",
                response_url="http://responseurl.com/path",
                trigger_id="trigger_id",
            ),
        )

        with mock.patch("slack_utils.decorators.verify_request",
                        return_value=True):
            view = CommandView()
            with mock.patch("slack_utils.views.registry") as registry_mock:
                registry_mock.register("command_without_text", lambda: None)
                resp = view.post(request)
        self.assertEqual(resp.status_code, 200, resp.content)
Ejemplo n.º 3
0
    def test_parses_slack_arguments(self):
        factory = RequestFactory()

        request = factory.post(
            '/path',
            dict(
                token='token',
                team_id='team_id',
                team_domain='team_domain',
                enterprise_id='enterprise_id',
                enterprise_name='enterprise_name',
                channel_id='channel_id',
                channel_name='channel_name',
                user_id='user_id',
                user_name='user_name',
                command='command',
                text='text',
                response_url='http://responseurl.com/path',
                trigger_id='trigger_id',
            ))

        with mock.patch('slack_utils.decorators.verify_request',
                        return_value=True):
            view = CommandView()
            with mock.patch.object(
                    view, 'handle_command',
                    return_value=HttpResponse()) as handle_command_mock:
                resp = view.post(request)

        self.assertEqual(resp.status_code, 200, resp.content)
        self.assertTrue(handle_command_mock.called)
        self.assertTupleEqual(handle_command_mock.call_args[0],
                              ('command', 'text'))
        self.assertDictEqual(
            handle_command_mock.call_args[1],
            dict(
                token='token',
                team_id='team_id',
                team_domain='team_domain',
                enterprise_id='enterprise_id',
                enterprise_name='enterprise_name',
                channel_id='channel_id',
                channel_name='channel_name',
                user_id='user_id',
                user_name='user_name',
                response_url='http://responseurl.com/path',
                trigger_id='trigger_id',
            ))