Ejemplo n.º 1
0
    def test_comment2(self):
        html = """
        <html>
        <head><title>Foo</title></head>
        <body>
        Some text.
        <!-- HTML comment -->
        Some more text.
        <p>Text</p>
        More text
        </body>
        </html>
        """

        og = decode_and_calc_og(html, "http://example.com/test.html")

        self.assertEqual(
            og,
            {
                "og:title":
                "Foo",
                "og:description":
                "Some text.\n\nSome more text.\n\nText\n\nMore text",
            },
        )
Ejemplo n.º 2
0
    def test_missing_title(self):
        html = """
        <html>
        <body>
        Some text.
        </body>
        </html>
        """

        og = decode_and_calc_og(html, "http://example.com/test.html")

        self.assertEqual(og, {"og:title": None, "og:description": "Some text."})
Ejemplo n.º 3
0
    def test_missing_title(self):
        html = u"""
        <html>
        <body>
        Some text.
        </body>
        </html>
        """

        og = decode_and_calc_og(html, "http://example.com/test.html")

        self.assertEquals(og, {u"og:title": None, u"og:description": u"Some text."})
Ejemplo n.º 4
0
    def test_simple(self):
        html = u"""
        <html>
        <head><title>Foo</title></head>
        <body>
        Some text.
        </body>
        </html>
        """

        og = decode_and_calc_og(html, "http://example.com/test.html")

        self.assertEquals(og, {u"og:title": u"Foo", u"og:description": u"Some text."})
Ejemplo n.º 5
0
    def test_h1_as_title(self):
        html = u"""
        <html>
        <meta property="og:description" content="Some text."/>
        <body>
        <h1>Title</h1>
        </body>
        </html>
        """

        og = decode_and_calc_og(html, "http://example.com/test.html")

        self.assertEquals(og, {u"og:title": u"Title", u"og:description": u"Some text."})
Ejemplo n.º 6
0
 def test_invalid_encoding2(self):
     """A body which doesn't match the sent character encoding."""
     # Note that this contains an invalid UTF-8 sequence in the title.
     html = b"""
     <html>
     <head><title>\xff\xff Foo</title></head>
     <body>
     Some text.
     </body>
     </html>
     """
     og = decode_and_calc_og(html, "http://example.com/test.html")
     self.assertEqual(og, {"og:title": "ÿÿ Foo", "og:description": "Some text."})
Ejemplo n.º 7
0
    def test_h1_as_title(self):
        html = """
        <html>
        <meta property="og:description" content="Some text."/>
        <body>
        <h1>Title</h1>
        </body>
        </html>
        """

        og = decode_and_calc_og(html, "http://example.com/test.html")

        self.assertEqual(og, {"og:title": "Title", "og:description": "Some text."})
Ejemplo n.º 8
0
    def test_simple(self):
        html = """
        <html>
        <head><title>Foo</title></head>
        <body>
        Some text.
        </body>
        </html>
        """

        og = decode_and_calc_og(html, "http://example.com/test.html")

        self.assertEqual(og, {"og:title": "Foo", "og:description": "Some text."})
Ejemplo n.º 9
0
 def test_invalid_encoding(self):
     """An invalid character encoding should be ignored and treated as UTF-8, if possible."""
     html = """
     <html>
     <head><title>Foo</title></head>
     <body>
     Some text.
     </body>
     </html>
     """
     og = decode_and_calc_og(
         html, "http://example.com/test.html", "invalid-encoding"
     )
     self.assertEqual(og, {"og:title": "Foo", "og:description": "Some text."})
Ejemplo n.º 10
0
    def test_missing_title_and_broken_h1(self):
        html = u"""
        <html>
        <body>
        <h1><a href="foo"/></h1>
        Some text.
        </body>
        </html>
        """

        og = decode_and_calc_og(html, "http://example.com/test.html")

        self.assertEquals(og, {
            u"og:title": None,
            u"og:description": u"Some text."
        })
Ejemplo n.º 11
0
    def test_comment(self):
        html = u"""
        <html>
        <head><title>Foo</title></head>
        <body>
        <!-- HTML comment -->
        Some text.
        </body>
        </html>
        """

        og = decode_and_calc_og(html, "http://example.com/test.html")

        self.assertEquals(og, {
            u"og:title": u"Foo",
            u"og:description": u"Some text."
        })
Ejemplo n.º 12
0
    def test_script(self):
        html = u"""
        <html>
        <head><title>Foo</title></head>
        <body>
        <script> (function() {})() </script>
        Some text.
        </body>
        </html>
        """

        og = decode_and_calc_og(html, "http://example.com/test.html")

        self.assertEquals(og, {
            u"og:title": u"Foo",
            u"og:description": u"Some text."
        })
Ejemplo n.º 13
0
    def test_comment(self):
        html = """
        <html>
        <head><title>Foo</title></head>
        <body>
        <!-- HTML comment -->
        Some text.
        </body>
        </html>
        """

        og = decode_and_calc_og(html, "http://example.com/test.html")

        self.assertEquals(og, {
            "og:title": "Foo",
            "og:description": "Some text."
        })
Ejemplo n.º 14
0
    def test_script(self):
        html = """
        <html>
        <head><title>Foo</title></head>
        <body>
        <script> (function() {})() </script>
        Some text.
        </body>
        </html>
        """

        og = decode_and_calc_og(html, "http://example.com/test.html")

        self.assertEquals(og, {
            "og:title": "Foo",
            "og:description": "Some text."
        })
Ejemplo n.º 15
0
    def test_comment2(self):
        html = u"""
        <html>
        <head><title>Foo</title></head>
        <body>
        Some text.
        <!-- HTML comment -->
        Some more text.
        <p>Text</p>
        More text
        </body>
        </html>
        """

        og = decode_and_calc_og(html, "http://example.com/test.html")

        self.assertEquals(og, {
            u"og:title": u"Foo",
            u"og:description": u"Some text.\n\nSome more text.\n\nText\n\nMore text"
        })
Ejemplo n.º 16
0
 def test_empty(self):
     html = ""
     og = decode_and_calc_og(html, "http://example.com/test.html")
     self.assertEqual(og, {})
Ejemplo n.º 17
0
 def test_no_tree(self):
     """A valid body with no tree in it."""
     html = b"\x00"
     og = decode_and_calc_og(html, "http://example.com/test.html")
     self.assertEqual(og, {})
Ejemplo n.º 18
0
 def test_empty(self):
     """Test a body with no data in it."""
     html = b""
     og = decode_and_calc_og(html, "http://example.com/test.html")
     self.assertEqual(og, {})