Ejemplo n.º 1
0
    def test_app_user_can_create(self):
        """Can the application user perform inserts?"""

        with session_scope(Session) as session:

            user = User()
            user.name = "Test User"
            session.add(user)

        with session_scope(Session) as another_session:

            count = another_session.query(User).count()
            self.assertEqual(count, 1, "Expected a single user")
Ejemplo n.º 2
0
    def _save_analysis(self, result_ds):
        """ Saves the analysis to the database
            Params:
                analysis_obj: The analysis object containing the updated fields
                result_ds: Dataset containing the results to associate with this analysis
        """
        with session_scope() as session:

            a = session.query(Analysis).get(self._analysis_obj.id)
            a.result_dataset = result_ds
            a.run_date = datetime.datetime.now()
            a.result_image = self._analysis_obj.result_image
            a.fit_image = self._analysis_obj.fit_image
            a.aic = self._analysis_obj.aic
            a.model_formula = self._analysis_obj.model_formula
            session.add(result_ds)
            session.add(a)
Ejemplo n.º 3
0
    def _update_progress(self, message, complete=False):
        """Simply updates the analysis progress message
            Params:
                analysis_obj: Analysis object to update
                message: Message to use
                complete: Set to True if complete
        """

        log.debug(message)

        with session_scope() as session:

            a = session.query(Analysis).get(self._analysis_obj.id)

            a.progress_message = message
            a.complete = complete
            session.add(a)
Ejemplo n.º 4
0
def setup_app(command, conf, vars):
    """Place any commands to setup ecomaps here - currently creating db tables"""

    # Don't reload the app if it was loaded under the testing environment
    if not pylons.test.pylonsapp:
        load_environment(conf.global_conf, conf.local_conf)

    # Create the tables if they don't already exist
    Base.metadata.drop_all(bind=Session.bind)
    Base.metadata.create_all(bind=Session.bind)

    with session_scope(Session) as session:

        user = User()
        user.name = "Phil Jenkins"
        user.first_name = "Phil"
        user.last_name = "Jenkins"
        user.username = "******"
        user.email = "*****@*****.**"
        user.access_level = "Admin"

        session.add(user)

        user2 = User()
        user2.name = "Mike Wilson"
        user2.first_name = "Mike"
        user2.last_name = "Wilson"
        user2.username = "******"
        user2.email = "*****@*****.**"
        user2.access_level = "Admin"

        session.add(user2)

        # Model that provides the interface to the R code
        model = Model()
        model.name = "LCM Thredds Model"
        model.id = 1
        model.description = "LCM Thredds model written in R"
        model.code_path = "code_root"

        session.add(model)

        pointDst = DatasetType()
        pointDst.type = "Point"

        coverDst = DatasetType()
        coverDst.type = "Coverage"

        resultDst = DatasetType()
        resultDst.type = "Result"

        session.add(pointDst)
        session.add(coverDst)
        session.add(resultDst)

        # Define a datasetType lookup. This will conver the possible thredds
        # datasets into their EcoMaps equivalents.
        datasetTypes = {"GRID": coverDst, "POINT": pointDst}

        # Populate from thredds
        registerThreddsDatasets("http://thredds.ceh.ac.uk/thredds/ecomaps.xml", datasetTypes, session)