def test_get_url_market(self):
        with mock.patch('source.lib.make_pycurl_request',
                        mock.Mock(return_value=
                        (self._get_html_with_redirect('market://url/index.html'), None)
                        )),\
            mock.patch('source.lib.fix_market_url') as m_fix_market:
            get_url('market://url', 11)

            self.assertTrue(m_fix_market.called)
Esempio n. 2
0
    def test_get_url_market(self):
        timeout = 10
        expected_redirect_url = 'market://something'
        expected_content = self.get_redirect_html('market://something/page.html')

        with mock.patch('source.lib.make_pycurl_request', mock.Mock(return_value=(expected_content, None))),\
            mock.patch('source.lib.fix_market_url') as fix_market_url_m:
            lib.get_url(expected_redirect_url, timeout)

            assert fix_market_url_m.called, 'fix_market_url() not called'
Esempio n. 3
0
 def test_without_redirect_url(self):
     url = 'http://url.ru'
     timeout = 30
     content = 'content'
     with mock.patch('source.lib.make_pycurl_request', mock.Mock(return_value=[content, None])):
         with mock.patch('source.lib.check_for_meta', mock.Mock(return_value=None)):
             self.assertEquals((None, None, content), lib.get_url(url, timeout))
Esempio n. 4
0
 def test_redirect(self):
     url = 'http://url.ru'
     timeout = 30
     content = 'content'
     new_redirect_url = 'http://redirect-url.ru'
     with mock.patch('source.lib.make_pycurl_request', mock.Mock(return_value=[content, new_redirect_url])):
         self.assertEquals((new_redirect_url, REDIRECT_HTTP, content), lib.get_url(url, timeout))
 def test_get_url_error_redirect(self):
     """
     get_url возвращает тип редиректа ERROR
     :return:
     """
     url = "some url"
     self.assertEquals(get_url(url, timeout=10), (url, ERROR_REDIRECT, None))
Esempio n. 6
0
 def test_get_url_with_match_ok_redirect(self):
     contnent = "VK.COM"
     redirect = "a"
     with mock.patch('source.lib.make_pycurl_request', mock.Mock(return_value=(contnent, redirect))):
         with mock.patch('source.lib.OK_REDIRECT', mock.Mock()):
             with mock.patch('source.lib.OK_REDIRECT.match', mock.Mock(return_value=True)):
                 self.assertEqual(get_url("abc", 10, "A"), (None, None, contnent))
Esempio n. 7
0
 def test_without_redirect(self):
     url = 'http://url.ru'
     timeout = 10
     content = 'content'
     new_redirect_url = 'http://odnoklassniki.ru/redirect-url/st.redirect'
     with mock.patch('source.lib.make_pycurl_request', mock.Mock(return_value=[content, new_redirect_url])):
         self.assertEquals((None, None, content), lib.get_url(url, timeout))
 def test_get_url_wrong_url(self):
     """
     error in url
     """
     url = "wrong url"
     with mock.patch("source.lib.make_pycurl_request", mock.Mock(side_effect=ValueError('Value Error'))):
         self.assertEquals(get_url(url, timeout=1), (url, 'ERROR', None))
Esempio n. 9
0
    def test_get_url_error(self):
        url = 'http://mail.ru'
        timeout = 10

        with mock.patch('source.lib.make_pycurl_request', mock.Mock(side_effect=ValueError)):
            redirect_url, redirect_type, content = lib.get_url(url, timeout)

            self.assertEquals(redirect_type, 'ERROR', 'ValueError not handled')
Esempio n. 10
0
 def test_without_redirect(self):
     url = 'http://url.ru'
     timeout = 10
     content = 'content'
     new_redirect_url = 'http://odnoklassniki.ru/redirect-url/st.redirect'
     with mock.patch('source.lib.make_pycurl_request',
                     mock.Mock(return_value=[content, new_redirect_url])):
         self.assertEquals((None, None, content), lib.get_url(url, timeout))
