def process_event(self, event): # type: (Dict[Text, Any]) -> Tuple[Dict[str, Any], Any] rest_operation = { 'method': 'POST', 'relative_url_path': '', 'base_url': self.base_url, 'request_kwargs': {} } if event['message']['type'] == 'private': raise NotImplementedError( "Private messaging service not supported.") service = get_service_profile(event['user_profile_id'], str(self.service_name)) request_data = [ ("token", self.token), ("team_id", event['message']['sender_realm_str']), ("team_domain", email_to_domain(event['message']['sender_email'])), ("channel_id", event['message']['stream_id']), ("channel_name", event['message']['display_recipient']), ("timestamp", event['message']['timestamp']), ("user_id", event['message']['sender_id']), ("user_name", event['message']['sender_full_name']), ("text", event['command']), ("trigger_word", event['trigger']), ("service_id", service.id), ] return rest_operation, request_data
def process_event(self, event): # type: (Dict[Text, Any]) -> Tuple[Dict[str, Any], Any] rest_operation = {'method': 'POST', 'relative_url_path': '', 'base_url': self.base_url, 'request_kwargs': {}} if event['message']['type'] == 'private': raise NotImplementedError("Private messaging service not supported.") service = get_service_profile(event['user_profile_id'], str(self.service_name)) request_data = [("token", self.token), ("team_id", event['message']['sender_realm_str']), ("team_domain", email_to_domain(event['message']['sender_email'])), ("channel_id", event['message']['stream_id']), ("channel_name", event['message']['display_recipient']), ("timestamp", event['message']['timestamp']), ("user_id", event['message']['sender_id']), ("user_name", event['message']['sender_full_name']), ("text", event['command']), ("trigger_word", event['trigger']), ("service_id", service.id), ] return rest_operation, request_data
def test_message_embedded_bot_with_invalid_service(self) -> None: user_profile = self.example_user("othello") self.create_test_bot(short_name='embedded', user_profile=user_profile, bot_type=UserProfile.EMBEDDED_BOT, service_name='helloworld') bot_profile = get_user("*****@*****.**", get_realm('zulip')) service_profile = get_service_profile(bot_profile.id, 'helloworld') service_profile.name = 'invalid' service_profile.save() with patch('logging.error') as logging_error_mock: self.send_stream_message(user_profile.email, "Denmark", content="@**{}** foo".format(bot_profile.full_name), topic_name="bar") logging_error_mock.assert_called_once_with( "Error: User {} has bot with invalid embedded bot service invalid".format(bot_profile.id))
def test_message_embedded_bot_with_invalid_service(self) -> None: user_profile = self.example_user("othello") self.create_test_bot(short_name='embedded', user_profile=user_profile, bot_type=UserProfile.EMBEDDED_BOT, service_name='helloworld') bot_profile = get_user("*****@*****.**", get_realm('zulip')) service_profile = get_service_profile(bot_profile.id, 'helloworld') service_profile.name = 'invalid' service_profile.save() with patch('logging.error') as logging_error_mock: self.send_stream_message(user_profile, "Denmark", content="@**{}** foo".format(bot_profile.full_name), topic_name="bar") logging_error_mock.assert_called_once_with( "Error: User {} has bot with invalid embedded bot service invalid".format(bot_profile.id))
def test_message_embedded_bot_with_invalid_service(self) -> None: user_profile = self.example_user("othello") self.create_test_bot(short_name='embedded', user_profile=user_profile, bot_type=UserProfile.EMBEDDED_BOT, service_name='helloworld') bot_profile = get_user("*****@*****.**", get_realm('zulip')) service_profile = get_service_profile(bot_profile.id, 'helloworld') service_profile.name = 'invalid' service_profile.save() with self.assertLogs(level='ERROR') as m: self.send_stream_message( user_profile, "Denmark", content=f"@**{bot_profile.full_name}** foo", topic_name="bar") self.assertRegexpMatches( m.output[0], r'ERROR:root:Error: User [0-9]* has bot with invalid embedded bot service invalid' )
def test_message_embedded_bot_with_invalid_service(self) -> None: user_profile = self.example_user("othello") self.create_test_bot( short_name="embedded", user_profile=user_profile, bot_type=UserProfile.EMBEDDED_BOT, service_name="helloworld", ) bot_profile = get_user("*****@*****.**", get_realm("zulip")) service_profile = get_service_profile(bot_profile.id, "helloworld") service_profile.name = "invalid" service_profile.save() with self.assertLogs(level="ERROR") as m: self.send_stream_message( user_profile, "Denmark", content=f"@**{bot_profile.full_name}** foo", topic_name="bar", ) self.assertEqual( m.output[0], f"ERROR:root:Error: User {bot_profile.id} has bot with invalid embedded bot service invalid", )