Esempio n. 1
0
 def _populate_database(
         cls,
         settings: plaster_pastedeploy.ConfigDict,
         add_test_data: bool
 ) -> None:
     engine = get_engine(settings)
     session_factory = get_session_factory(engine)
     app_config = CFG(settings)
     print("- Populate database with default data -")
     with transaction.manager:
         dbsession = get_tm_session(session_factory, transaction.manager)
         try:
             fixtures = [BaseFixture]
             fixtures_loader = FixturesLoader(dbsession, app_config)
             fixtures_loader.loads(fixtures)
             transaction.commit()
             if add_test_data:
                 app_config.configure_filedepot()
                 fixtures = [ContentFixture]
                 fixtures_loader.loads(fixtures)
             transaction.commit()
             print("Database initialized.")
         except IntegrityError as exc:
             transaction.abort()
             print('Database initialization failed')
             raise DatabaseInitializationFailed(
                 'Warning, there was a problem when adding default data'
                 ', it may have already been added.'
             ) from exc
Esempio n. 2
0
def base_fixture(session, app_config) -> Session:
    with transaction.manager:
        try:
            fixtures_loader = FixturesLoader(session, app_config)
            fixtures_loader.loads([BaseFixture])
        except IntegrityError as e:
            transaction.abort()
            raise e
    transaction.commit()
    return session
Esempio n. 3
0
def default_content_fixture(base_fixture, app_config) -> Session:
    """
    Warning! This fixture is now deprecated. Don't use it for new tests.
    """
    with transaction.manager:
        try:
            fixtures_loader = FixturesLoader(base_fixture, app_config)
            fixtures_loader.loads([ContentFixture])
        except IntegrityError as e:
            transaction.abort()
            raise e
    transaction.commit()
    return session
Esempio n. 4
0
def test_fixture(session, app_config) -> Session:
    """
    Warning ! This fixture is now deprecated. Don't use it for new created tests.
    """
    with transaction.manager:
        try:
            fixtures_loader = FixturesLoader(session, app_config)
            fixtures_loader.loads([FixtureTest])
        except IntegrityError as e:
            transaction.abort()
            raise e
    transaction.commit()
    return session
Esempio n. 5
0
 def init_database(self, settings: typing.Dict[str, typing.Any]):
     with transaction.manager:
         try:
             fixtures_loader = FixturesLoader(self.session, self.app_config)
             fixtures_loader.loads(self.fixtures)
             transaction.commit()
             logger.info(self, "Database initialized.")
         except IntegrityError:
             logger.error(
                 self,
                 'Warning, there was a problem when adding default data'  # nopep8
                 ', it may have already been added:')
             import traceback
             logger.error(self, traceback.format_exc())
             transaction.abort()
             logger.error(self, 'Database initialization failed')
Esempio n. 6
0
 def init_database(self) -> None:
     session = get_tm_session(self.session_factory, transaction.manager)
     with transaction.manager:
         try:
             DeclarativeBase.metadata.create_all(self.engine)
             fixtures_loader = FixturesLoader(session, self.app_config)
             fixtures_loader.loads(self.fixtures)
             transaction.commit()
             logger.info(self, "Database initialized.")
         except IntegrityError:
             logger.error(
                 self,
                 'Warning, there was a problem when adding default data'  # nopep8
                 ', it may have already been added:')
             import traceback
             logger.error(self, traceback.format_exc())
             transaction.abort()
             logger.error(self, 'Database initialization failed')
Esempio n. 7
0
 def _populate_database(cls, settings: plaster_pastedeploy.ConfigDict,
                        add_test_data: bool) -> None:
     engine = get_engine(settings)
     session_factory = get_session_factory(engine)
     app_config = CFG(settings)
     print("- Populate database with default data -")
     with transaction.manager:
         dbsession = get_tm_session(session_factory, transaction.manager)
         try:
             fixtures = [BaseFixture]
             fixtures_loader = FixturesLoader(dbsession, app_config)
             fixtures_loader.loads(fixtures)
             transaction.commit()
             if add_test_data:
                 app_config.configure_filedepot()
                 fixtures = [ContentFixture]
                 fixtures_loader.loads(fixtures)
             transaction.commit()
             print("Database initialized.")
         except IntegrityError as exc:
             transaction.abort()
             print('Database initialization failed')
             raise DatabaseInitializationFailed(
                 'Warning, there was a problem when adding default data'
                 ', it may have already been added.') from exc