Esempio n. 11
0
 def test_get_url_error_redirect(self):
     """
     get_url возвращает тип редиректа ERROR
     :return:
     """
     url = "url"
     with mock.patch('source.lib.make_pycurl_request', mock.Mock(side_effect=ValueError('value error'))):
         self.assertEquals(get_url(url, timeout=self.normal_timeout), (url, ERROR_REDIRECT, None))
    def test_get_url_http(self):
        m_redirect_url = 'index.html'
        m_redirect_type = REDIRECT_HTTP
        with mock.patch('source.lib.make_pycurl_request', mock.Mock(return_value=('<html></html>', m_redirect_url))):
            redirect_url, redirect_type, content = get_url('http://tech-mail.ru', 11)

            self.assertEquals(m_redirect_url, redirect_url)
            self.assertEquals(m_redirect_type, redirect_type)
Esempio n. 13
0
    def test_get_url_value_error(self):
        url = 'http://url.ru'
        timeout = 30
        with mock.patch('source.lib.make_pycurl_request', mock.Mock(side_effect=ValueError)):
            redirect_url, redirect_type, content = lib.get_url(url, timeout)

        self.assertEquals(url, redirect_url)
        self.assertEquals('ERROR', redirect_type)
        self.assertEquals(None, content)
 def test_get_url_market_url_http_redirect_type(self):
     with mock.patch('source.lib.fix_market_url', mock.Mock()) as fix_market_url:
         new_redirect_url = "market://market.url"
         prepare_url_return = 'url after prepare'
         content = 'this is original content'
         with mock.patch('source.lib.make_pycurl_request', mock.Mock(return_value=(content, new_redirect_url))):
             with mock.patch('source.lib.prepare_url', mock.Mock(return_value=prepare_url_return)) as prepare_url:
                  self.assertEquals(get_url(new_redirect_url, timeout=10), (prepare_url_return, REDIRECT_HTTP, content))
                  fix_market_url.assert_called_once_with(new_redirect_url)
 def test_get_url_redirect_meta(self):
     from source.lib import REDIRECT_META
     url = 'http://url.ru'
     timeout = 30
     content = 'content'
     new_redirect_url = 'http://redirect-url.ru'
     with mock.patch('source.lib.make_pycurl_request', mock.Mock(return_value=[content, None])):
         with mock.patch('source.lib.check_for_meta', mock.Mock(return_value=new_redirect_url)):
             self.assertEquals((new_redirect_url, REDIRECT_META, content), lib.get_url(url, timeout))
Esempio n. 16
0
 def test_redirect(self):
     url = 'http://url.ru'
     timeout = 30
     content = 'content'
     new_redirect_url = 'http://redirect-url.ru'
     with mock.patch('source.lib.make_pycurl_request',
                     mock.Mock(return_value=[content, new_redirect_url])):
         self.assertEquals((new_redirect_url, REDIRECT_HTTP, content),
                           lib.get_url(url, timeout))
Esempio n. 17
0
 def _get_url_redirect(self, new_redirect_url, make_py_curl_request_return,
                       prepare_url_return, check_meta_return):
     with mock.patch('source.lib.fix_market_url', mock.Mock()) as fix_market_url, \
         mock.patch('source.lib.make_pycurl_request', mock.Mock(return_value=make_py_curl_request_return)), \
         mock.patch('source.lib.check_for_meta', mock.Mock(return_value=check_meta_return)), \
         mock.patch('source.lib.prepare_url', mock.Mock(return_value=prepare_url_return)) as m_prepare_url:
         return get_url(
             new_redirect_url,
             timeout=self.normal_timeout), fix_market_url, m_prepare_url
Esempio n. 18
0
    def test_get_url_ignore_ok_login_redirects(self):
        """
        ignoring ok login redirects
        """
        content = "dummy content"
        new_redirect_url = "http://odnoklassniki.ru/123.123st.redirect"

        with mock.patch("source.lib.make_pycurl_request",
                        mock.Mock(return_value=(content, new_redirect_url))):
            self.assertEquals(get_url("url", timeout=1), (None, None, content))
