Пример #1
0
    def test_disqus_empty_id_workaround(self):
        """
        Simulate supplying --empty_id to import call to work around empty
        thread ids
        """

        xml = join(dirname(__file__), "disqus.xml")
        xxx = tempfile.NamedTemporaryFile()

        db = SQLite3(xxx.name, conf)
        Disqus(db, xml, empty_id=True).migrate()

        self.assertEqual(
            len(db.execute("SELECT id FROM comments").fetchall()), 3)

        self.assertEqual(db.threads["/"]["title"], "Hello, World!")
        self.assertEqual(db.threads["/"]["id"], 1)

        a = db.comments.get(1)

        self.assertEqual(a["author"], "peter")
        self.assertEqual(a["email"], "*****@*****.**")
        self.assertEqual(a["remote_addr"], "127.0.0.0")

        b = db.comments.get(2)
        self.assertEqual(b["parent"], a["id"])
Пример #2
0
    def test_detection(self):

        wp = """\
                <?xml version="1.0" encoding="UTF-8"?>
                <rss version="2.0"
                    xmlns:content="http://purl.org/rss/1.0/modules/content/"
                    xmlns:dc="http://purl.org/dc/elements/1.1/"
                    xmlns:wp="http://wordpress.org/export/%s/">"""

        self.assertEqual(WordPress.detect(wp % "invalid"), None)

        for version in ("1.0", "1.1", "1.2", "1.3"):
            self.assertEqual(WordPress.detect(wp % version),
                             "http://wordpress.org/export/%s/" % version)

        dq = '''\
        <?xml version="1.0"?>
        <disqus xmlns="http://disqus.com"
                xmlns:dsq="http://disqus.com/disqus-internals"'''
        self.assertIsNotNone(Disqus.detect(dq))
Пример #3
0
    def test_detection(self):

        wp = """\
                <?xml version="1.0" encoding="UTF-8"?>
                <rss version="2.0"
                    xmlns:content="http://purl.org/rss/1.0/modules/content/"
                    xmlns:dc="http://purl.org/dc/elements/1.1/"
                    xmlns:wp="http://wordpress.org/export/%s/">"""

        self.assertEqual(WordPress.detect(wp % "invalid"), None)

        for version in ("1.0", "1.1", "1.2", "1.3"):
            self.assertEqual(WordPress.detect(wp % version),
                             "http://wordpress.org/export/%s/" % version)

        dq = '''\
        <?xml version="1.0"?>
        <disqus xmlns="http://disqus.com"
                xmlns:dsq="http://disqus.com/disqus-internals"'''
        self.assertIsNotNone(Disqus.detect(dq))
Пример #4
0
    def test_disqus(self):

        xml = join(dirname(__file__), "disqus.xml")
        xxx = tempfile.NamedTemporaryFile()

        db = SQLite3(xxx.name, Config.load(None))
        Disqus(db, xml).migrate()

        self.assertEqual(len(db.execute("SELECT id FROM comments").fetchall()), 2)

        self.assertEqual(db.threads["/"]["title"], "Hello, World!")
        self.assertEqual(db.threads["/"]["id"], 1)

        a = db.comments.get(1)

        self.assertEqual(a["author"], "peter")
        self.assertEqual(a["email"], "*****@*****.**")
        self.assertEqual(a["remote_addr"], "127.0.0.0")

        b = db.comments.get(2)
        self.assertEqual(b["parent"], a["id"])
Пример #5
0
    def test_disqus_empty_id(self):
        """
        Fails with empty thread id
        """

        xml = join(dirname(__file__), "disqus.xml")
        xxx = tempfile.NamedTemporaryFile()

        db = SQLite3(xxx.name, conf)
        Disqus(db, xml, empty_id=False).migrate()

        # TODO: Convert unittest testcases with assertX to plain pytest
        # asserts, allowing capturing of stdout, like this:
        #
        # def test_disqus_empty_id(self, capfd):
        # [...]
        # out, err = capfd.readouterr()
        # assert out == \
        #     "Isso couldn't import any thread, try again with --empty-id\n"

        self.assertEqual(
            len(db.execute("SELECT id FROM comments").fetchall()), 0)