Exemplo n.º 1
0
    def test_validates_success(self):
        import pyon.util.arg_check as ac
        fl = self._FakeLog()
        ac.log = fl
        try:
            ac.validateTrue(False,'blah')
        except BadRequest as e:
            self.assertTrue(e.message == 'blah')

        self.assertEquals(fl.name,"pyon.util.test.test_arg_check")
Exemplo n.º 2
0
    def test_validates_success(self):
        import pyon.util.arg_check as ac
        fl = self._FakeLog()
        ac.log = fl
        try:
            ac.validateTrue(False, 'blah')
        except BadRequest as e:
            self.assertTrue(e.message == 'blah')

        self.assertEquals(fl.name, "pyon.util.test.test_arg_check")
Exemplo n.º 3
0
    def get_datastore(self, ds_name, profile=DataStore.DS_PROFILE.BASIC, config=None):
        """
        Factory method to get a datastore instance from given name, profile and config.
        This is the central point to cache these instances, to decide persistent or mock
        and to force clean the store on first use.
        @param ds_name  Logical name of datastore (will be scoped with sysname)
        @param profile  One of known constants determining the use of the store
        @param config  Override config to use
        """
        validateTrue(ds_name,'ds_name must be provided')
        if ds_name in self._datastores:
            log.debug("get_datastore(): Found instance of store '%s'" % ds_name)
            return self._datastores[ds_name]

        scoped_name = DatastoreManager.get_scoped_name(ds_name)

        # Imports here to prevent cyclic module dependency
        from pyon.core.bootstrap import CFG
        config = config or CFG

        if self.persistent is None:
            self.persistent = not bool(get_safe(config, "system.mockdb"))
        if self.force_clean is None:
            self.force_clean = bool(get_safe(config, "system.force_clean"))

        # Create a datastore instance
        log.info("get_datastore(): Create instance of store '%s' {persistent=%s, scoped_name=%s}" % (
            ds_name, self.persistent, scoped_name))
        new_ds = DatastoreManager.get_datastore_instance(ds_name, self.persistent, profile)

        # Clean the store instance
        # TBD: Do we really want to do it here? or make it more manual?
        if self.force_clean:
            log.info("get_datastore(): Force clean store '%s'" % ds_name)
            try:
                new_ds.delete_datastore(scoped_name)
            except NotFound:
                pass

        # Create store if not existing
        if not new_ds.datastore_exists(scoped_name):
            new_ds.create_datastore(scoped_name)
        else:
            if self.persistent:
                # NOTE: This may be expensive if called more than once per container
                # If views exist and are dropped and recreated
                new_ds._define_views(profile=profile, keepviews=True)

        # Set a few standard datastore instance fields
        new_ds.local_name = ds_name
        new_ds.ds_profile = profile

        self._datastores[ds_name] = new_ds

        return new_ds
Exemplo n.º 4
0
    def test_validations(self):
        import pyon.util.arg_check as arg_check

        with self.assertRaises(BadRequest):
            arg_check.validateTrue(False,'test')

        with self.assertRaises(BadRequest):
            arg_check.validateEqual(3,4,'test')

        with self.assertRaises(BadRequest):
            arg_check.validateNotEqual(4,4,'test')

        with self.assertRaises(BadRequest):
            arg_check.validateFalse(True,'test')

        with self.assertRaises(BadRequest):
            one = list()
            two = list()
            arg_check.validateIs(one,two,'test')

        with self.assertRaises(BadRequest):
            one = list()
            two = one
            arg_check.validateIsNot(one,two,'test')

        with self.assertRaises(BadRequest):
            c = None
            arg_check.validateIsNotNone(c,'test')

        with self.assertRaises(BadRequest):
            one = list([1,3])
            two = 2
            arg_check.validateIn(two,one,'test')

        with self.assertRaises(BadRequest):
            one = list([1,2,3])
            two = 2
            arg_check.validateNotIn(two,one,'test')

        with self.assertRaises(BadRequest):
            one = list()
            arg_check.validateIsInstance(one,dict,'test')

        with self.assertRaises(BadRequest):
            one = list()
            arg_check.validateNotIsInstance(one,list,'test')
