예제 #1
0
 def test_check_for_meta_with_content_split_bad(self):
     """
     В контенте не 2 параметра
     :return:
     """
     result = self._prepare_mock()
     result.__getitem__ = mock.Mock(return_value="content")
     with mock.patch.object(re, 'search', mock.Mock()) as research, \
             mock.patch.object(BeautifulSoup, 'find', return_value=result):
         check_for_meta("content", "url")
         self.assertFalse(research.called)
예제 #2
0
 def test_check_for_meta_with_content_split_bad(self):
     """
     В контенте не 2 параметра
     :return:
     """
     result = self._prepare_mock()
     result.__getitem__ = mock.Mock(return_value="content")
     with mock.patch.object(re, 'search', mock.Mock()) as research, \
             mock.patch.object(BeautifulSoup, 'find', return_value=result):
         check_for_meta("content", "url")
         self.assertFalse(research.called)
예제 #3
0
 def test_check_for_meta_with_content_split_bad(self):
     """
     В контенте не 2 параметра
     :return:
     """
     result = mock.MagicMock(name="result")
     result.attrs = {
         "content": True,
         "http-equiv": "refresh"
     }
     result.__getitem__ = mock.Mock(return_value="content")
     with mock.patch.object(re, 'search', mock.Mock()) as research:
         with mock.patch.object(BeautifulSoup, 'find', return_value=result):
             check_for_meta("content", "url")
             assert research.called is False
예제 #4
0
    def test_check_for_meta_no_meta(self):
        content = self.get_default_html()
        url_prefix = 'http://mail.ru'

        url = lib.check_for_meta(content, url_prefix)

        assert url is None, 'url found but no url was specified'
예제 #5
0
 def test_check_for_meta_no_meta(self):
     """
     Result is None
     """
     result = None
     with mock.patch.object(BeautifulSoup, "find", return_value=result):
         self.assertIsNone(check_for_meta("content", "url"))
    def test_check_for_meta(self):
        content = '<meta http-equiv="refresh" content="content; url=redirect_url">'
        url = 'http://url.ru'
        redirect_url = 'http://redirect-url.ru'

        with mock.patch('source.lib.to_unicode', mock.Mock(return_value=redirect_url)):
            self.assertEquals(lib.urljoin(url, redirect_url), lib.check_for_meta(content, url))
    def test_check_for_meta_not_content(self):
        content = "meta: not content"
        url = 'url'
        result = mock.MagicMock()

        with mock.patch('source.lib.BeautifulSoup.find', mock.Mock(return_value=result)):
            self.assertEquals(None, lib.check_for_meta(content, url))
예제 #8
0
 def test_check_for_meta_no_meta(self):
     """
     find("meta") returns None
     """
     ret = None
     with mock.patch.object(BeautifulSoup, 'find', return_value=ret):
         check = check_for_meta("content", "url")
         self.assertIsNone(check)
예제 #9
0
 def test_check_for_meta_no_httpequiv_attr(self):
     result = mock.MagicMock(name="result")
     result.attrs = {
         "content": True,
     }
     with mock.patch.object(BeautifulSoup, 'find', return_value=result):
         check = check_for_meta("content", "url")
         self.assertIsNone(check)
예제 #10
0
 def test_check_for_meta_no_meta(self):
     """
     find("meta") returns None
     """
     ret = None
     with mock.patch.object(BeautifulSoup, 'find', return_value=ret):
         check = check_for_meta("content", "url")
         self.assertIsNone(check)
예제 #11
0
    def test_check_for_meta(self):
        content = self.get_redirect_html('page.html')

        url_prefix = 'http://mail.ru'

        url = lib.check_for_meta(content, url_prefix)

        assert url, 'No meta tag found'
        assert url.startswith(url_prefix), 'supplied url prefix not took in account'
예제 #12
0
 def test_check_for_meta_httpequiv_no_refresh(self):
     """
     http-equiv is /no refresh/
     """
     result = mock.MagicMock(name="result")
     result.attrs = {"content": True, 'http-equiv': "no refresh"}
     with mock.patch.object(BeautifulSoup, 'find', return_value=result):
         check = check_for_meta("content", "url")
         self.assertIsNone(check)
예제 #13
0
 def test_check_for_meta(self):
     meta_url = 'test.url'
     url = 'http://test/'
     content = """
             <html>
             <head>
                 <meta http-equiv="refresh" content="5; url=%s">
             </head>
         </html>""" % meta_url
     self.assertEqual(lib.check_for_meta(content, url), url+meta_url)
