Ejemplo n.º 1
0
    def init_component_settings(self):
        # now we need to assign component's settings to the main setting object
        for cname in listcomponents():
            try:
                Settings = findobj('%s:config.settings.Settings' % cname)
                ps = Settings(self.settings)

                # update component-level settings
                try:
                    self.settings.components[cname].setdefaults(ps.for_me)
                except KeyError as e:
                    if cname not in str(e):
                        raise
                    # the application's settings did not override any of this
                    # component's settings and therefore doesn't have a settings
                    # object for this component.  Therefore, we just add it.
                    self.settings.components[cname] = ps.for_me

                # update application-level settings
                self.settings.setdefaults(ps.for_app)
            except HierarchyImportError as e:
                # this happens if the component did not have a settings module or
                # did not have a Settings class in the module
                if '%s.config.settings' % cname not in str(e) and 'Settings' not in str(e):
                    raise  # pragma: no cover

        # lock the settings, this ensures that an attribute error is thrown if an
        # attribute is accessed that doesn't exist.  Without the lock, a new attr
        # would be created, which is undesirable since any "new" attribute at this
        # point would probably be an accident
        self.settings.lock()
Ejemplo n.º 2
0
    def begin(self):
        # Add test apps to import path
        sys.path.append(
            os.path.join(os.path.dirname(os.path.dirname(__file__)), 'tests',
                         'apps'))

        if self.val_disable:
            return
        # import here so we can avoid test coverage issues
        from blazeweb.events import signal
        from blazeweb.globals import ag, settings
        from blazeweb.hierarchy import findobj
        from blazeweb.scripting import load_current_app, UsageError

        try:
            _, _, _, wsgiapp = load_current_app(self.val_app_name,
                                                self.val_app_profile)

            # make the app available to the tests
            ag.wsgi_test_app = wsgiapp

            # an application can define functions to be called after the app
            # is initialized but before any test inspection is done or tests
            # are ran.  We call those functions here:
            for callstring in tolist(settings.testing.init_callables):
                tocall = findobj(callstring)
                tocall()

            # we also support events for pre-test setup
            signal('blazeweb.pre_test_init').send()
        except UsageError:
            if self.val_debug:
                raise
            self.val_disable = True
Ejemplo n.º 3
0
    def begin(self):
        # Add test apps to import path
        sys.path.append(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'tests', 'apps'))

        if self.val_disable:
            return
        # import here so we can avoid test coverage issues
        from blazeweb.events import signal
        from blazeweb.globals import ag, settings
        from blazeweb.hierarchy import findobj
        from blazeweb.scripting import load_current_app, UsageError

        try:
            _, _, _, wsgiapp = load_current_app(self.val_app_name, self.val_app_profile)

            # make the app available to the tests
            ag.wsgi_test_app = wsgiapp

            # an application can define functions to be called after the app
            # is initialized but before any test inspection is done or tests
            # are ran.  We call those functions here:
            for callstring in tolist(settings.testing.init_callables):
                tocall = findobj(callstring)
                tocall()

            # we also support events for pre-test setup
            signal('blazeweb.pre_test_init').send()
        except UsageError:
            if self.val_debug:
                raise
            self.val_disable = True
Ejemplo n.º 4
0
    def init_component_settings(self):
        # now we need to assign component's settings to the main setting object
        for cname in listcomponents():
            try:
                Settings = findobj('%s:config.settings.Settings' % cname)
                ps = Settings(self.settings)

                # update component-level settings
                try:
                    self.settings.components[cname].setdefaults(ps.for_me)
                except KeyError as e:
                    if cname not in str(e):
                        raise
                    # the application's settings did not override any of this
                    # component's settings and therefore doesn't have a settings
                    # object for this component.  Therefore, we just add it.
                    self.settings.components[cname] = ps.for_me

                # update application-level settings
                self.settings.setdefaults(ps.for_app)
            except HierarchyImportError as e:
                # this happens if the component did not have a settings module or
                # did not have a Settings class in the module
                if '%s.config.settings' % cname not in str(
                        e) and 'Settings' not in str(e):
                    raise  # pragma: no cover

        # lock the settings, this ensures that an attribute error is thrown if an
        # attribute is accessed that doesn't exist.  Without the lock, a new attr
        # would be created, which is undesirable since any "new" attribute at this
        # point would probably be an accident
        self.settings.lock()
Ejemplo n.º 5
0
def pytest_configure(config):
    from blazeutils import tolist
    from blazeweb.events import signal
    from blazeweb.globals import ag, settings
    from blazeweb.hierarchy import findobj
    from blazeweb.scripting import load_current_app
    _, _, _, wsgiapp = load_current_app(config.getoption('blazeweb_package'),
                                        config.getoption('blazeweb_profile'))

    # make the app available to the tests
    ag.wsgi_test_app = wsgiapp

    # an application can define functions to be called after the app
    # is initialized but before any test inspection is done or tests
    # are ran.  We call those functions here:
    for callstring in tolist(settings.testing.init_callables):
        tocall = findobj(callstring)
        tocall()

    # we also support events for pre-test setup
    signal('blazeweb.pre_test_init').send()
Ejemplo n.º 6
0
        def setup_class(cls):
            # these lines necessary because we are sharing test space with a Flask
            #   app built with FlaskSQLAlchemy. That lib places listeners on the
            #   session class but expects its own code will run to set up a session
            SASession._model_changes = mock.Mock()
            SASession.app = mock.Mock()

            _, _, _, wsgiapp = load_current_app('webgrid_blazeweb_ta', 'Test')

            # make the app available to the tests
            ag.wsgi_test_app = wsgiapp

            # an application can define functions to be called after the app
            # is initialized but before any test inspection is done or tests
            # are ran.  We call those functions here:
            for callstring in tolist(settings.testing.init_callables):
                tocall = findobj(callstring)
                tocall()

            # we also support events for pre-test setup
            signal('blazeweb.pre_test_init').send()

            cls.ta = TestApp(ag.wsgi_test_app)
Ejemplo n.º 7
0
        def setup_class(cls):
            # these lines necessary because we are sharing test space with a Flask
            #   app built with FlaskSQLAlchemy. That lib places listeners on the
            #   session class but expects its own code will run to set up a session
            SASession._model_changes = mock.Mock()
            SASession.app = mock.Mock()

            _, _, _, wsgiapp = load_current_app('webgrid_blazeweb_ta', 'Test')

            # make the app available to the tests
            ag.wsgi_test_app = wsgiapp

            # an application can define functions to be called after the app
            # is initialized but before any test inspection is done or tests
            # are ran.  We call those functions here:
            for callstring in tolist(settings.testing.init_callables):
                tocall = findobj(callstring)
                tocall()

            # we also support events for pre-test setup
            signal('blazeweb.pre_test_init').send()

            cls.ta = TestApp(ag.wsgi_test_app)
Ejemplo n.º 8
0
    def test_findobj(self):
        view = findobj('news:views.FakeView')
        assert 'newlayout.components.news.views.FakeView' in str(view), view

        view = findobj('views.AppLevelView')
        assert 'newlayout.views.AppLevelView' in str(view), view
Ejemplo n.º 9
0
    def test_findobj(self):
        view = findobj('news:views.FakeView')
        assert 'newlayout.components.news.views.FakeView' in str(view), view

        view = findobj('views.AppLevelView')
        assert 'newlayout.views.AppLevelView' in str(view), view