import logging
import unittest
from unittest import mock

from requests import HTTPError

from libs.upbeatbot import UpBeatBot


logging.disable(logging.CRITICAL)


class TestUpbeatBot(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.upbeat_bot = UpBeatBot()

    @mock.patch('bs4.BeautifulSoup')
    @mock.patch('requests.get')
    def test_get_cute_animal_picture_happy_path(self, mock_request, mock_soup):
        expected_picture = 'https://cutestpaw.com/cat/happy-pic.jpg'

        mock_preview_soup = mock.Mock()
        mock_preview_soup.select.return_value = [{'href' : 'https://example.com'}]

        mock_picture_soup = mock.Mock()
        mock_picture_soup.select.return_value = [{'src': expected_picture}]

        mock_soup.side_effect = [mock_preview_soup, mock_picture_soup]

        mock_preview_response = mock.Mock()
        mock_image_response = mock.Mock()
        mock_request.side_effect = [mock_preview_response, mock_image_response]

        picture = self.upbeat_bot.get_cute_animal_picture()

        self.assertEqual(picture, expected_picture)

    @mock.patch('requests.get')
    def test_get_cute_animal_picture_fails_fetching_preview(self, mock_request):
        mock_response = mock.Mock()
        mock_response.raise_for_status.side_effect = HTTPError
        mock_request.return_value = mock_response

        picture = self.upbeat_bot.get_cute_animal_picture('cat')

        self.assertEqual(picture, self.upbeat_bot.animals['cat'])

    @mock.patch('bs4.BeautifulSoup')
    @mock.patch('requests.get')
    def test_get_cute_animal_picture_fails_fetching_image(self, mock_request, mock_soup):
        mock_preview_soup = mock.Mock()
        mock_preview_soup.select.return_value = [{'href' : 'https://example.com'}]
        mock_soup.return_value = mock_preview_soup

        mock_preview_response = mock.Mock()
        mock_image_response = mock.Mock()
        mock_image_response.raise_for_status.side_effect = HTTPError
        mock_request.side_effect = [mock_preview_response, mock_image_response]

        picture = self.upbeat_bot.get_cute_animal_picture('cat')

        self.assertEqual(picture, self.upbeat_bot.animals['cat'])

    def test_get_animal_from_message_chosen_animal_returned(self):
        tweet = 'Hey @upbeatbot send me a dog!'
        animal = self.upbeat_bot._get_animal_from_message(tweet)

        self.assertEqual(animal, 'dog')

    def test__get_animal_from_message_returns_None_if_no_animal_found(self):
        tweet = 'Hey @upbeatbot send me a pic!'
        animal = self.upbeat_bot._get_animal_from_message(tweet)

        self.assertIsNone(animal)

@@ -27,66 +27,8 @@
 test
-%0Afrom unittest import mock%0A%0Afrom requests import HTTPError
 %0A%0Afr
@@ -228,460 +228,147 @@
     
-@mock.patch('bs4.BeautifulSoup')%0A    @mock.patch('requests.get')%0A    def test_get_cute_animal_picture_happy_path(self, mock_request, mock_soup):%0A        expected_picture = 'https://cutestpaw.com/cat/happy-pic.jpg'%0A%0A        mock_preview_soup = mock.Mock()%0A        mock_preview_soup.select.return_value = %5B%7B'href' : 'https://example.com'%7D%5D%0A%0A        mock_picture_soup = mock.Mock()%0A        mock_picture_soup.select.return_value = %5B%7B'src': expected
+def test_get_cute_animal_picture_with_no_message_returns_random_image(self):%0A        img_filename = self.upbeat_bot.get_cute_animal
 _picture
 %7D%5D%0A%0A
@@ -363,18 +363,18 @@
 _picture
-%7D%5D
+()
 %0A%0A      
@@ -379,1449 +379,733 @@
     
-mock_soup.side_effect = %5Bmock_preview_soup, mock_picture_soup%5D%0A%0A        mock_preview_response = mock.Mock()%0A        mock_image_response = mock.Mock()%0A        mock_request.side_effect = %5Bmock_preview_response, mock_image_response%5D%0A%0A        picture = self.upbeat_bot.get_cute_animal_picture()%0A%0A        self.assertEqual(picture, expected_picture)%0A%0A    @mock.patch('requests.get')%0A    def test_get_cute_animal_picture_fails_fetching_preview(self, mock_request):%0A        mock_response = mock.Mock()%0A        mock_response.raise_for_status.side_effect = HTTPError%0A        mock_request.return_value = mock_response%0A%0A        picture = self.upbeat_bot.get_cute_animal_picture('cat')%0A%0A        self.assertEqual(picture, self.upbeat_bot.
+# Assert we get an image back%0A        self.assertTrue('.jpg' in img_filename)%0A%0A    def test_get_cute_animal_picture_for_message_with_no_animal_in_message_returns_random_image(self):%0A        img_filename = self.upbeat_bot.get_cute_animal_picture(message='This message has no animal in it')%0A%0A        # Assert we get 
 an
+ 
 ima
-ls%5B'cat'%5D)%0A%0A    @mock.patch('bs4.BeautifulSoup')%0A    @mock.patch('requests.get')%0A    def test_get_cute_animal_picture_fails_fetching_image(self, mock_request, mock_soup):%0A        mock_preview_soup = mock.Mock()%0A        mock_preview_soup.select.return_value = %5B%7B'href' : 'https://example.com'%7D%5D%0A        mock_soup.return_value = mock_preview_soup%0A%0A        mock_preview_response = mock.Mock()%0A        mock_image_response = mock.Mock()%0A        mock_image_response.raise_for_status.side_effect = HTTPError%0A        mock_request.side_effect = %5Bmock_preview_response, mock_image_response%5D%0A%0A        picture = self.upbeat_bot.get_cute_animal_picture('cat')%0A%0A        self.assertEqual(picture, self.upbeat_bot.animals%5B'cat'%5D
+ge back%0A        self.assertTrue('.jpg' in img_filename)%0A%0A    def test_get_cute_animal_picture_for_message_with_animal_in_message_returns_image_for_animal(self):%0A        animal = 'cat'%0A        img_filename = self.upbeat_bot.get_cute_animal_picture(message='Send me a %7B%7D'.format(animal))%0A%0A        # Assert we get an image back from the directory for the animal%0A        self.assertTrue(animal in img_filename
 )%0A%0A 

Fix tests