예제 #14
0
 def test_check_for_meta(self):
     meta_url = 'test.url'
     url = 'http://test/'
     content = """
             <html>
             <head>
                 <meta http-equiv="refresh" content="5; url=%s">
             </head>
         </html>""" % meta_url
     self.assertEqual(lib.check_for_meta(content, url), url + meta_url)
예제 #15
0
 def test_check_for_meta_no_http_equiv(self):
     """
     No http_equiv in result
     """
     result = mock.MagicMock(name="result")
     result.attrs = {
         "content": "contentDummy",
     }
     with mock.patch.object(BeautifulSoup, "find", return_value=result):
         self.assertIsNone(check_for_meta("content", "url"))
예제 #16
0
    def test_check_for_meta_not_refresh(self):
        content = "meta: http-equiv=Content-Type content=content"
        url = 'url'
        result = mock.MagicMock()
        result.attrs = {
            'content': 'content',
            'http-equiv': 'Content-Type',
        }

        with mock.patch('source.lib.BeautifulSoup.find', mock.Mock(return_value=result)):
            self.assertEquals(None, lib.check_for_meta(content, url))
예제 #17
0
 def test_check_for_meta_correct(self):
     """
     Весь путь в check_for_meta
     :return:
     """
     url = "localhost/lal?what_are_you_doing=dont_know"
     result = self._prepare_mock()
     result.__getitem__ = mock.Mock(return_value="wait;url=" + url)
     with mock.patch.object(BeautifulSoup, 'find', return_value=result):
         check = check_for_meta("content", "url")
         self.assertEquals(check, url)
예제 #18
0
 def test_check_for_meta_without_httpequiv_attr(self):
     """
     http-equiv unspecified
     """
     result = mock.MagicMock(name="result")
     result.attrs = {
         "content": True,
     }
     with mock.patch.object(BeautifulSoup, 'find', return_value=result):
         check = check_for_meta("content", "url")
         self.assertIsNone(check)
예제 #19
0
    def test_check_for_meta_not_result(self):
        content = """
            <!DOCTYPE html>
            <html>
                <head></head>
                <body></body>
            </html>
        """
        url = 'url'

        self.assertEquals(None, lib.check_for_meta(content, url))
예제 #20
0
 def test_check_for_meta_correct(self):
     """
     Весь путь в check_for_meta
     :return:
     """
     url = "localhost/lal?what_are_you_doing=dont_know"
     result = self._prepare_mock()
     result.__getitem__ = mock.Mock(return_value="wait;url=" + url)
     with mock.patch.object(BeautifulSoup, 'find', return_value=result):
         check = check_for_meta("content", "url")
         self.assertEquals(check, url)
예제 #21
0
 def test_check_for_meta_httpequiv_no_refresh(self):
     """
     http-equiv is /no refresh/
     """
     result = mock.MagicMock(name="result")
     result.attrs = {
         "content": True,
         'http-equiv': "no refresh"
     }
     with mock.patch.object(BeautifulSoup, 'find', return_value=result):
         check = check_for_meta("content", "url")
         self.assertIsNone(check)
예제 #22
0
 def test_check_for_meta_wrong_length(self):
     """
     Splitted content length is wrong
     """
     result = mock.MagicMock(name="result")
     result.attrs = {
         "content": "dummy;dummy;dummy",
         "http-equiv": "refresh"
     }
     result.__getitem__ = mock.Mock(return_value=result.attrs["content"])
     with mock.patch.object(BeautifulSoup, "find", return_value=result):
         self.assertIsNone(check_for_meta("content", "url"))
예제 #23
0
    def test_check_for_meta_not_search_url(self):
        content = """
            <!DOCTYPE html>
            <html>
                <head>
                    <meta http-equiv="refresh" content="5; url=">
                </head>
                <body></body>
            </html>
        """
        url = 'url'

        self.assertEquals(None, lib.check_for_meta(content, url))
예제 #24
0
    def test_check_for_meta_not_refresh(self):
        content = """
            <!DOCTYPE html>
            <html>
                <head>
                    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                </head>
                <body></body>
            </html>
        """
        url = 'url'

        self.assertEquals(None, lib.check_for_meta(content, url))
예제 #25
0
    def test_check_for_meta_len_splitted_not_equals_2(self):
        content = """
            <!DOCTYPE html>
            <html>
                <head>
                    <meta http-equiv="ReFresh" content="5" />
                </head>
                <body></body>
            </html>
        """
        url = 'url'

        self.assertEquals(None, lib.check_for_meta(content, url))
