mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 14:03:30 +00:00 
			
		
		
		
	The test helper here was taking an "expected_topic" parameter that it just ignored, and then the dialogflow tests were passing in expected messages in that slot, so the actual "expected_message" var was "None" and was ignored. So the tests weren't testing anything. Now we eliminate the crufty expected_topic parameter and require an actual value for "expected_message". I also clean up the mypy type for content_type, and I remove the `content_type is None` check, since all callers either pass in a str content type or default to "application/json".
		
			
				
	
	
		
			47 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
from zerver.lib.test_classes import WebhookTestCase
 | 
						|
 | 
						|
 | 
						|
class DialogflowHookTests(WebhookTestCase):
 | 
						|
    URL_TEMPLATE = "/api/v1/external/dialogflow?api_key={api_key}&email=AARON@zulip.com"
 | 
						|
 | 
						|
    def test_dialogflow_default(self) -> None:
 | 
						|
        self.url = self.build_webhook_url(
 | 
						|
            email="AARON@zulip.com",
 | 
						|
            username="aaron",
 | 
						|
            user_ip="127.0.0.1",
 | 
						|
        )
 | 
						|
        expected_message = "The weather sure looks great !"
 | 
						|
        self.send_and_test_private_message("default", expected_message)
 | 
						|
 | 
						|
    def test_dialogflow_alternate_result(self) -> None:
 | 
						|
        self.url = self.build_webhook_url(
 | 
						|
            email="AARON@zulip.com",
 | 
						|
            username="aaron",
 | 
						|
            user_ip="127.0.0.1",
 | 
						|
        )
 | 
						|
        expected_message = "Weather in New Delhi is nice!"
 | 
						|
        self.send_and_test_private_message("alternate_result", expected_message)
 | 
						|
 | 
						|
    def test_dialogflow_error_status(self) -> None:
 | 
						|
        self.url = self.build_webhook_url(
 | 
						|
            email="AARON@zulip.com",
 | 
						|
            username="aaron",
 | 
						|
            user_ip="127.0.0.1",
 | 
						|
        )
 | 
						|
        expected_message = "403 - Access Denied"
 | 
						|
        self.send_and_test_private_message("error_status", expected_message)
 | 
						|
 | 
						|
    def test_dialogflow_exception(self) -> None:
 | 
						|
        self.url = self.build_webhook_url(
 | 
						|
            email="AARON@zulip.com",
 | 
						|
            username="aaron",
 | 
						|
            user_ip="127.0.0.1",
 | 
						|
        )
 | 
						|
        expected_message = "DialogFlow couldn't process your query."
 | 
						|
        self.send_and_test_private_message("exception", expected_message)
 | 
						|
 | 
						|
    def get_body(self, fixture_name: str) -> str:
 | 
						|
        return self.webhook_fixture_data("dialogflow",
 | 
						|
                                         fixture_name,
 | 
						|
                                         file_type="json")
 |