Beispiel #1
0
def setUp(test):
    FunctionalTestSetup().setUp()
Beispiel #2
0
def tearDown(test):
    FunctionalTestSetup().tearDown()
Beispiel #3
0
def load_ftesting_zcml():
    """Load ZCML.

    First call is expensive, subsequent calls are virtually free.
    """
    return FunctionalTestSetup(find_ftesting_zcml())
Beispiel #4
0
 def setUp(self):
     FunctionalTestSetup(integration_zcml).setUp()
    def setUp(test):
        FunctionalTestSetup().setUp()

        if kwsetUp is not None:
            kwsetUp(test)
 def tearDown(test):
     if kwtearDown is not None:
         kwtearDown(test)
     FunctionalTestSetup().tearDown()
Beispiel #7
0
def setUp(test):
    fts = FunctionalTestSetup()
    fts.setUp()
    app = fts.getRootFolder()
    setSite(app)
Beispiel #8
0
def tearDown(test):
    setSite(None)
    fts = FunctionalTestSetup()
    fts.tearDown()
Beispiel #9
0
def setUp(test):
    FunctionalTestSetup().setUp()
    # register provider TALES
    from zope.app.pagetemplate import metaconfigure
    from zope.contentprovider import tales
    metaconfigure.registerType('provider', tales.TALESProviderExpression)
Beispiel #10
0
def layeredTestTearDown():
    setSite(None)
    fts = FunctionalTestSetup()
    fts.tearDown()
Beispiel #11
0
def layeredTestSetup():
    fts = FunctionalTestSetup()
    fts.setUp()
    app = fts.getRootFolder()
    setSite(app)
Beispiel #12
0
 def setUp(self):
     self.setup = FunctionalTestSetup(
         self.config_file, product_config=self.product_config)
     self.db = createTestDB(self.db_name)
     self.base_storage = self.db._storage
     self._base_db_open = True
Beispiel #13
0
class ZODBLayer(object):
    """This layer load a ZCML configuration and create a test database.

    You can access the test database with layer.getRootFolder().
    """
    db = None
    db_name = 'main'
    connection = None
    __bases__ = tuple()
    
    def __init__(self, config_file, module, name, allow_teardown=False,
                 product_config=None):
        self.config_file = config_file
        self.__module__ = module
        self.__name__ = name
        self.allow_teardown = allow_teardown
        self.product_config = product_config
    
    def getRootFolder(self):
        """This return the root object of the database or assert if
        the database have not been created yet.
        """
        if self.connection is None:
            assert self.db is not None
            self.connection = self.db.open()
        return self.connection.root()[ZopePublication.root_name]

    def _close_db(self):
        # Close any opened connections
        if self.connection is not None:
            transaction.abort()
            self.connection.close()
            self.connection = None

        # Close the Database
        if self.db is not None:
            base = component.getGlobalSiteManager()
            base.unregisterUtility(
                self.db, ZODB.interfaces.IDatabase, self.db_name)
            self.db.close()
            self.db = None

    def setUp(self):
        self.setup = FunctionalTestSetup(
            self.config_file, product_config=self.product_config)
        self.db = createTestDB(self.db_name)
        self.base_storage = self.db._storage
        self._base_db_open = True

    def testSetUp(self):
        from fernlehrgang.models import Base
        session = Session()
        Base.metadata.create_all(session.connection().engine)
        transaction.commit()
        if self._base_db_open:
            self._close_db()
            self._base_db_open = False
        self.db = createTestDB(self.db_name, self.base_storage)

    def testTearDown(self):
        self._close_db()
        from fernlehrgang.models import Base
        session = Session()
        Base.metadata.drop_all(session.connection().engine)
        transaction.commit()
        session.close()

    def tearDown(self):
        self.setup.tearDownCompletely()
        if not self.allow_teardown:
            raise NotImplementedError