Exemple #1
0
 def setUp(self):
     super(DbTests, self).setUp()
     cfg = self.env_aware_cfg()
     self.point_to_sqlite_database(cfg,
                                   ngamsTestLib.tmp_path('ngas.sqlite'))
     self.db = ngamsDb.from_config(cfg, maxpool=1)
     ngamsTestLib.delNgasTbls(self.db)
Exemple #2
0
    def loadCfg(self,
                dbCfgName,
                cfgFile = "src/ngamsCfg.xml",
                dbCfgGroupIds = stdCfgGrIdList,
                checkCfg = 1,
                delDbTbls = 1,
                createDatabase = True):
        """
        Load configuration into NGAS DB. Return the configuration and DB objects.

        cfgFile:        Name of configuration file to load (string).

        dbCfgGroupIds:  DB Cfg. Group IDs to use when defining the cfg. (list).

        checkCfg:       Check cfg. when loading before writing in the DB
                        (integer/0|1).

        delDbTbls:      Delete the NGAS tables in the DB (integer/0|1).

        Returns:        Tuple with ngamsConfig and ngamsDb Objects (tuple).
        """
        # This ensure the Db.Id attribute is what we want it to be
        cfgObj = self.env_aware_cfg(cfgFile, check=checkCfg, db_id_attr=dbIdAttr)
        revAttr = "NgamsCfg.Header[1].Revision"
        cfgObj.storeVal(revAttr, "TEST-REVISION", "ngamsCfg-Test")

        self.point_to_sqlite_database(cfgObj, createDatabase)
        dbObj = ngamsDb.from_config(cfgObj, maxpool=1)
        if (delDbTbls): delNgasTbls(dbObj)
        cfgObj.writeToDb(dbObj)

        # Create a DB configuration association.
        sql = "INSERT INTO ngas_cfg (cfg_name, cfg_par_group_ids, cfg_comment) VALUES ({0}, {1}, 'Test Cfg')"
        dbObj.query2(sql, args=(dbCfgName, ','.join([str(x) for x in dbCfgGroupIds])))
        return (cfgObj, dbObj)
Exemple #3
0
    def test_subscription_equality(self):

        # baseline
        URL = 'http://127.0.0.1:1234/path'
        subs1 = ngamsSubscriber.ngamsSubscriber(url=URL, subscrId='my-id')
        subs2 = ngamsSubscriber.ngamsSubscriber(url=URL, subscrId='my-id')
        self.assertEqual(subs1, subs2)

        # Store in DB, check equality holds
        cfg = self.env_aware_cfg()
        self.point_to_sqlite_database(cfg, tmp_path('ngas.sqlite'))
        db = ngamsDb.from_config(cfg, maxpool=1)
        with contextlib.closing(db):
            db_subs1 = db.insertSubscriberEntry(subs1)
            db_subs2 = db.insertSubscriberEntry(subs2)
            self.assertIs(subs1, db_subs1)
            self.assertEqual(subs1, db_subs2)
            self.assertEqual(subs2, db_subs2)