예제 #26
0
    def test_check_for_meta_not_http_equiv(self):
        content = """
            <!DOCTYPE html>
            <html>
                <head>
                    <meta name="refresh" content="content" />
                </head>
                <body></body>
            </html>
        """
        url = 'url'

        self.assertEquals(None, lib.check_for_meta(content, url))
예제 #27
0
 def test_check_for_meta_dfs(self):
     """
     DFS -> 100% line coverage, but bad branch cov.
     """
     result = mock.MagicMock(name="result")
     result.attrs = {
         "content": "wat;url=",
         "http-equiv": "refresh",
     }
     url = 'example.com/hell.php?what=123'
     result.__getitem__ = mock.Mock(return_value=result.attrs["content"] + url)
     with mock.patch.object(BeautifulSoup, "find", return_value=result):
         check = check_for_meta("content", "url")
         self.assertEquals(check, url)
예제 #28
0
 def test_check_for_meta(self):
     url = 'http://url.ru'
     redirect_url = 'http://redirect-url.ru'
     content = """
         <!DOCTYPE html>
         <html>
             <head>
                 <meta http-equiv="refresh" content="5; url=""" + redirect_url + """">
             </head>
             <body></body>
         </html>
     """
     with mock.patch('source.lib.to_unicode', mock.Mock(return_value=redirect_url)):
         self.assertEquals(lib.urljoin(url, redirect_url), lib.check_for_meta(content, url))
예제 #29
0
    def test_check_for_meta_wrong_search(self):
        """
        re.search returned none
        """
        result = mock.MagicMock(name="result")
        result.attrs = {
            "content": "wat;url=",
            "http-equiv": "refresh",
        }
        url = 'example.com/hell.php?what=123'
        result.__getitem__ = mock.Mock(return_value=result.attrs["content"] + url)

        with mock.patch.object(BeautifulSoup, "find", return_value=result):
            with mock.patch("source.lib.urljoin", mock.Mock()):
                self.assertIsNone(check_for_meta("content", "url"))
예제 #30
0
 def test_check_for_meta_correct_content_correct_research(self):
     """
     Весь путь в check_for_meta
     :return:
     """
     result = mock.MagicMock(name="result")
     result.attrs = {
         "content": True,
         "http-equiv": "refresh"
     }
     url = "localhost/lal?what_are_you_doing=dont_know"
     result.__getitem__ = mock.Mock(return_value="wait;url=" + url)
     with mock.patch.object(BeautifulSoup, 'find', return_value=result):
         check = check_for_meta("content", "url")
         self.assertEquals(check, url)
예제 #31
0
    def test_check_for_meta_no_equal_sign(self):
        content = r"""
            <html>
                <head>
                    <meta http-equiv="refresh" content="5; url">
                </head>
                <body>
                </body>
            </html>"""

        url_prefix = 'http://mail.ru'

        url = lib.check_for_meta(content, url_prefix)

        assert url is None, 'url found but no url was specified (no equal sign)'
예제 #32
0
    def test_check_for_meta_bad_html(self):
        content = """
            <html>
                <head>
                    <meta http-equiv="refresh" content="5url={0}">
                </head>
                <body>
                </body>
            </html>"""

        url_prefix = 'http://mail.ru'

        url = lib.check_for_meta(content, url_prefix)

        self.assertEquals(url, None, 'such bad html should be parsed')
예제 #33
0
 def test_check_for_meta_cant_research(self):
     """
     re.search ничего не вернул
     :return:
     """
     result = mock.MagicMock(name="result")
     result.attrs = {
         "content": True,
         "http-equiv": "refresh"
     }
     url = "localhost/lal?what_are_you_doing=dont_know"
     result.__getitem__ = mock.Mock(return_value="wait;url=" + url)
     with mock.patch("source.lib.urljoin", mock.Mock()) as urljoin:
         with mock.patch.object(BeautifulSoup, 'find', return_value=result):
             check = check_for_meta("content", "url")
             self.assertFalse(urljoin.called)
             self.assertIsNone(check)
예제 #34
0
 def test_check_for_bad_meta(self):
     meta = '<html><head><meta http-equiv="refresh" content="0;URL=''http://thetudors.example.com/''; sdfsdfsdf" /></head></html>'
     self.assertIsNone(check_for_meta(meta, ''))
예제 #35
0
 def test_check_for_meta_wrong_url(self):
     self.assertEqual(
         check_for_meta('<html><head><meta http-equiv="refresh" content="0;URwqeL=''http://thetudors.example.com/''" /></head></html>', ''),
         None
     )
예제 #36
0
 def test_check_for_meta_wrong(self):
     self.assertEqual(check_for_meta('', ''), None)