Пример #1
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]()
Пример #2
0
 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)
Пример #3
0
 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
Пример #4
0
 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)
Пример #5
0
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
Пример #6
0
 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
Пример #7
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()
Пример #8
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()
Пример #9
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()
Пример #10
0
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
Пример #11
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()
Пример #12
0
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)
Пример #13
0
    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)
Пример #14
0
    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:
            rebuild_index(active_app)
Пример #15
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]()
Пример #16
0
    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)
Пример #17
0
# 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"""
Пример #18
0
 def start(self):
     """Call after each process start
     """
     for database_settings in self.databases:
         database.set_metadata(*database_settings)
Пример #19
0
def dbcontext():
    for (database_settings, _) in read_options(
            True, [_get_config_filepath()], ValueError):
        database.set_metadata(*database_settings)
        with database.session.begin():
            yield
Пример #20
0
 def start(self):
     """Call after each process start
     """
     for database_settings in self.databases:
         database.set_metadata(*database_settings)
Пример #21
0
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)
Пример #22
0
# This software is licensed under the BSD License, as described in
# the file LICENSE.txt, which you should have received as part of
# this distribution.
#--

import unittest
from nagare import database, i18n, security, component
from nagare.namespaces import xhtml5
from sqlalchemy import MetaData
from kansha.board import comp as board_module
from kansha.board import boardsmanager
from . import helpers
from kansha.security import Unauthorized
from elixir import metadata as __metadata__

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


class BoardTest(unittest.TestCase):
    def setUp(self):
        helpers.setup_db(__metadata__)
        self.boards_manager = boardsmanager.BoardsManager()

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

    def test_view_board_1(self):
        """Test security view board 1

        Board Private
        User not logged
Пример #23
0
def dbcontext():
    for (database_settings, _) in read_options(True, [_get_config_filepath()],
                                               ValueError):
        database.set_metadata(*database_settings)
        with database.session.begin():
            yield