link_shortner bot : Add test for bad requests.
(This module now has 100% coverage.)
This commit is contained in:
		
							parent
							
								
									582b16861e
								
							
						
					
					
						commit
						8e978a0845
					
				
					 2 changed files with 37 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -0,0 +1,27 @@
 | 
			
		|||
{
 | 
			
		||||
  "request": {
 | 
			
		||||
    "api_url": "https://www.googleapis.com/urlshortener/v1/url",
 | 
			
		||||
    "method": "POST",
 | 
			
		||||
    "params": {
 | 
			
		||||
      "key": "qwertyuiopx"
 | 
			
		||||
    },
 | 
			
		||||
    "json": {
 | 
			
		||||
      "longUrl": "www.youtube.com/watch"
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  "response": {
 | 
			
		||||
    "error":{
 | 
			
		||||
      "errors":[
 | 
			
		||||
        {
 | 
			
		||||
          "reason":"keyInvalid"
 | 
			
		||||
        }
 | 
			
		||||
      ]
 | 
			
		||||
    },
 | 
			
		||||
    "code": 400,
 | 
			
		||||
    "message": "Bad Request"
 | 
			
		||||
  },
 | 
			
		||||
  "response-headers": {
 | 
			
		||||
    "status": 400,
 | 
			
		||||
    "content-type": "application/json; charset=utf-8"
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,5 +1,8 @@
 | 
			
		|||
from unittest.mock import patch
 | 
			
		||||
from zulip_bots.test_lib import BotTestCase
 | 
			
		||||
from zulip_bots.test_lib import StubBotHandler
 | 
			
		||||
from zulip_bots.bots.link_shortener.link_shortener import LinkShortenerHandler
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestLinkShortenerBot(BotTestCase):
 | 
			
		||||
    bot_name = "link_shortener"
 | 
			
		||||
| 
						 | 
				
			
			@ -33,3 +36,10 @@ class TestLinkShortenerBot(BotTestCase):
 | 
			
		|||
            self._test('help',
 | 
			
		||||
                       ('Mention the link shortener bot in a conversation and then '
 | 
			
		||||
                        'enter any URLs you want to shorten in the body of the message.'))
 | 
			
		||||
 | 
			
		||||
    def test_exception_when_api_key_is_invalid(self)-> None:
 | 
			
		||||
        bot_test_instance = LinkShortenerHandler()
 | 
			
		||||
        with self.mock_config_info({'key': 'qwertyuiopx'}):
 | 
			
		||||
            with self.mock_http_conversation('test_invalid_key'):
 | 
			
		||||
                with self.assertRaises(StubBotHandler.BotQuitException):
 | 
			
		||||
                    bot_test_instance.initialize(StubBotHandler())
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue