From 2a86b468935cd4ca26c0c9499dece972677a10e6 Mon Sep 17 00:00:00 2001
From: Martin Zimmermann
Date: Wed, 18 Dec 2013 12:51:14 +0100
Subject: [PATCH] add test for disqus import
---
isso/migrate.py | 2 +-
specs/disqus.xml | 81 +++++++++++++++++++++++++++++++++++++++++
specs/test_migration.py | 30 +++++++++++++++
3 files changed, 112 insertions(+), 1 deletion(-)
create mode 100644 specs/disqus.xml
create mode 100644 specs/test_migration.py
diff --git a/isso/migrate.py b/isso/migrate.py
index 99e6869..93d645f 100644
--- a/isso/migrate.py
+++ b/isso/migrate.py
@@ -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)):
diff --git a/specs/disqus.xml b/specs/disqus.xml
new file mode 100644
index 0000000..e105a66
--- /dev/null
+++ b/specs/disqus.xml
@@ -0,0 +1,81 @@
+
+
+
+ disqusdev
+ Technology
+
+
+
+ some-id
+ disqusdev
+
+ http://example.org/
+ Hello, World!
+
+ 2012-12-12T12:12:12Z
+
+ Baz
+ foo@bar.com
+
+
+
+
+
+
+
+
+
+
+
+ ...
+ 2013-10-10T19:20:29Z
+ false
+ false
+
+ foo@bar.com
+ peter
+ true
+
+ 127.0.0.1
+
+
+
+
+
+ Hello, World.
]]>
+ 2013-10-11T06:51:33Z
+ false
+ false
+
+ foo@bar.com
+ user
+ false
+ user
+
+ 127.0.0.1
+
+
+
+
+
+
+
+ ...
+ 2013-10-10T19:20:29Z
+ false
+ false
+
+ foo@bar.com
+ where am I?
+ true
+
+ 127.0.0.1
+
+
+
+
diff --git a/specs/test_migration.py b/specs/test_migration.py
new file mode 100644
index 0000000..8a40ea2
--- /dev/null
+++ b/specs/test_migration.py
@@ -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"]