Esempio n. 19
0
 def test_get_url_error_redirect(self):
     """
     get_url возвращает тип редиректа ERROR
     :return:
     """
     url = "url"
     with mock.patch('source.lib.make_pycurl_request',
                     mock.Mock(side_effect=ValueError('value error'))):
         self.assertEquals(get_url(url, timeout=self.normal_timeout),
                           (url, ERROR_REDIRECT, None))
Esempio n. 20
0
 def test_without_redirect_url(self):
     url = 'http://url.ru'
     timeout = 30
     content = 'content'
     with mock.patch('source.lib.make_pycurl_request',
                     mock.Mock(return_value=[content, None])):
         with mock.patch('source.lib.check_for_meta',
                         mock.Mock(return_value=None)):
             self.assertEquals((None, None, content),
                               lib.get_url(url, timeout))
Esempio n. 21
0
 def test_get_url_ok_redirect(self):
     """
     Пропускает ok login redirects
     :return:
     """
     url = "url"
     new_redirect_url = "http://odnoklassniki.ru/123.st.redirect"
     content = "content"
     with mock.patch('source.lib.make_pycurl_request', mock.Mock(return_value=(content, new_redirect_url))):
         self.assertEquals(get_url(url, timeout=self.normal_timeout), (None, None, content))
 def test_get_url_ok_redirect(self):
     """
     ignoring ok login redirects
     :return:
     """
     url = "some url"
     new_redirect_url = 'http://odnoklassniki.ru/asdasd.st.redirect'
     content = 'this is the end'
     with mock.patch('source.lib.make_pycurl_request', mock.Mock(return_value=(content, new_redirect_url))):
         self.assertEquals(get_url(url, timeout=10), (None, None, content))
Esempio n. 23
0
    def test_get_url_redirect_meta_none(self):
        url = 'http://url.ru'
        timeout = 30
        content = 'content'
        with mock.patch('source.lib.make_pycurl_request', mock.Mock(return_value=[content, None])):
            with mock.patch('source.lib.check_for_meta', mock.Mock(return_value=None)):
                redirect_url, redirect_type, return_content = lib.get_url(url, timeout)

        self.assertEquals(None, redirect_url)
        self.assertEquals(None, redirect_type)
        self.assertEquals(content, return_content)
Esempio n. 24
0
    def test_get_url_not_redirect(self):
        url = 'http://url.ru'
        timeout = 30
        content = 'content'
        new_redirect_url = 'http://odnoklassniki.ru/redirect-url/st.redirect'
        with mock.patch('source.lib.make_pycurl_request', mock.Mock(return_value=[content, new_redirect_url])):
            redirect_url, redirect_type, return_content = lib.get_url(url, timeout)

        self.assertEquals(None, redirect_url)
        self.assertEquals(None, redirect_type)
        self.assertEquals(content, return_content)
Esempio n. 25
0
 def test_get_url_market_url_http_redirect_type(self):
     """
     Input market_url
     """
     with mock.patch('source.lib.fix_market_url', mock.Mock()):
         redirect_url = "market://details"
         prepare_url_return = 'become after prepare'
         content = 'dummyContent'
         with mock.patch('source.lib.make_pycurl_request', mock.Mock(return_value=(content, redirect_url))):
             with mock.patch('source.lib.prepare_url', mock.Mock(return_value=prepare_url_return)):
                 self.assertEquals(get_url(redirect_url, timeout=1), (prepare_url_return, REDIRECT_HTTP, content))
Esempio n. 26
0
 def test_redirect_market(self):
     url = 'http://url.ru'
     timeout = 30
     content = 'content'
     new_redirect_url = 'market://url.ru'
     new_redirect_url_without_market = 'http://play.google.com/store/apps/url.ru'
     with mock.patch('source.lib.make_pycurl_request',
                     mock.Mock(return_value=[content, new_redirect_url])):
         self.assertEquals(
             (new_redirect_url_without_market, REDIRECT_HTTP, content),
             lib.get_url(url, timeout))
