예제 #1
0
    def test_settings_initialize_only_once(self):
        self.init_ptah()
        ptah.init_settings(self.config, {})

        self.assertRaises(
            RuntimeError,
            ptah.init_settings, self.config, {})
예제 #2
0
    def init_ptah(self, initsettings=False, *args, **kw):
        self.config.include('ptah')
        self.config.scan(self.__class__.__module__)
        self.config.commit()
        self.config.autocommit = True

        if initsettings:
            ptah.init_settings(self.config, self.registry.settings)
예제 #3
0
    def test_settings_initialize_load_preparer(self):
        node1 = ptah.form.TextField(
            'node',
            default = 'default1',
            preparer = lambda s: s.lower())

        ptah.register_settings('group', node1)
        self.init_ptah()

        ptah.init_settings(self.config, {'group.node': 'Test'})

        group = ptah.get_settings('group', self.request.registry)
        self.assertEqual(group['node'], 'test')
예제 #4
0
파일: testing.py 프로젝트: runyaga/ptah
    def init_ptah(self, *args, **kw):
        self.registry.settings.update(self._settings)

        self.config.scan('ptah')
        self.config.commit()
        self.config.autocommit = True

        ptah.init_settings(self.config, self.registry.settings)

        if self._init_sqla:
            # create sql tables
            Base = sqlahelper.get_base()
            Base.metadata.drop_all()
            Base.metadata.create_all()
            transaction.commit()
예제 #5
0
    def init_ptah(self, *args, **kw):
        self.registry.settings.update(self._settings)

        self.config.scan('ptah')
        self.config.commit()
        self.config.autocommit = True

        ptah.init_settings(self.config, self.registry.settings)

        if self._init_sqla:
            # create sql tables
            Base = sqlahelper.get_base()
            Base.metadata.drop_all()
            Base.metadata.create_all()
            transaction.commit()
예제 #6
0
    def test_settings_initialize_load_partly_defaults(self):
        node1 = ptah.form.TextField(
            'node1',
            default = 'default1')

        node2 = ptah.form.TextField(
            'node2',
            default = 10)

        ptah.register_settings('group', node1, node2)
        self.init_ptah()

        ptah.init_settings(self.config, {'group.node1': 'setting from ini'})

        group = ptah.get_settings('group', self.request.registry)
        self.assertEqual(group['node1'], 'setting from ini')
        self.assertEqual(group['node2'], 10)
예제 #7
0
    def test_settings_initialize_events_exceptions(self):
        self.init_ptah()

        sm = self.config.registry

        events = []
        err_tp = TypeError()

        def h1(ev):
            raise err_tp

        sm.registerHandler(h1, (ptah.events.SettingsInitializing,))

        err = None
        try:
            ptah.init_settings(self.config, {})
        except Exception as exc:
            err = exc

        self.assertIsInstance(err, ptah.config.StopException)
        self.assertIs(err.exc, err_tp)
예제 #8
0
    def test_settings_initialize_load_settings_include(self):
        path = os.path.join(self.dir, 'settings.cfg')
        f = open(path, 'wb')
        f.write(bytes_('[DEFAULT]\ngroup.node1 = value\n\n','ascii'))
        f.close()

        node1 = ptah.form.TextField(
            'node1',
            default = 'default1')

        node2 = ptah.form.IntegerField(
            'node2',
            default = 10)

        ptah.register_settings('group', node1, node2)
        self.init_ptah()

        ptah.init_settings(self.config, {'include': path})

        group = ptah.get_settings('group', self.request.registry)

        self.assertEqual(group['node1'], 'value')
        self.assertEqual(group['node2'], 10)
예제 #9
0
    def test_settings_initialize_events(self):
        self.init_ptah()

        sm = self.config.registry

        events = []

        def h1(ev):
            events.append(ev)

        def h2(ev):
            events.append(ev)

        sm.registerHandler(h1, (ptah.events.SettingsInitializing,))
        sm.registerHandler(h2, (ptah.events.SettingsInitialized,))

        ptah.init_settings(self.config, {})

        self.assertTrue(isinstance(events[0], ptah.events.SettingsInitializing))
        self.assertTrue(isinstance(events[1], ptah.events.SettingsInitialized))

        self.assertTrue(events[0].config is self.config)
        self.assertTrue(events[1].config is self.config)