Beispiel #1
0
    def __init__(self):

        # Making sure that all the entities has been imported (i.e. initialized)
        assert auth_model is not None
        assert user_model is not None
        assert campaign_model is not None

        self.flask_app = flask.Flask(__name__)

        properties.init()

        self.host = properties.get_app_host()
        self.port = properties.get_app_port()

        db_access.init()

        # Registering web-service endpoints
        self.flask_app.register_blueprint(auth_endpoint.AUTH_BLUEPRINT)
        self.flask_app.register_blueprint(users_endpoint.USERS_BLUEPRINT)
        self.flask_app.register_blueprint(
            my_campaigns_endpoint.MY_CAMPAIGNS_BLUEPRINT)

        # Registering views
        self.flask_app.register_blueprint(index_view.INDEX_BLUEPRINT)

        session = db_access.Session()
        try:
            if not startup_service.superuser_exists():
                startup_service.create_superuser()
            else:
                superuser_roles = user_roles_service.get_user_roles(
                    "superuser")

                grant_required = False
                for role in roles.ALL_ROLES:
                    if role not in superuser_roles:
                        grant_required = True
                        break

                if grant_required:
                    user_roles_service.grant_roles("SYSTEM", "superuser",
                                                   roles.ALL_ROLES)

            session.commit()

        except Exception as err:
            session.rollback()
            logger.log_error("Error on application startup: {}".format(
                str(err)))
            raise err
        finally:
            session.close()

        logger.log_info("Application initialized.")
Beispiel #2
0
 def setUp(self):
     assertModelInitialized()
     properties.init()
     db_access.init()
     self.session = db_access.Session()
 def setUp(self):
     properties.init()
     db_access.init()
     self.session = db_access.Session()