Esempio n. 27
0
 def test_get_url_ok_redirect(self):
     """
     Пропускает ok login redirects
     :return:
     """
     url = "url"
     new_redirect_url = "http://odnoklassniki.ru/123.st.redirect"
     content = "content"
     with mock.patch('source.lib.make_pycurl_request',
                     mock.Mock(return_value=(content, new_redirect_url))):
         self.assertEquals(get_url(url, timeout=self.normal_timeout),
                           (None, None, content))
Esempio n. 28
0
    def test_get_url_redirect_http(self):
        from source.lib import REDIRECT_HTTP
        url = 'http://url.ru'
        timeout = 30
        content = 'content'
        new_redirect_url = 'http://redirect-url.ru'
        with mock.patch('source.lib.make_pycurl_request', mock.Mock(return_value=[content, new_redirect_url])):
            redirect_url, redirect_type, return_content = lib.get_url(url, timeout)

        self.assertEquals(new_redirect_url, redirect_url)
        self.assertEquals(REDIRECT_HTTP, redirect_type)
        self.assertEquals(content, return_content)
Esempio n. 29
0
    def test_get_url_http_new_redirect_and_ok_redirect(self):
        url = 'http://mail.ru'
        timeout = 10
        expected_redirect_url = rstr.xeger(lib.OK_REDIRECT)
        expected_content = self.get_redirect_html('page.html')

        with mock.patch('source.lib.make_pycurl_request', mock.Mock(return_value=(expected_content, expected_redirect_url))):
            redirect_url, redirect_type, content = lib.get_url(url, timeout)

            self.assertIsNone(redirect_url, 'redirect_url is not None')
            self.assertIsNone(redirect_type, 'redirect_type is not None')
            self.assertEqual(content, expected_content, 'content not match')
Esempio n. 30
0
 def test_get_url_none_redirect_url_none_redirect_type(self):
     """
     redirect_url is none
     None redirect_type
     """
     with mock.patch('source.lib.fix_market_url', mock.Mock()):
         redirect_url = None
         final_url = None
         content = 'this is original content'
         with mock.patch('source.lib.make_pycurl_request', mock.Mock(return_value=(content, redirect_url))), \
              mock.patch('source.lib.check_for_meta', mock.Mock(return_value=None)), \
              mock.patch('source.lib.prepare_url', mock.Mock(return_value=final_url)):
             self.assertEquals(get_url('dummyurl', timeout=1), (final_url, None, content))
Esempio n. 31
0
 def test_get_url_none_redirect_url_meta_redirect_type(self):
     """
     redirect url is none pri make_pycurl_request
     return meta redirect type
     """
     with mock.patch('source.lib.fix_market_url', mock.Mock()):
         redirect_url = "not none redirect url"
         content = 'this is original content'
         with mock.patch('source.lib.make_pycurl_request', mock.Mock(return_value=(content, None))):
             with mock.patch('source.lib.check_for_meta', mock.Mock(return_value=redirect_url)):
                 with mock.patch('source.lib.prepare_url',
                                 mock.Mock(return_value=redirect_url)):
                     self.assertEquals(get_url('dummyurl', timeout=1), (redirect_url, REDIRECT_META, content))
Esempio n. 32
0
 def test_get_url_with_http_redirect(self):
     contnent = "VK.COM"
     redirect = "a"
     url = "abc"
     market = mock.Mock()
     market.scheme = 'market'
     with mock.patch('source.lib.make_pycurl_request', mock.Mock(return_value=(contnent, redirect))):
         with mock.patch('source.lib.OK_REDIRECT', mock.Mock()):
             with mock.patch('source.lib.OK_REDIRECT.match', mock.Mock(return_value=False)):
                 with mock.patch('source.lib.urlsplit', mock.Mock(return_value=market)):
                     with mock.patch('source.lib.fix_market_url', mock.Mock(return_value=url)):
                         with mock.patch('source.lib.prepare_url', mock.Mock(return_value=url)):
                             self.assertEqual(get_url(url, 10, "A"), (url, REDIRECT_HTTP, contnent))
