コード例 #1
0
ファイル: tests.py プロジェクト: daamien/kansha
 def setUp(self):
     database.set_metadata(__metadata__, 'sqlite:///:memory:', False, {})
     helpers.setup_db(__metadata__)
     helpers.set_context(helpers.create_user())
     self.board = board = helpers.create_board()
     self.column = column = board.create_column(1, u'test')
     self.card = column.create_card(u'test')
     self.extension = self.create_instance(self.card, DummyActionLog(), board)
コード例 #2
0
ファイル: tests.py プロジェクト: Net-ng/kansha
 def setUp(self):
     database.set_metadata(__metadata__, 'sqlite:///:memory:', False, {})
     helpers.setup_db(__metadata__)
     helpers.set_context(helpers.create_user())
     extensions = [(self.extension_name, self.extension_class)] if self.extension_name else []
     self.board = board = helpers.create_board(extensions)
     self.column = column = board.create_column(1, u'test')
     self.card = column.create_card(u'test')
     self.extension = dict(self.card.extensions)[self.extension_name]() if self.extension_name else None
コード例 #3
0
def drop(parser, options, args):
    """Delete the database tables of the application

    In:
      - ``parser`` -- the optparse.OptParser object used to parse the configuration file
      - ``options`` -- options in the command lines
      - ``args`` -- arguments in the command lines : application name
    """
    for (database_settings, populate) in read_options(options.debug, args, parser.error):
        database.set_metadata(*database_settings)

        with database.session.begin():
            database_settings[0].drop_all()
コード例 #4
0
ファイル: shell.py プロジェクト: nagareproject/core
def activate_applications(cfgfiles, debug, error):
    """Initialize applications

    In:
      - ``cfgfile`` -- paths to application configuration files or names of
        registered applications
      - ``debug`` -- enable the display of the generated SQL statements
      - ``error`` -- the function to call in case of configuration errors

    Return:
      - database session
      - {application name -> application object}
    """
    # Configure the local service
    local.worker = local.Process()
    local.request = local.Process()

    configs = []

    # Merge all the ``[logging]]`` section of all the applications
    for cfgfile in cfgfiles:
        # Read the configuration file of the application
        conffile, app, project_name, aconf = util.read_application(cfgfile, error)
        if conffile is None:
            error('Configuration file "%s" not found' % cfgfile)
        configs.append((conffile, app, project_name, aconf))

        log.configure(aconf['logging'].dict(), aconf['application']['app'])

    # Configure the logging service
    log.activate()

    apps = {}

    # For each application given, activate its metadata and its logger
    for cfgfile, app, project_name, aconf in configs:
        name = aconf['application']['app']

        log.set_logger('nagare.application.' + name)

        data_path = aconf['application']['data']

        apps[name], databases = util.activate_WSGIApp(app, cfgfile, aconf, error, data_path=data_path, debug=debug)

        for database_settings, populate in databases:
            database.set_metadata(*database_settings)

    session = database.session
    session.begin()
    return session, apps
コード例 #5
0
    def setUp(self):
        # call the base implementation
        super(DatabaseEnabledTestCase, self).setUp()

        # setup the database
        database.set_metadata(
            self.metadata,
            self.database_uri,
            self.debug,
            self.engine_settings
        )

        self.metadata.create_all()
        sys.argv = [test_resource_path('conf', 'eureka.cfg.template')]
        populate()
        database.session.flush()
コード例 #6
0
ファイル: shell.py プロジェクト: apoirier/test
def create_globals(cfgfiles, debug, error):
    """
    In:
      - ``cfgfile`` -- paths to application configuration files or names of
        registered applications
      - ``debug`` -- enable the display of the generated SQL statements
      - ``error`` -- the function to call in case of configuration errors

    Return:
      - the namespace with the ``apps`` and ``session`` variables defined
    """
    # Configure the local service
    local.worker = local.Process()
    local.request = local.Process()

    configs = []

    # Merge all the ``[logging]]`` section of all the applications
    for cfgfile in cfgfiles:
        # Read the configuration file of the application
        (cfgfile, app, dist, aconf) = util.read_application(cfgfile, error)
        configs.append((cfgfile, app, dist, aconf))

        log.configure(aconf['logging'].dict(), aconf['application']['name'])

    # Configure the logging service
    log.activate()

    apps = {}

    # For each application given, activate its metadata and its logger
    for (cfgfile, app, dist, aconf) in configs:
        name = aconf['application']['name']

        log.set_logger('nagare.application.'+name)

        requirement = None if not dist else pkg_resources.Requirement.parse(dist.project_name)
        data_path = None if not requirement else pkg_resources.resource_filename(requirement, '/data')

        (apps[name], databases) = util.activate_WSGIApp(app, cfgfile, aconf, error, data_path=data_path, debug=debug)

        for (database_settings, populate) in databases:
            database.set_metadata(*database_settings)

    session = database.session
    session.begin()
    return dict(session=session, apps=apps)
