Esempio n. 1
0
    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")

        second = db.comments.get(2)
        self.assertEqual(second["author"], "Tester")
        self.assertEqual(second["text"], "Zweiter.")

        for i in (3, 4, 5):
            self.assertEqual(db.comments.get(i)["parent"], second["id"])

        last = db.comments.get(6)
        self.assertEqual(last["author"], "Letzter :/")
        self.assertEqual(last["parent"], None)
Esempio n. 2
0
 def test_render(self):
     conf = Config.load(None).section("markup")
     renderer = html.Markup(conf).render
     self.assertEqual(
         renderer("http://example.org/ and sms:+1234567890"),
         '<p><a href="http://example.org/">http://example.org/</a> and sms:+1234567890</p>'
     )
Esempio n. 3
0
    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")

        second = db.comments.get(2)
        self.assertEqual(second["author"], "Tester")
        self.assertEqual(second["text"], "Zweiter.")

        for i in (3, 4, 5):
            self.assertEqual(db.comments.get(i)["parent"], second["id"])

        last = db.comments.get(6)
        self.assertEqual(last["author"], "Letzter :/")
        self.assertEqual(last["parent"], None)
Esempio n. 4
0
def main():

    parser = ArgumentParser(description="a blog comment hosting service")
    subparser = parser.add_subparsers(help="commands", dest="command")

    parser.add_argument('--version',
                        action='version',
                        version='%(prog)s ' + dist.version)
    parser.add_argument("-c",
                        dest="conf",
                        default="/etc/isso.conf",
                        metavar="/etc/isso.conf",
                        help="set configuration file")

    imprt = subparser.add_parser('import', help="import Disqus XML export")
    imprt.add_argument("dump", metavar="FILE")

    serve = subparser.add_parser("run", help="run server")

    args = parser.parse_args()
    conf = Config.load(args.conf)

    if args.command == "import":
        conf.set("guard", "enabled", "off")
        migrate.disqus(db.SQLite3(conf.get('general', 'dbpath'), conf),
                       args.dump)
        sys.exit(0)

    run_simple(conf.get('server', 'host'),
               conf.getint('server', 'port'),
               make_app(conf),
               threaded=True,
               use_reloader=conf.getboolean('server', 'reload'))
Esempio n. 5
0
def main():

    parser = ArgumentParser(description="a blog comment hosting service")
    subparser = parser.add_subparsers(help="commands", dest="command")

    parser.add_argument('--version', action='version', version='%(prog)s ' + dist.version)
    parser.add_argument("-c", dest="conf", default="/etc/isso.conf",
            metavar="/etc/isso.conf", help="set configuration file")

    imprt = subparser.add_parser('import', help="import Disqus XML export")
    imprt.add_argument("dump", metavar="FILE")
    imprt.add_argument("-n", "--dry-run", dest="dryrun", action="store_true",
                       help="perform a trial run with no changes made")
    imprt.add_argument("-t", "--type", dest="type", default=None,
                       choices=["disqus", "wordpress"], help="export type")

    serve = subparser.add_parser("run", help="run server")

    args = parser.parse_args()
    conf = Config.load(args.conf)

    if args.command == "import":
        conf.set("guard", "enabled", "off")

        if args.dryrun:
            xxx = tempfile.NamedTemporaryFile()
            dbpath = xxx.name
        else:
            dbpath = conf.get("general", "dbpath")

        mydb = db.SQLite3(dbpath, conf)
        migrate.dispatch(args.type, mydb, args.dump)

        sys.exit(0)

    if not any(conf.getiter("general", "host")):
        logger.error("No website(s) configured, Isso won't work.")
        sys.exit(1)

    if conf.get("server", "listen").startswith("http://"):
        host, port, _ = urlsplit(conf.get("server", "listen"))
        try:
            from gevent.pywsgi import WSGIServer
            WSGIServer((host, port), make_app(conf)).serve_forever()
        except ImportError:
            run_simple(host, port, make_app(conf), threaded=True,
                       use_reloader=conf.getboolean('server', 'reload'))
    else:
        sock = conf.get("server", "listen").partition("unix://")[2]
        try:
            os.unlink(sock)
        except OSError as ex:
            if ex.errno != errno.ENOENT:
                raise
        wsgi.SocketHTTPServer(sock, make_app(conf)).serve_forever()
Esempio n. 6
0
    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.load(None)
        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)
Esempio n. 7
0
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"] == "*****@*****.**"

    b = db.comments.get(2)
    assert b["parent"] == a["id"]
Esempio n. 8
0
    def test_session_key_migration(self):

        conf = Config.load(None)
        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")
Esempio n. 9
0
    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"], "*****@*****.**")
        self.assertEqual(a["remote_addr"], "127.0.0.0")

        b = db.comments.get(2)
        self.assertEqual(b["parent"], a["id"])
Esempio n. 10
0
    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.load(None)
        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)
Esempio n. 11
0
    def test_session_key_migration(self):

        conf = Config.load(None)
        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")
Esempio n. 12
0
def main():

    parser = ArgumentParser(description="a blog comment hosting service")
    subparser = parser.add_subparsers(help="commands", dest="command")

    parser.add_argument('--version', action='version', version='%(prog)s ' + dist.version)
    parser.add_argument("-c", dest="conf", default="/etc/isso.conf",
            metavar="/etc/isso.conf", help="set configuration file")

    imprt = subparser.add_parser('import', help="import Disqus XML export")
    imprt.add_argument("dump", metavar="FILE")

    serve = subparser.add_parser("run", help="run server")

    args = parser.parse_args()
    conf = Config.load(args.conf)

    if args.command == "import":
        conf.set("guard", "enabled", "off")
        migrate.disqus(db.SQLite3(conf.get('general', 'dbpath'), conf), args.dump)
        sys.exit(0)

    run_simple(conf.get('server', 'host'), conf.getint('server', 'port'), make_app(conf),
               threaded=True, use_reloader=conf.getboolean('server', 'reload'))
