add test for disqus import

This commit is contained in:
Martin Zimmermann 2013-12-18 12:51:14 +01:00
parent f81b955aa5
commit 2a86b46893
3 changed files with 112 additions and 1 deletions

View File

@ -74,7 +74,7 @@ def disqus(db, xmlfile):
res[post.find('%sthread' % ns).attrib.get(dsq + 'id')].append(item)
num = len(tree.findall('%sthread' % ns))
cols = int(os.popen('stty size', 'r').read().split()[1])
cols = int((os.popen('stty size', 'r').read() or "25 80").split()[1])
for i, thread in enumerate(tree.findall('%sthread' % ns)):

81
specs/disqus.xml Normal file
View File

@ -0,0 +1,81 @@
<?xml version="1.0"?>
<disqus xmlns="http://disqus.com"
xmlns:dsq="http://disqus.com/disqus-internals"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://disqus.com/api/schemas/1.0/disqus.xsd
http://disqus.com/api/schemas/1.0/internals.xsd"
>
<category dsq:id="1">
<forum>disqusdev</forum>
<title>Technology</title>
</category>
<thread dsq:id="2">
<id>some-id</id>
<forum>disqusdev</forum>
<category dsq:id="1"/>
<link>http://example.org/</link>
<title>Hello, World!</title>
<message/>
<createdAt>2012-12-12T12:12:12Z</createdAt>
<author>
<name>Baz</name>
<email>foo@bar.com</email>
</author>
</thread>
<!-- Yeah... occurs. No idea, why. -->
<thread dsq:id="3">
<id/>
</thread>
<!-- regular post -->
<post dsq:id="4">
<id />
<message>...</message>
<createdAt>2013-10-10T19:20:29Z</createdAt>
<isDeleted>false</isDeleted>
<isSpam>false</isSpam>
<author>
<email>foo@bar.com</email>
<name>peter</name>
<isAnonymous>true</isAnonymous>
</author>
<ipAddress>127.0.0.1</ipAddress>
<thread dsq:id="2" />
</post>
<!-- reference to previous post -->
<post dsq:id="5">
<message><![CDATA[<p>Hello, World.</p>]]></message>
<createdAt>2013-10-11T06:51:33Z</createdAt>
<isDeleted>false</isDeleted>
<isSpam>false</isSpam>
<author>
<email>foo@bar.com</email>
<name>user</name>
<isAnonymous>false</isAnonymous>
<username>user</username>
</author>
<ipAddress>127.0.0.1</ipAddress>
<thread dsq:id="2" />
<parent dsq:id="4" />
</post>
<!-- orphan comment (= thread id no longer exists) -->
<post dsq:id="6">
<id />
<message>...</message>
<createdAt>2013-10-10T19:20:29Z</createdAt>
<isDeleted>false</isDeleted>
<isSpam>false</isSpam>
<author>
<email>foo@bar.com</email>
<name>where am I?</name>
<isAnonymous>true</isAnonymous>
</author>
<ipAddress>127.0.0.1</ipAddress>
<thread dsq:id="1337" />
</post>
</disqus>

30
specs/test_migration.py Normal file
View File

@ -0,0 +1,30 @@
# -*- encoding: utf-8 -*-
import tempfile
from os.path import join, dirname
from isso.core import Config
from isso.db import SQLite3
from isso.migrate import disqus
def test_disqus():
xml = join(dirname(__file__), "disqus.xml")
xxx = tempfile.NamedTemporaryFile()
db = SQLite3(xxx.name, Config.load(None))
disqus(db, xml)
assert db.threads["/"]["title"] == "Hello, World!"
assert db.threads["/"]["id"] == 1
a = db.comments.get(1)
assert a["author"] == "peter"
assert a["email"] == "foo@bar.com"
b = db.comments.get(2)
assert b["parent"] == a["id"]