コード例 #7
0
ファイル: create_index.py プロジェクト: ephilippot/kansha
    def run(parser, options, args):

        for cfg in args:
            (cfgfile, app, dist, conf) = util.read_application(cfg,
                                                               parser.error)
            requirement = (
                None if not dist
                else pkg_resources.Requirement.parse(dist.project_name)
            )
            data_path = (
                None if not requirement
                else pkg_resources.resource_filename(requirement, '/data')
            )

            (active_app, databases) = util.activate_WSGIApp(
                app, cfgfile, conf, parser.error, data_path=data_path)
            for (database_settings, populate) in databases:
                database.set_metadata(*database_settings)
            if active_app:
                rebuild_index(active_app)
コード例 #8
0
def create(parser, options, args):
    """Create the database tables of the application

    If the ``--drop`` option is on, delete the existing tables before to re-create them

    If the ``--no-populate`` option is off, call the populate function (if it exists)
    after the creation of the tables

    In:
      - ``parser`` -- the optparse.OptParser object used to parse the configuration file
      - ``options`` -- options in the command lines
      - ``args`` -- arguments in the command lines : application name
    """
    for (database_settings, populate) in read_options(options.debug, args, parser.error):
        database.set_metadata(*database_settings)

        with database.session.begin():
            if options.drop:
                database_settings[0].drop_all()

            database_settings[0].create_all()

            if options.populate and populate:
                reference.load_object(populate)[0]()
コード例 #9
0
ファイル: create_demo.py プロジェクト: Net-ng/kansha
    def run(parser, options, args):

        try:
            application = args[0]
        except IndexError:
            application = 'kansha'

        (cfgfile, app, dist, conf) = util.read_application(application,
                                                           parser.error)
        requirement = (
            None if not dist
            else pkg_resources.Requirement.parse(dist.project_name)
        )
        data_path = (
            None if not requirement
            else pkg_resources.resource_filename(requirement, '/data')
        )

        (active_app, databases) = util.activate_WSGIApp(
            app, cfgfile, conf, parser.error, data_path=data_path)
        for (database_settings, populate) in databases:
            database.set_metadata(*database_settings)
        if active_app:
            create_demo(active_app)
コード例 #10
0
ファイル: test_boards.py プロジェクト: Net-ng/kansha
# the file LICENSE.txt, which you should have received as part of
# this distribution.
#--

import unittest

from nagare import database
from elixir import metadata as __metadata__

from kansha import helpers
from kansha.board import boardsmanager
from kansha.board.models import DataBoard
from kansha.board import comp as board_module


database.set_metadata(__metadata__, 'sqlite:///:memory:', False, {})


# FIXME: dirty tests; rewrite them all on component API.

class BoardTest(unittest.TestCase):

    def setUp(self):
        helpers.setup_db(__metadata__)
        self.boards_manager = helpers.get_boards_manager()

    def tearDown(self):
        helpers.teardown_db(__metadata__)

    def test_add_board(self):
        """Create a new board"""
コード例 #11
0
ファイル: wsgi.py プロジェクト: apoirier/test
 def start(self):
     """Call after each process start
     """
     for database_settings in self.databases:
         database.set_metadata(*database_settings)
コード例 #12
0
ファイル: fixtures.py プロジェクト: lojban/lojbanquest
from hashlib import sha256

__all__ = ["RoomData", "DoorData", "PlayerData", "dbfix", "meta"]

class RoomData(DataSet):
    class start_room:
        name = u"pensi"
        realm = "CVCCV"
    class other_room(start_room):
        name = u"penmi"

class DoorData(DataSet):
    class door_one:
        room_a_id = u"pensi"
        room_b_id = u"penmi"

class PlayerData(DataSet):
    class hero:
        username = u"hero"
        password = sha256(u"hero").hexdigest()
        status = 0
        login = datetime(2010, 1, 2)
        position = RoomData.start_room

meta = __metadata__
set_metadata(meta, "sqlite:///:memory:", True, {})
dbfix = SQLAlchemyFixture(
        env=globals(),
        style=TrimmedNameStyle(suffix="Data"),
        engine = meta.bind)
コード例 #13
0
ファイル: fabfile.py プロジェクト: droodle/eureka-opensource
def dbcontext():
    for (database_settings, _) in read_options(
            True, [_get_config_filepath()], ValueError):
        database.set_metadata(*database_settings)
        with database.session.begin():
            yield