Skip to content

Commit

Permalink
tests: migration: Split & extend disqus testcases
Browse files Browse the repository at this point in the history
The addition of a thread with an empty id in `disqus.xml`
necessitates adjusting the unit tests to work around this.
  • Loading branch information
ix5 committed May 1, 2022
1 parent 248ee9b commit 7ea6148
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions isso/tests/test_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,41 @@

class TestMigration(unittest.TestCase):

def test_disqus(self):
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).migrate()
Disqus(db, xml, empty_id=False).migrate()

# TODO: Convert unittest testcases with assertX to plain pytest
# asserts, allowing capturing of stdout
#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()), 2)
len(db.execute("SELECT id FROM comments").fetchall()), 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)
Expand Down

0 comments on commit 7ea6148

Please sign in to comment.