def test_session_key_migration(self): conf = config.new({ "general": { "dbpath": "/dev/null", "max-age": "1h" } }) conf.set("general", "session-key", "supersecretkey") with sqlite3.connect(self.path) as con: con.execute("PRAGMA user_version = 1") con.execute("CREATE TABLE threads (id INTEGER PRIMARY KEY)") db = SQLite3(self.path, conf) self.assertEqual(db.version, SQLite3.MAX_VERSION) self.assertEqual(db.preferences.get("session-key"), conf.get("general", "session-key")) # try again, now with the session-key removed from our conf conf.remove_option("general", "session-key") db = SQLite3(self.path, conf) self.assertEqual(db.version, SQLite3.MAX_VERSION) self.assertEqual(db.preferences.get("session-key"), "supersecretkey")
def test_session_key_migration(self): conf = config.new( {"general": { "dbpath": "/dev/null", "max-age": "1h" }}) conf.set("general", "session-key", "supersecretkey") with sqlite3.connect(self.path) as con: con.execute("PRAGMA user_version = 1") con.execute("CREATE TABLE threads (id INTEGER PRIMARY KEY)") db = SQLite3(self.path, conf) self.assertEqual(db.version, SQLite3.MAX_VERSION) self.assertEqual(db.preferences.get("session-key"), conf.get("general", "session-key")) # try again, now with the session-key removed from our conf conf.remove_option("general", "session-key") db = SQLite3(self.path, conf) self.assertEqual(db.version, SQLite3.MAX_VERSION) self.assertEqual(db.preferences.get("session-key"), "supersecretkey")
def _new(val): conf = config.new({ "hash": { "algorithm": val, "salt": "" } }) return new(conf.section("hash"))
def test_limit_nested_comments(self): tree = { 1: None, 2: None, 3: 2, 4: 3, 7: 3, 5: 2, 6: None } with sqlite3.connect(self.path) as con: con.execute("PRAGMA user_version = 2") con.execute("CREATE TABLE threads (" " id INTEGER PRIMARY KEY," " uri VARCHAR UNIQUE," " title VARCHAR)") con.execute("CREATE TABLE comments (" " tid REFERENCES threads(id)," " id INTEGER PRIMARY KEY," " parent INTEGER," " created FLOAT NOT NULL, modified FLOAT," " block VARCHAR, edit VARCHAR," " text VARCHAR, email VARCHAR, website VARCHAR," " mode INTEGER," " remote_addr VARCHAR," " likes INTEGER DEFAULT 0," " voters BLOB)") con.execute("INSERT INTO threads (uri, title) VALUES (?, ?)", ("/", "Test")) for (id, parent) in iteritems(tree): con.execute("INSERT INTO comments (" " tid, parent, created)" "VALUEs (?, ?, ?)", (id, parent, id)) conf = config.new({ "general": { "dbpath": "/dev/null", "max-age": "1h" } }) SQLite3(self.path, conf) flattened = [ (1, None), (2, None), (3, 2), (4, 2), (5, 2), (6, None), (7, 2) ] with sqlite3.connect(self.path) as con: rv = con.execute("SELECT id, parent FROM comments ORDER BY created").fetchall() self.assertEqual(flattened, rv)
def test_limit_nested_comments(self): tree = { 1: None, 2: None, 3: 2, 4: 3, 7: 3, 5: 2, 6: None } with sqlite3.connect(self.path) as con: con.execute("PRAGMA user_version = 2") con.execute("CREATE TABLE threads (" " id INTEGER PRIMARY KEY," " uri VARCHAR UNIQUE," " title VARCHAR)") con.execute("CREATE TABLE comments (" " tid REFERENCES threads(id)," " id INTEGER PRIMARY KEY," " parent INTEGER," " created FLOAT NOT NULL, modified FLOAT," " text VARCHAR, email VARCHAR, website VARCHAR," " mode INTEGER," " remote_addr VARCHAR," " likes INTEGER DEFAULT 0," " dislikes INTEGER DEFAULT 0," " voters BLOB)") con.execute("INSERT INTO threads (uri, title) VALUES (?, ?)", ("/", "Test")) for (id, parent) in iteritems(tree): con.execute("INSERT INTO comments (" " tid, parent, created)" "VALUEs (?, ?, ?)", (id, parent, id)) conf = config.new({ "general": { "dbpath": "/dev/null", "max-age": "1h" } }) SQLite3(self.path, conf) flattened = [ (1, None), (2, None), (3, 2), (4, 2), (5, 2), (6, None), (7, 2) ] with sqlite3.connect(self.path) as con: rv = con.execute("SELECT id, parent FROM comments ORDER BY created").fetchall() self.assertEqual(flattened, rv)
def test_render(self): conf = config.new({ "markup": { "options": "autolink", "allowed-elements": "", "allowed-attributes": "" } }) renderer = html.Markup(conf.section("markup")).render self.assertEqual(renderer("http://example.org/ and sms:+1234567890"), '<p><a href="http://example.org/">http://example.org/</a> and sms:+1234567890</p>')
def test_defaults(self): conf = config.new( {"general": { "dbpath": "/dev/null", "max-age": "1h" }}) db = SQLite3(self.path, conf) self.assertEqual(db.version, SQLite3.MAX_VERSION) self.assertTrue(db.preferences.get("session-key", "").isalnum())
def test_defaults(self): conf = config.new({ "general": { "dbpath": "/dev/null", "max-age": "1h" } }) db = SQLite3(self.path, conf) self.assertEqual(db.version, SQLite3.MAX_VERSION) self.assertTrue(db.preferences.get("session-key", "").isalnum())
def test_sanitized_render_extensions(self): """Options should be normalized from both dashed-case or snake_case (legacy)""" conf = config.new({ "markup": { "options": "no_intra_emphasis", # Deliberately snake_case "flags": "", "allowed-elements": "", "allowed-attributes": "" } }) renderer = html.Markup(conf.section("markup")).render self.assertEqual(renderer("foo_bar_baz"), '<p>foo_bar_baz</p>') conf.set("markup", "options", "no-intra-emphasis") # dashed-case renderer = html.Markup(conf.section("markup")).render self.assertEqual(renderer("foo_bar_baz"), '<p>foo_bar_baz</p>')
try: import unittest2 as unittest except ImportError: import unittest import tempfile from os.path import join, dirname from isso import config from isso.db import SQLite3 from isso.migrate import Disqus, WordPress, autodetect conf = config.new({ "general": { "dbpath": "/dev/null", "max-age": "1h" } }) class TestMigration(unittest.TestCase): def test_disqus(self): xml = join(dirname(__file__), "disqus.xml") xxx = tempfile.NamedTemporaryFile() db = SQLite3(xxx.name, conf) Disqus(db, xml).migrate() self.assertEqual(len(db.execute("SELECT id FROM comments").fetchall()), 2)
from __future__ import unicode_literals try: import unittest2 as unittest except ImportError: import unittest import tempfile from os.path import join, dirname from isso import config from isso.db import SQLite3 from isso.migrate import Disqus, WordPress, autodetect conf = config.new({"general": {"dbpath": "/dev/null", "max-age": "1h"}}) class TestMigration(unittest.TestCase): def test_disqus(self): xml = join(dirname(__file__), "disqus.xml") xxx = tempfile.NamedTemporaryFile() db = SQLite3(xxx.name, conf) Disqus(db, xml).migrate() self.assertEqual(len(db.execute("SELECT id FROM comments").fetchall()), 2) self.assertEqual(db.threads["/"]["title"], "Hello, World!")
from isso import config from isso.db import SQLite3 from isso.migrate import Generic from pathlib import Path dbpath = "/Users/zrong/works/mysite/test.db" conf = config.new({"general": {"dbpath": dbpath, "max-age": "1h"}}) def test_generic(): print(Path(__file__).resolve()) # filepath = Path(__file__).parent.joinpath('isso', 'tests', 'generic.json') filepath = Path(__file__).parent.joinpath('generic.json') db = SQLite3(dbpath, conf) Generic(db, filepath).migrate() if __name__ == "__main__": test_generic()