예제 #1
0
    def setup_class(cls):
        cls._database_directory = tempfile.TemporaryDirectory(suffix="votes")
        cls._database_location = os.path.join(cls._database_directory.name, "test.db")

        config = copy.deepcopy(cls.default_config)
        config["database"] = {"file": '"' + cls._database_location + '"'}
        if hasattr(cls, "config"):
            config.update(cls.config)

        cls._setup_database()

        app = create_app(config)
        app.create_tables()
        app.load_models(cls.database_input)
        cherrypy.tree.mount(app, "/", config)

        cls._revertable_settings["log.screen"] = cherrypy.log.screen
        cherrypy.log.screen = False

        cherrypy.engine.start()
        cls.app = app
예제 #2
0
파일: app.py 프로젝트: MrJohz/votes
from configparser import ConfigParser
import json
import cherrypy
from votes import create_app

config = ConfigParser()
config.read('votes.conf')

if __name__ == "__main__":
    import sys
    app = create_app(config)

    if len(sys.argv) == 1:
        cherrypy.quickstart(app, '/', 'votes.conf')
    elif sys.argv[1] == 'initialise-database':
        app.drop_tables()
        app.create_tables()
    elif sys.argv[1] == 'dump-db':
        with open(sys.argv[2], mode='w') as file:
            json.dump(app.dump_models(), file, sort_keys=True, indent=2)
    elif sys.argv[1] == 'load-db':
        with open(sys.argv[2], mode='r') as file:
            app.load_models(json.load(file))
    else:
        print("Unknown argument", sys.argv[1])