Beispiel #1
0
    def setup_test(self):
        """setup database for testing"""
        # setup config
        path = os.path.join(os.path.dirname(__file__), '../config')
        self.config = cfg.Config(path, 'localhost')

        # connect to the database
        self.database = old_database(
            'mysql',
            'database',
            'test',
            'testuser',
            'password'
        )
        self.db = new_db(
            'mysql',
            'database',
            'test',
            'testuser',
            passwd='password'
        )

        # create session
        self.session = zoom.session.Session(self)
Beispiel #2
0
    def setup(self,
              instance_path=None,
              server=request.server,
              timer=SystemTimer(timeit.default_timer())):
        """set up the system"""

        if instance_path is None:
            instance_path = Instance('system').path

        self.debugging = True
        self.timer = timer
        self.start_time = timer.start_time
        self.lib_path = os.path.split(os.path.abspath(__file__))[0]

        if not os.path.exists(os.path.join(instance_path, 'dz.conf')):
            msg = 'instance missing %s' % os.path.abspath(instance_path)
            raise Exception(msg)
        self.instance_path = os.path.abspath(instance_path)

        if '.' not in sys.path:
            sys.path.insert(0, '.')

        # system config file
        self.config = config = cfg.Config(instance_path, server)

        # connect to the database and stores
        db_engine = config.get('database', 'engine', 'mysql')
        db_host = config.get('database', 'dbhost', 'database')
        db_name = config.get('database', 'dbname', 'zoomdev')
        db_user = config.get('database', 'dbuser', 'testuser')
        db_pass = config.get('database', 'dbpass', 'password')

        # legacy database module
        self.database = old_database(
            db_engine,
            db_host,
            db_name,
            db_user,
            db_pass,
            )

        # database module
        db_params = dict(
            engine=db_engine,
            host=db_host,
            db=db_name,
            user=db_user,
            )
        if db_pass:
            db_params['passwd'] = db_pass
        # pylint: disable=invalid-name, star-args
        self.db = new_db(**db_params)

        self.db_debug = config.get('database', 'debug', '0') not in NEGATIVE
        self.db.debug = self.db_debug
        self.database.debug = self.db_debug

        # message queues
        from zoom.queues import Queues
        self.queues = Queues(self.db)

        from zoom.store import EntityStore
        settings_store = EntityStore(self.database, settings.SystemSettings)
        self.settings = settings.Settings(settings_store, config, 'system')

        if not os.path.exists(config.sites_path):
            raise Exception('sites missing %s' % config.sites_path)

        self.debugging = config.get('errors', 'debugging', '0') == '1'

        self.request = request
        self.server = server
        self.server_name = server  # deprecated

        # get current site directory
        self.root = request.instance
        self.uri = config.get('site', 'uri', '/')
        if self.uri[-1] == '/':
            self.uri = self.uri[:-1]

        # get site info
        self.site = Site(
            name='',
            theme='',
            home=os.path.join(config.sites_path, server),
            data_path=os.path.join(config.sites_path, server,
                                   config.get('data', 'path', 'data')),
            url=self.uri,
            tracking_id=config.get('site', 'tracking_id', ''),
            )

        # csrf validation
        self.csrf_validation = (
            config.get('site', 'csrf_validation', True) not in
            ['0', 'False', 'off', 'no', True]
            )

        # secure cookies
        self.secure_cookies = (
            config.get('sessions', 'secure_cookies', False) not in
            ['0', 'False', 'off', 'no', False]
        )

        # users and groups
        self.guest = config.get('users', 'default', 'guest')
        self.administrator_group = \
            system.config.get('users', 'administrator_group', 'administrators')
        self.manager_group = config.get('users', 'manager_group', 'managers')
        self.managers = config.get('users', 'managers', 'managers')
        self.developers = config.get('users', 'developers', 'developers')
        self.administrators = \
            config.get('users', 'administrators', 'administrators')

        # apps
        self.index = config.get('apps', 'index', 'index')
        self.home = config.get('apps', 'home', 'home')

        # background processing
        self.background = config.get('background', 'run', True) not in NEGATIVE

        # users (experimental)
        self.users = UserStore(self.db)

        # email settings
        self.from_addr = system.config.get('mail', 'from_addr')
        self.mail_delivery = system.config.get('mail', 'delivery', 'immediate')

        # load theme
        self.themes_path = existing(config.get(
            'theme',
            'path',
            os.path.join(self.root, 'themes'))
        )
        self.theme = (
            self.themes_path and
            self.settings.get('theme_name') or
            config.get('theme', 'name', 'default')
        )
        self.set_theme(self.theme)

        self.app = NoApp()
        self.site_name = ''
        self.warnings = []
        self.errors = []
        self.messages = []

        self.styles = OrderedSet()
        self.css = OrderedSet()
        self.libs = OrderedSet()
        self.js = OrderedSet()
        self.head = OrderedSet()
        self.tail = OrderedSet()

        self.helpers = {}

        self.show_errors = config.get('error', 'users', '0') == '1'

        self.profile = config.get('system', 'profile', '0') == '1'

        self.track_visits = config.get(
            'system',
            'track_visits',
            '0').lower() in POSITIVE

        self.logging = config.get(
            'log',
            'logging',
            True) not in ['0', 'False', 'off', 'no', False]

        self.session = zoom.session.Session(self)
        self.session.load_session()

        self.is_setup = True