Esempio n. 13
0
# This portion of code is fork of gunicorn's example of running
# custom applications.
# Original link - http://gunicorn-docs.readthedocs.org/en/latest/custom.html
# 2009-2015 (c) Benoit Chesneau <*****@*****.**>
# 2009-2015 (c) Paul J. Davis <*****@*****.**>

import os
import sys
import multiprocessing

import gunicorn.app.base
from gunicorn.six import iteritems
from isso import make_app
from isso.core import Config

application = make_app(Config.load('production.cfg'))

virtenv = os.environ['OPENSHIFT_PYTHON_DIR'] + '/virtenv/'
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:
    execfile(virtualenv, dict(__file__=virtualenv))
except IOError:
    pass

ip = os.environ['OPENSHIFT_PYTHON_IP']
port = int(os.environ['OPENSHIFT_PYTHON_PORT'])


def number_of_workers():
    return (multiprocessing.cpu_count() * 2) + 1
Esempio n. 14
0
                        metavar="/etc/isso.conf",
                        help="set configuration file")

    imprt = subparser.add_parser('import', help="import Disqus XML export")
    imprt.add_argument("dump", metavar="FILE")

    serve = subparser.add_parser("run", help="run server")

    args = parser.parse_args()
    conf = Config.load(args.conf)

    if args.command == "import":
        conf.set("guard", "enabled", "off")
        migrate.disqus(db.SQLite3(conf.get('general', 'dbpath'), conf),
                       args.dump)
        sys.exit(0)

    run_simple(conf.get('server', 'host'),
               conf.getint('server', 'port'),
               make_app(conf),
               threaded=True,
               use_reloader=conf.getboolean('server', 'reload'))


try:
    import uwsgi
except ImportError:
    pass
else:
    application = make_app(Config.load(os.environ.get('ISSO_SETTINGS')))
Esempio n. 15
0
File: run.py Progetto: alemic/isso
# -*- encoding: utf-8 -*-

import os

from isso import make_app
from isso.core import Config

application = make_app(Config.load(os.environ.get('ISSO_SETTINGS')))
Esempio n. 16
0
    def test_defaults(self):

        db = SQLite3(self.path, Config.load(None))

        self.assertEqual(db.version, SQLite3.MAX_VERSION)
        self.assertTrue(db.preferences.get("session-key", "").isalnum())
Esempio n. 17
0
def main():

    parser = ArgumentParser(description="a blog comment hosting service")
    subparser = parser.add_subparsers(help="commands", dest="command")

    parser.add_argument('--version',
                        action='version',
                        version='%(prog)s ' + dist.version)
    parser.add_argument("-c",
                        dest="conf",
                        default="/etc/isso.conf",
                        metavar="/etc/isso.conf",
                        help="set configuration file")

    imprt = subparser.add_parser('import', help="import Disqus XML export")
    imprt.add_argument("dump", metavar="FILE")
    imprt.add_argument("-n",
                       "--dry-run",
                       dest="dryrun",
                       action="store_true",
                       help="perform a trial run with no changes made")
    imprt.add_argument("-t",
                       "--type",
                       dest="type",
                       default=None,
                       choices=["disqus", "wordpress"],
                       help="export type")

    serve = subparser.add_parser("run", help="run server")

    args = parser.parse_args()
    conf = Config.load(args.conf)

    if args.command == "import":
        conf.set("guard", "enabled", "off")

        if args.dryrun:
            xxx = tempfile.NamedTemporaryFile()
            dbpath = xxx.name
        else:
            dbpath = conf.get("general", "dbpath")

        mydb = db.SQLite3(dbpath, conf)
        migrate.dispatch(args.type, mydb, args.dump)

        sys.exit(0)

    if conf.get("general", "log-file"):
        handler = logging.FileHandler(conf.get("general", "log-file"))

        logger.addHandler(handler)
        logging.getLogger("werkzeug").addHandler(handler)

        logger.propagate = False
        logging.getLogger("werkzeug").propagate = False

    if not any(conf.getiter("general", "host")):
        logger.error("No website(s) configured, Isso won't work.")
        sys.exit(1)

    if conf.get("server", "listen").startswith("http://"):
        host, port, _ = urlsplit(conf.get("server", "listen"))
        try:
            from gevent.pywsgi import WSGIServer
            WSGIServer((host, port), make_app(conf)).serve_forever()
        except ImportError:
            run_simple(host,
                       port,
                       make_app(conf),
                       threaded=True,
                       use_reloader=conf.getboolean('server', 'reload'))
    else:
        sock = conf.get("server", "listen").partition("unix://")[2]
        try:
            os.unlink(sock)
        except OSError as ex:
            if ex.errno != errno.ENOENT:
                raise
        wsgi.SocketHTTPServer(sock, make_app(conf)).serve_forever()
Esempio n. 18
0
 def test_render(self):
     conf = Config.load(None).section("markup")
     renderer = html.Markup(conf).render
     self.assertEqual(renderer("http://example.org/ and sms:+1234567890"),
                      '<p><a href="http://example.org/">http://example.org/</a> and sms:+1234567890</p>')
Esempio n. 19
0
    def test_defaults(self):

        db = SQLite3(self.path, Config.load(None))

        self.assertEqual(db.version, SQLite3.MAX_VERSION)
        self.assertTrue(db.preferences.get("session-key", "").isalnum())