Exemplo n.º 5
0
    def test_validations(self):
        import pyon.util.arg_check as arg_check

        with self.assertRaises(BadRequest):
            arg_check.validateTrue(False, 'test')

        with self.assertRaises(BadRequest):
            arg_check.validateEqual(3, 4, 'test')

        with self.assertRaises(BadRequest):
            arg_check.validateNotEqual(4, 4, 'test')

        with self.assertRaises(BadRequest):
            arg_check.validateFalse(True, 'test')

        with self.assertRaises(BadRequest):
            one = list()
            two = list()
            arg_check.validateIs(one, two, 'test')

        with self.assertRaises(BadRequest):
            one = list()
            two = one
            arg_check.validateIsNot(one, two, 'test')

        with self.assertRaises(BadRequest):
            c = None
            arg_check.validateIsNotNone(c, 'test')

        with self.assertRaises(BadRequest):
            one = list([1, 3])
            two = 2
            arg_check.validateIn(two, one, 'test')

        with self.assertRaises(BadRequest):
            one = list([1, 2, 3])
            two = 2
            arg_check.validateNotIn(two, one, 'test')

        with self.assertRaises(BadRequest):
            one = list()
            arg_check.validateIsInstance(one, dict, 'test')

        with self.assertRaises(BadRequest):
            one = list()
            arg_check.validateNotIsInstance(one, list, 'test')
Exemplo n.º 6
0
    def get_datastore(self,
                      ds_name,
                      profile=DataStore.DS_PROFILE.BASIC,
                      config=None):
        """
        Factory method to get a datastore instance from given name, profile and config.
        This is the central point to cache these instances, to decide persistent or mock
        and to force clean the store on first use.
        @param ds_name  Logical name of datastore (will be scoped with sysname)
        @param profile  One of known constants determining the use of the store
        @param config  Override config to use
        """
        validateTrue(ds_name, 'ds_name must be provided')
        if ds_name in self._datastores:
            log.debug("get_datastore(): Found instance of store '%s'" %
                      ds_name)
            return self._datastores[ds_name]

        scoped_name = DatastoreManager.get_scoped_name(ds_name)

        # Imports here to prevent cyclic module dependency
        from pyon.core.bootstrap import CFG
        config = config or CFG

        if self.persistent is None:
            self.persistent = not bool(get_safe(config, "system.mockdb"))
        if self.force_clean is None:
            self.force_clean = bool(get_safe(config, "system.force_clean"))

        # Create a datastore instance
        log.info(
            "get_datastore(): Create instance of store '%s' {persistent=%s, scoped_name=%s}"
            % (ds_name, self.persistent, scoped_name))
        new_ds = DatastoreManager.get_datastore_instance(
            ds_name, self.persistent, profile)

        # Clean the store instance
        # TBD: Do we really want to do it here? or make it more manual?
        if self.force_clean:
            log.info("get_datastore(): Force clean store '%s'" % ds_name)
            try:
                new_ds.delete_datastore(scoped_name)
            except NotFound:
                pass

        # Create store if not existing
        if not new_ds.datastore_exists(scoped_name):
            new_ds.create_datastore(scoped_name)
        else:
            if self.persistent:
                # NOTE: This may be expensive if called more than once per container
                # If views exist and are dropped and recreated
                new_ds._define_views(profile=profile, keepviews=True)

        # Set a few standard datastore instance fields
        new_ds.local_name = ds_name
        new_ds.ds_profile = profile

        self._datastores[ds_name] = new_ds

        return new_ds
Exemplo n.º 7
0
 def list_len(self, l):
     '''
     You needed to be certain that a list had len >0
     '''
     validateTrue(len(l) > 0, 'list=%s was empty.' % str(l))
Exemplo n.º 8
0
 def list_len(self, l):
     """
     You needed to be certain that a list had len >0
     """
     validateTrue(len(l) > 0, "list=%s was empty." % str(l))