Exemplo n.º 1
0
def update_dataset_details(dataset_id):
    """Update dataset details.

    If one of the fields is not specified, it will not be updated.

    **Example request**:

    .. sourcecode:: json

        {
            "name": "Not Mood",
            "description": "Dataset for mood misclassification.",
            "public": true
        }

    :reqheader Content-Type: *application/json*
    :<json string name: *Optional.* Name of the dataset.
    :<json string description: *Optional.* Description of the dataset.
    :<json boolean public: *Optional.* ``true`` to make dataset public, ``false`` to make it private.

    :resheader Content-Type: *application/json*
    """
    ds = get_check_dataset(dataset_id, write=True)
    dataset_data = request.get_json()

    try:
        dataset_validator.validate_dataset_update(dataset_data)
    except dataset_validator.ValidationException as e:
        raise api_exceptions.APIBadRequest(e.error)

    db.dataset.update_dataset_meta(ds["id"], dataset_data)
    return jsonify(success=True, message="Dataset updated.")
Exemplo n.º 2
0
def update_dataset_details(dataset_id):
    """Update dataset details.

    If one of the fields is not specified, it will not be updated.

    **Example request**:

    .. sourcecode:: json

        {
            "name": "Not Mood",
            "description": "Dataset for mood misclassification.",
            "public": true
        }

    :reqheader Content-Type: *application/json*
    :<json string name: *Optional.* Name of the dataset.
    :<json string description: *Optional.* Description of the dataset.
    :<json boolean public: *Optional.* ``true`` to make dataset public, ``false`` to make it private.

    :resheader Content-Type: *application/json*
    """
    ds = get_check_dataset(dataset_id, write=True)
    dataset_data = request.get_json()

    try:
        dataset_validator.validate_dataset_update(dataset_data)
    except dataset_validator.ValidationException as e:
        raise api_exceptions.APIBadRequest(str(e))

    db.dataset.update_dataset_meta(ds["id"], dataset_data)
    return jsonify(
        success=True,
        message="Dataset updated."
    )
    def test_dataset_update(self):
        # All fields is OK
        dataset_validator.validate_dataset_update({
            "name": "dataset name",
            "description": "description",
            "public": True
        })
        # An empty dict is OK
        dataset_validator.validate_dataset_update({})

        # Extra field
        with self.assertRaises(dataset_validator.ValidationException):
            dataset_validator.validate_dataset_update(
                {"anotherfield": "value"})

        # Name too short
        with self.assertRaises(dataset_validator.ValidationException):
            dataset_validator.validate_dataset_update({"name": ""})

        # desc must be string
        with self.assertRaises(dataset_validator.ValidationException):
            dataset_validator.validate_dataset_update({"description": 1})

        # public must be boolean
        with self.assertRaises(dataset_validator.ValidationException):
            dataset_validator.validate_dataset_update({"public": "true"})
    def test_dataset_update(self):
        # All fields is OK
        dataset_validator.validate_dataset_update({"name": "dataset name",
                                                   "description": "description",
                                                   "public": True})
        # An empty dict is OK
        dataset_validator.validate_dataset_update({})

        # Extra field
        with self.assertRaises(dataset_validator.ValidationException):
            dataset_validator.validate_dataset_update({"anotherfield": "value"})

        # Name too short
        with self.assertRaises(dataset_validator.ValidationException):
            dataset_validator.validate_dataset_update({"name": ""})

        # desc must be string
        with self.assertRaises(dataset_validator.ValidationException):
            dataset_validator.validate_dataset_update({"description": 1})

        # public must be boolean
        with self.assertRaises(dataset_validator.ValidationException):
            dataset_validator.validate_dataset_update({"public": "true"})