Merge branch 'feature/75', closes #75
commit
4ee509ed02
@ -1,30 +1,95 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
try:
|
||||
import unittest2 as unittest
|
||||
except ImportError:
|
||||
import unittest
|
||||
|
||||
import tempfile
|
||||
from os.path import join, dirname
|
||||
|
||||
from isso.core import Config
|
||||
|
||||
from isso.db import SQLite3
|
||||
from isso.migrate import disqus
|
||||
from isso.migrate import Disqus, WordPress
|
||||
|
||||
|
||||
class TestMigration(unittest.TestCase):
|
||||
|
||||
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"], "foo@bar.com")
|
||||
self.assertEqual(a["remote_addr"], "127.0.0.0")
|
||||
|
||||
b = db.comments.get(2)
|
||||
self.assertEqual(b["parent"], a["id"])
|
||||
|
||||
def test_wordpress(self):
|
||||
|
||||
xml = join(dirname(__file__), "wordpress.xml")
|
||||
xxx = tempfile.NamedTemporaryFile()
|
||||
|
||||
db = SQLite3(xxx.name, Config.load(None))
|
||||
WordPress(db, xml).migrate()
|
||||
|
||||
self.assertEqual(db.threads["/2014/test/"]["title"], "Hello, World!")
|
||||
self.assertEqual(db.threads["/2014/test/"]["id"], 1)
|
||||
|
||||
self.assertEqual(db.threads["/?p=4"]["title"], "...")
|
||||
self.assertEqual(db.threads["/?p=4"]["id"], 2)
|
||||
|
||||
self.assertEqual(len(db.execute("SELECT id FROM threads").fetchall()), 2)
|
||||
self.assertEqual(len(db.execute("SELECT id FROM comments").fetchall()), 7)
|
||||
|
||||
first = db.comments.get(1)
|
||||
self.assertEqual(first["author"], "Ohai")
|
||||
self.assertEqual(first["text"], "Erster!1")
|
||||
self.assertEqual(first["remote_addr"], "82.119.20.0")
|
||||
|
||||
def test_disqus():
|
||||
second = db.comments.get(2)
|
||||
self.assertEqual(second["author"], "Tester")
|
||||
self.assertEqual(second["text"], "Zweiter.")
|
||||
|
||||
xml = join(dirname(__file__), "disqus.xml")
|
||||
xxx = tempfile.NamedTemporaryFile()
|
||||
for i in (3, 4, 5):
|
||||
self.assertEqual(db.comments.get(i)["parent"], second["id"])
|
||||
|
||||
db = SQLite3(xxx.name, Config.load(None))
|
||||
disqus(db, xml)
|
||||
last = db.comments.get(6)
|
||||
self.assertEqual(last["author"], "Letzter :/")
|
||||
self.assertEqual(last["parent"], None)
|
||||
|
||||
assert db.threads["/"]["title"] == "Hello, World!"
|
||||
assert db.threads["/"]["id"] == 1
|
||||
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/">"""
|
||||
|
||||
a = db.comments.get(1)
|
||||
self.assertEqual(WordPress.detect(wp % "invalid"), None)
|
||||
|
||||
assert a["author"] == "peter"
|
||||
assert a["email"] == "foo@bar.com"
|
||||
for version in ("1.0", "1.1", "1.2", "1.3"):
|
||||
self.assertEqual(WordPress.detect(wp % version),
|
||||
"http://wordpress.org/export/%s/" % version)
|
||||
|
||||
b = db.comments.get(2)
|
||||
assert b["parent"] == a["id"]
|
||||
dq = '''\
|
||||
<?xml version="1.0"?>
|
||||
<disqus xmlns="http://disqus.com"
|
||||
xmlns:dsq="http://disqus.com/disqus-internals"'''
|
||||
self.assertIsNotNone(Disqus.detect(dq))
|
||||
|
@ -0,0 +1,144 @@
|
||||
<?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/1.0/">
|
||||
<!-- This WXR dump is incomplete! It only contains elements needed for an
|
||||
import, a few are unused yet, but eventually useful later.
|
||||
|
||||
The <item> node is derived from a sort-of real-world WordPress blog,
|
||||
but modified to test various things.
|
||||
-->
|
||||
<channel>
|
||||
<item>
|
||||
<title>Hello, World!</title>
|
||||
<link>http://example.tld/2014/test/</link>
|
||||
<pubDate>Tue, 14 Jan 2014 17:31:03 +0000</pubDate>
|
||||
<dc:creator><![CDATA[Tester]]></dc:creator>
|
||||
<wp:post_id>18</wp:post_id>
|
||||
<wp:post_date>2014-01-14 17:31:03</wp:post_date>
|
||||
<wp:post_date_gmt>2014-01-14 17:31:03</wp:post_date_gmt>
|
||||
<wp:comment_status>open</wp:comment_status>
|
||||
<wp:post_name>test</wp:post_name>
|
||||
<wp:status>publish</wp:status>
|
||||
<wp:post_type>post</wp:post_type>
|
||||
<wp:comment>
|
||||
<wp:comment_id>2</wp:comment_id>
|
||||
<wp:comment_author><![CDATA[Ohai]]></wp:comment_author>
|
||||
<wp:comment_author_email>test@example.org
|
||||
</wp:comment_author_email>
|
||||
<wp:comment_author_url>http://example.tld/</wp:comment_author_url>
|
||||
<wp:comment_author_IP>::ffff:82.119.20.0</wp:comment_author_IP>
|
||||
<wp:comment_date>2014-01-14 17:32:12</wp:comment_date>
|
||||
<wp:comment_date_gmt>2014-01-14 17:32:12</wp:comment_date_gmt>
|
||||
<wp:comment_content>
|
||||
<![CDATA[Erster!1]]></wp:comment_content>
|
||||
<wp:comment_approved>1</wp:comment_approved>
|
||||
|
||||
<!-- what's that? -->
|
||||
<wp:comment_type></wp:comment_type>
|
||||
|
||||
<wp:comment_parent>0</wp:comment_parent>
|
||||
<wp:comment_user_id>0</wp:comment_user_id>
|
||||
</wp:comment>
|
||||
<wp:comment>
|
||||
<wp:comment_id>6</wp:comment_id>
|
||||
<wp:comment_author><![CDATA[Tester]]></wp:comment_author>
|
||||
<wp:comment_author_email>info@posativ.org
|
||||
</wp:comment_author_email>
|
||||
<wp:comment_author_url></wp:comment_author_url>
|
||||
<wp:comment_author_IP>::ffff:86.56.63.0</wp:comment_author_IP>
|
||||
<wp:comment_date>2014-04-29 15:21:27</wp:comment_date>
|
||||
<wp:comment_date_gmt>2014-04-29 15:21:27</wp:comment_date_gmt>
|
||||
<wp:comment_content><![CDATA[Zweiter.]]></wp:comment_content>
|
||||
<wp:comment_approved>1</wp:comment_approved>
|
||||
<wp:comment_type></wp:comment_type>
|
||||
<wp:comment_parent>0</wp:comment_parent>
|
||||
<wp:comment_user_id>1</wp:comment_user_id>
|
||||
</wp:comment>
|
||||
<wp:comment>
|
||||
<wp:comment_id>7</wp:comment_id>
|
||||
<wp:comment_author><![CDATA[Tester]]></wp:comment_author>
|
||||
<wp:comment_author_email>info@posativ.org
|
||||
</wp:comment_author_email>
|
||||
<wp:comment_author_url></wp:comment_author_url>
|
||||
<wp:comment_author_IP>::ffff:86.56.63.0</wp:comment_author_IP>
|
||||
<wp:comment_date_gmt>2014-04-29 15:21:35</wp:comment_date_gmt>
|
||||
<wp:comment_content><![CDATA[Drölfter!]]></wp:comment_content>
|
||||
<wp:comment_approved>1</wp:comment_approved>
|
||||
<wp:comment_parent>6</wp:comment_parent>
|
||||
</wp:comment>
|
||||
<wp:comment>
|
||||
<wp:comment_id>8</wp:comment_id>
|
||||
<wp:comment_author><![CDATA[Tester]]></wp:comment_author>
|
||||
<wp:comment_author_email>info@posativ.org
|
||||
</wp:comment_author_email>
|
||||
<wp:comment_author_url></wp:comment_author_url>
|
||||
<wp:comment_author_IP>::ffff:86.56.63.0</wp:comment_author_IP>
|
||||
<wp:comment_date>2014-04-29 15:21:45</wp:comment_date>
|
||||
<wp:comment_date_gmt>2014-04-29 15:21:45</wp:comment_date_gmt>
|
||||
<wp:comment_content>
|
||||
<![CDATA[Yet another reply.]]></wp:comment_content>
|
||||
<wp:comment_approved>1</wp:comment_approved>
|
||||
<wp:comment_type></wp:comment_type>
|
||||
<wp:comment_parent>7</wp:comment_parent>
|
||||
<wp:comment_user_id>1</wp:comment_user_id>
|
||||
</wp:comment>
|
||||
<wp:comment>
|
||||
<wp:comment_id>9</wp:comment_id>
|
||||
<wp:comment_author><![CDATA[Tester]]></wp:comment_author>
|
||||
<wp:comment_author_email>info@posativ.org
|
||||
</wp:comment_author_email>
|
||||
<wp:comment_author_url></wp:comment_author_url>
|
||||
<wp:comment_author_IP>::ffff:86.56.63.0</wp:comment_author_IP>
|
||||
<wp:comment_date>2014-04-29 15:21:52</wp:comment_date>
|
||||
<wp:comment_date_gmt>2014-04-29 15:21:52</wp:comment_date_gmt>
|
||||
<wp:comment_content><![CDATA[...]]></wp:comment_content>
|
||||
<wp:comment_approved>1</wp:comment_approved>
|
||||
<wp:comment_type></wp:comment_type>
|
||||
<wp:comment_parent>7</wp:comment_parent>
|
||||
<wp:comment_user_id>1</wp:comment_user_id>
|
||||
</wp:comment>
|
||||
<wp:comment>
|
||||
<wp:comment_id>10</wp:comment_id>
|
||||
<wp:comment_author><![CDATA[Letzter :/]]></wp:comment_author>
|
||||
<wp:comment_author_email>info@posativ.org
|
||||
</wp:comment_author_email>
|
||||
<wp:comment_author_url></wp:comment_author_url>
|
||||
<wp:comment_author_IP>::ffff:86.56.63.0</wp:comment_author_IP>
|
||||
<wp:comment_date>2014-04-29 15:21:56</wp:comment_date>
|
||||
<wp:comment_date_gmt>2014-04-29 15:21:56</wp:comment_date_gmt>
|
||||
<wp:comment_content><![CDATA[...]]></wp:comment_content>
|
||||
<wp:comment_approved>1</wp:comment_approved>
|
||||
<wp:comment_type></wp:comment_type>
|
||||
<wp:comment_parent>0</wp:comment_parent>
|
||||
<wp:comment_user_id>1</wp:comment_user_id>
|
||||
</wp:comment>
|
||||
</item>
|
||||
|
||||
<!-- handle ?p=X urls -->
|
||||
<item>
|
||||
<title>...</title>
|
||||
<link>http://example.tld/?p=4</link>
|
||||
<wp:comment>
|
||||
<wp:comment_id>11</wp:comment_id>
|
||||
<wp:comment_author><![CDATA[Anonymous]]></wp:comment_author>
|
||||
<wp:comment_author_email>info@posativ.org
|
||||
</wp:comment_author_email>
|
||||
<wp:comment_author_url></wp:comment_author_url>
|
||||
<wp:comment_author_IP>::ffff:86.56.63.0</wp:comment_author_IP>
|
||||
<wp:comment_date>2014-04-29 15:21:56</wp:comment_date>
|
||||
<wp:comment_date_gmt>2014-04-29 15:21:57</wp:comment_date_gmt>
|
||||
<wp:comment_content><![CDATA[...]]></wp:comment_content>
|
||||
<wp:comment_approved>1</wp:comment_approved>
|
||||
<wp:comment_type></wp:comment_type>
|
||||
<wp:comment_parent>0</wp:comment_parent>
|
||||
<wp:comment_user_id>1</wp:comment_user_id>
|
||||
</wp:comment>
|
||||
</item>
|
||||
<item>
|
||||
<title>No comments</title>
|
||||
<link>http://example.tld/?p=6</link>
|
||||
</item>
|
||||
</channel>
|
||||
</rss>
|
Loading…
Reference in new issue