def test_failed_connection(self, es_mock):
     es_mock.side_effect = ConnectionError()
     ge = GfycatExtractor(MockObjects.get_mock_post_gfycat(),
                          MockObjects.get_blank_user())
     ge.extract_content()
     failed_post = ge.failed_extract_posts[0]
     self.assertTrue('Failed to locate content' in failed_post.status)
    def test_extract_content_assignment_direct(self, es_mock):
        post = MockObjects.get_mock_post_gfycat()
        post.url += '.webm'
        ge = GfycatExtractor(post, MockObjects.get_blank_user())
        ge.extract_content()

        es_mock.assert_called()
 def test_extract_single(self, j_mock):
     dir_url = 'https://giant.gfycat.com/KindlyElderlyCony.webm'
     j_mock.return_value = {'gfyItem': {'webmUrl': dir_url}}
     ge = GfycatExtractor(MockObjects.get_mock_post_gfycat(), MockObjects.get_blank_user())
     ge.extract_single()
     j_mock.assert_called_with('https://gfycat.com/cajax/get/KindlyElderlyCony')
     self.check_output(ge, dir_url)
    def test_extract_single_tagged(self, j_mock):
        dir_url = 'https://giant.gfycat.com/anchoredenchantedamericanriverotter.webm'

        mock_response = MagicMock()
        mock_response.status_code = 200
        mock_response.headers = {'Content-Type': 'json'}
        mock_response.json.return_value = {'gfyItem': {'webmUrl': dir_url}}
        j_mock.return_value = mock_response

        ge = GfycatExtractor(MockObjects.get_mock_post_gfycat_tagged(), MockObjects.get_blank_user())
        ge.extract_single()
        j_mock.assert_called_with('https://api.gfycat.com/v1/gfycats/anchoredenchantedamericanriverotter', timeout=10)
        self.check_output_tagged(ge, dir_url)
    def test_extract_content_assignment_single(self, es_mock):
        ge = GfycatExtractor(MockObjects.get_mock_post_gfycat(),
                             MockObjects.get_blank_user())
        ge.extract_content()

        es_mock.assert_called()
 def test_direct_extraction(self):
     post = MockObjects.get_mock_post_gfycat()
     post.url = post.url + '.webm'
     ge = GfycatExtractor(post, MockObjects.get_blank_user())
     ge.extract_direct_link()
     self.check_output(ge, post.url)