Esempio n. 33
0
 def test_get_url_with_no_http_and_meta_redirect(self):
     contnent = "VK.COM"
     url = "abc"
     market = mock.Mock()
     market.scheme = 'http'
     with mock.patch('source.lib.make_pycurl_request', mock.Mock(return_value=(contnent, None))):
         with mock.patch('source.lib.OK_REDIRECT', mock.Mock()):
             with mock.patch('source.lib.OK_REDIRECT.match', mock.Mock(return_value=False)):
                 with mock.patch('source.lib.urlsplit', mock.Mock(return_value=market)):
                     with mock.patch('source.lib.fix_market_url', mock.Mock(return_value=url)):
                         with mock.patch('source.lib.prepare_url', mock.Mock(return_value=url)):
                             with mock.patch('source.lib.check_for_meta', mock.Mock(return_value=None)):
                                 self.assertEqual(get_url(url, 10, "A"), (url, None, contnent))
Esempio n. 34
0
    def test_get_url_html(self):
        url = 'http://mail.ru'
        timeout = 10
        expected_redirect_url = 'http://mail.ru/page.html'
        expected_content = self.get_redirect_html('page.html')
        expected_redirect_type = lib.REDIRECT_META

        with mock.patch('source.lib.make_pycurl_request', mock.Mock(return_value=(expected_content, None))):
            redirect_url, redirect_type, content = lib.get_url(url, timeout)

            self.assertEquals(redirect_url, expected_redirect_url, 'redirect_url not match')
            self.assertEquals(content, expected_content, 'content not match')
            self.assertEquals(redirect_type, expected_redirect_type, 'redirect_type is not correct')
Esempio n. 35
0
    def test_get_url_redirect_meta_market(self):
        from source.lib import REDIRECT_META
        url = 'http://url.ru'
        timeout = 30
        content = 'content'
        new_redirect_url = 'market://redirect-url.ru'
        new_redirect_url_without_market = 'http://play.google.com/store/apps/redirect-url.ru'
        with mock.patch('source.lib.make_pycurl_request', mock.Mock(return_value=[content, None])):
            with mock.patch('source.lib.check_for_meta', mock.Mock(return_value=new_redirect_url)):
                redirect_url, redirect_type, return_content = lib.get_url(url, timeout)

        self.assertEquals(new_redirect_url_without_market, redirect_url)
        self.assertEquals(REDIRECT_META, redirect_type)
        self.assertEquals(content, return_content)
 def test_get_url_none_redirect_url_none_redirect_type(self):
     """
     redirect url is none
     return null redirect type
     :return:
     """
     with mock.patch('source.lib.fix_market_url', mock.Mock()) as fix_market_url:
         new_redirect_url = None
         prepare_url_return = None
         content = 'this is original content'
         with mock.patch('source.lib.make_pycurl_request', mock.Mock(return_value=(content, new_redirect_url))):
             with mock.patch('source.lib.check_for_meta', mock.Mock(return_value=None)):
                 with mock.patch('source.lib.prepare_url', mock.Mock(return_value=prepare_url_return)) as prepare_url:
                     self.assertEquals((prepare_url_return, None, content), get_url('some url', timeout=10))
                     assert not fix_market_url.called
                     prepare_url.assert_called_once_with(new_redirect_url)
    def test_get_url_error(self):
        with mock.patch('source.lib.make_pycurl_request', mock.Mock(side_effect=ValueError)):
            url, redirect_type, content = get_url('url', 11)

            self.assertEquals(redirect_type, 'ERROR')
Esempio n. 38
0
 def test_make_pycurl_request_raised_exception(self):
     url = 'http://url.ru'
     timeout = 30
     with mock.patch('source.lib.make_pycurl_request',
                     mock.Mock(side_effect=ValueError)):
         self.assertEquals((url, 'ERROR', None), lib.get_url(url, timeout))