Beispiel #1
0
 def name(self, value):
     check_type(value=value,
                allowed_types=[str, None],
                var_name="name",
                raise_exception=True)
     if value is not None:
         check_is_valid_ds_name(value=value, raise_exception=True)
         if self.__name != value:
             self.__flag_ts_loaded = False
             self.__name = value
Beispiel #2
0
    def dataset_delete(self, name, deep=False):
        """
        Remove data_set from base

        Corresponding web app resource operation: **removeDataSet**

        :param name: name of the dataset to delete
        :type name: str

        :param deep: true to deeply remove dataset (TSUID and metadata erased)
        :type deep: boolean

        :returns: the response body
        :rtype: str

        .. note::
           Removing an unknown dataset results in a successful operation (server constraint)
           The only possible errors may come from server (HTTP status_code code 5xx)

        :raises TypeError: if *name* is not a str
        :raises TypeError: if *deep* is not a bool
        """

        # Checks inputs
        check_type(value=name,
                   allowed_types=str,
                   var_name="name",
                   raise_exception=True)
        check_is_valid_ds_name(value=name, raise_exception=True)
        check_type(value=deep,
                   allowed_types=bool,
                   var_name="deep",
                   raise_exception=True)

        template = 'dataset_remove'
        if deep:
            template = 'dataset_deep_remove'
        response = self.send(root_url=self.session.dm_url + self.root_url,
                             verb=GenericClient.VERB.DELETE,
                             template=TEMPLATES[template],
                             uri_params={'name': name})

        if response.status_code == 404:
            raise IkatsNotFoundError("Dataset %s not found in database" % name)
        return response.text
Beispiel #3
0
    def delete(self, name, deep=False, raise_exception=True):
        """
        Remove dataset from database
        Returns a boolean status of the action (True means "OK", False means "errors occurred")

        :param name: Dataset name to delete
        :param deep: true to deeply remove dataset (tsuid and metadata erased)
        :param raise_exception: Indicates if exceptions shall be raised (True, default) or not (False)

        :type name: str or Dataset
        :type deep: bool
        :type raise_exception: bool

        :returns: the status of the action
        :rtype: bool

        :raises TypeError: if *name* is not a str
        :raises TypeError: if *deep* is not a bool
        :raises ValueError: if *name* is a valid name
        :raises IkatsNotFoundError: if dataset not found in database
        """
        check_type(value=deep,
                   allowed_types=[bool, None],
                   var_name="deep",
                   raise_exception=True)
        check_type(value=name,
                   allowed_types=[str, Dataset],
                   var_name="name",
                   raise_exception=True)

        if isinstance(name, Dataset):
            name = name.name

        check_is_valid_ds_name(value=name, raise_exception=True)

        try:
            self.dm_client.dataset_delete(name=name, deep=deep)
        except IkatsException:
            if raise_exception:
                raise
            return False
        return True
Beispiel #4
0
    def save(self, ds, raise_exception=True):
        """
        Save the dataset to database (creation only, no update available)
        Returns a boolean status of the action (True means "OK", False means "errors occurred")

        :param ds: Dataset to create
        :param raise_exception: Indicates if exceptions shall be raised (True, default) or not (False)

        :type ds: Dataset
        :type raise_exception: bool

        :returns: the status of the action
        :rtype: bool

        :raises TypeError: if *ds* is not a valid Dataset object
        :raises ValueError: if *ds* doesn't contain any Timeseries
        :raises IkatsConflictError: if Dataset name already exists in database
        """

        check_is_valid_ds_name(ds.name, raise_exception=True)
        if ds.ts is None or (isinstance(ds.ts, list) and not ds.ts):
            raise ValueError("No TS to save")

        for ts in ds.ts:
            if ts.tsuid is None:
                raise IkatsInputError("TS %s doesn't have a TSUID" % ts.fid)

        try:
            self.dm_client.dataset_create(name=ds.name,
                                          description=ds.desc,
                                          ts=[x.tsuid for x in ds.ts])
        except IkatsException:
            if raise_exception:
                raise
            return False
        return True
Beispiel #5
0
    def test_check_is_valid_ds_name(self):
        """
        Test check_is_valid_ds_name function
        """

        # DS name not a str
        ds_name = 123
        with self.assertRaises(TypeError):
            check_is_valid_ds_name(value=ds_name, raise_exception=True)
        self.assertFalse(
            check_is_valid_ds_name(value=ds_name, raise_exception=False))

        # DS name too short
        ds_name = "a"
        with self.assertRaises(ValueError):
            check_is_valid_ds_name(value=ds_name, raise_exception=True)
        self.assertFalse(
            check_is_valid_ds_name(value=ds_name, raise_exception=False))

        # DS name too short
        ds_name = ""
        with self.assertRaises(ValueError):
            check_is_valid_ds_name(value=ds_name, raise_exception=True)
        self.assertFalse(
            check_is_valid_ds_name(value=ds_name, raise_exception=False))

        # DS name contains spaces
        ds_name = "DS name contains spaces"
        with self.assertRaises(ValueError):
            check_is_valid_ds_name(value=ds_name, raise_exception=True)
        self.assertFalse(
            check_is_valid_ds_name(value=ds_name, raise_exception=False))

        # Valid DS Name
        ds_name = "azerty"
        self.assertTrue(
            check_is_valid_ds_name(value=ds_name, raise_exception=False))