Esempio n. 1
0
 def __create(cls, ini):
     reg = Registry('testing')
     conf = Configurator(registry=reg, package=ini.package_name)
     conf.setup_registry(settings=ini.settings)
     if not ini.config_file_name is None and not ini.package_name is None:
         conf.begin()
         try:
             conf.load_zcml(ini.config_file_name)
         finally:
             conf.end()
     return conf
Esempio n. 2
0
 def __create(cls, ini):
     reg = Registry('testing')
     conf = Configurator(registry=reg, package=ini.package_name)
     conf.setup_registry(settings=ini.settings)
     if not ini.config_file_name is None and not ini.package_name is None:
         conf.begin()
         try:
             conf.load_zcml(ini.config_file_name)
         finally:
             conf.end()
     return conf
Esempio n. 3
0
class BaseTestCaseWithConfiguration(TestCaseWithIni):
    """
    Base class for test cases that access an initialized (but not configured)
    registry.

    :ivar config: The registry configurator. This is set in the set_up method.
    """
    #: The name of a package containing a configuration file to load.
    #: Defaults to `None` indicating that no configuration applies.
    package_name = None
    # : The name of a ZCML configuration file to use.
    config_file_name = 'configure.zcml'
    # : The section name in the ini file to look for settings. Override as
    # : needed in derived classes.
    ini_section_name = None

    def set_up(self):
        super(BaseTestCaseWithConfiguration, self).set_up()
        # Create and configure a new testing registry.
        reg = Registry('testing')
        self.config = Configurator(registry=reg,
                                   package=self.package_name)
        if not self.ini_section_name is None:
            settings = self.ini.get_settings(self.ini_section_name)
        else:
            try:
                settings = self.ini.get_settings('DEFAULT')
            except configparser.NoSectionError:
                settings = None
        self.config.setup_registry(settings=settings)
        if not self.package_name is None:
            if not settings is None:
                cfg_zcml = settings.get('configure_zcml',
                                        self.config_file_name)
            else:
                cfg_zcml = self.config_file_name
            self.config.begin()
            try:
                self.config.load_zcml(cfg_zcml)
            finally:
                self.config.end()

    def tear_down(self):
        super(BaseTestCaseWithConfiguration, self).tear_down()
        tear_down_registry(self.config.registry)
        try:
            del self.config
        except AttributeError:
            pass
Esempio n. 4
0
class FunctionalTestCase(TestCaseWithIni, ResourceCreatorMixin):
    """
    Use this for test cases that need access to a WSGI application.

    :ivar app: :class:`webtest.TestApp` instance wrapping our WSGI app to test.
    """
    #: The name of the application to test. Must be set in derived classes.
    app_name = None
    #: The name of the package where the tests reside. Override as needed.
    package_name = 'everest'

    def set_up(self):
        super(FunctionalTestCase, self).set_up()
        # Create the WSGI application and set up a configurator.
        wsgiapp = self.__load_wsgiapp()
        self.config = Configurator(registry=wsgiapp.registry,
                                   package=self.package_name)
        self.config.begin()
        self.app = \
            EverestTestApp(wsgiapp,
                           self.package_name,
                           extra_environ=self._create_extra_environment())

    def tear_down(self):
        super(FunctionalTestCase, self).tear_down()
        transaction.abort()
        self.config.end()
        tear_down_registry(self.config.registry)
        try:
            del self.app
        except AttributeError:
            pass

    def _create_extra_environment(self):
        """
        Returns the value for the `extra_environ` argument for the test
        app. Override as needed.
        """
        return {}

    def __load_wsgiapp(self):
        wsgiapp = loadapp('config:' + self.ini.ini_file_path,
                          name=self.app_name)
        return wsgiapp
Esempio n. 5
0
class FunctionalTestCase(TestCaseWithIni):
    """
    Use this for test cases that need access to a WSGI application.
    
    :ivar app: :class:`webtest.TestApp` instance wrapping our WSGI app to test. 
    """
    # : The name of the application to test.
    app_name = None

    def set_up(self):
        super(FunctionalTestCase, self).set_up()
        # Create the WSGI application and set up a configurator.
        wsgiapp = self._load_wsgiapp()
        self.config = Configurator(registry=wsgiapp.registry,
                                   package=self.package_name)
        self.config.begin()
        self.app = TestApp(wsgiapp,
                           extra_environ=self._create_extra_environment())

    def tear_down(self):
        super(FunctionalTestCase, self).tear_down()
        transaction.abort()
        self.config.end()
        tear_down_registry(self.config.registry)
        try:
            del self.app
        except AttributeError:
            pass

    def _load_wsgiapp(self):
        wsgiapp = loadapp('config:' + self.ini.ini_file_path,
                          name=self.app_name)
        return wsgiapp

    def _create_extra_environment(self):
        return {}
Esempio n. 6
0
class FunctionalTestCase(TestCaseWithIni):
    """
    Use this for test cases that need access to a WSGI application.
    
    :ivar app: :class:`webtest.TestApp` instance wrapping our WSGI app to test. 
    """
    # : The name of the application to test.
    app_name = None

    def set_up(self):
        super(FunctionalTestCase, self).set_up()
        # Create the WSGI application and set up a configurator.
        wsgiapp = self._load_wsgiapp()
        self.config = Configurator(registry=wsgiapp.registry,
                                   package=self.package_name)
        self.config.begin()
        self.app = TestApp(wsgiapp,
                           extra_environ=self._create_extra_environment())

    def tear_down(self):
        super(FunctionalTestCase, self).tear_down()
        transaction.abort()
        self.config.end()
        tear_down_registry(self.config.registry)
        try:
            del self.app
        except AttributeError:
            pass

    def _load_wsgiapp(self):
        wsgiapp = loadapp('config:' + self.ini.ini_file_path,
                          name=self.app_name)
        return wsgiapp

    def _create_extra_environment(self):
        return {}