コード例 #1
0
    def test_update_dataset_sqlalchemy_error(self, mock_dao_update):
        """
            Dataset API: Test update dataset sqlalchemy error
        """
        mock_dao_update.side_effect = DAOUpdateFailedError()

        table = self.insert_dataset("ab_permission", "", [],
                                    get_example_database())
        self.login(username="******")
        table_data = {"description": "changed_description"}
        uri = f"api/v1/dataset/{table.id}"
        rv = self.client.put(uri, json=table_data)
        data = json.loads(rv.data.decode("utf-8"))
        self.assertEqual(rv.status_code, 422)
        self.assertEqual(data, {"message": "Dataset could not be updated."})
コード例 #2
0
 def update(cls, model: Model, properties: Dict, commit: bool = True) -> Model:
     """
     Generic update a model
     :raises: DAOCreateFailedError
     """
     for key, value in properties.items():
         setattr(model, key, value)
     try:
         db.session.merge(model)
         if commit:
             db.session.commit()
     except SQLAlchemyError as e:  # pragma: no cover
         db.session.rollback()
         raise DAOUpdateFailedError(exception=e)
     return model
コード例 #3
0
    def test_update_dataset_sqlalchemy_error(self, mock_dao_update):
        """
        Dataset API: Test update dataset sqlalchemy error
        """
        mock_dao_update.side_effect = DAOUpdateFailedError()

        dataset = self.insert_default_dataset()
        self.login(username="******")
        table_data = {"description": "changed_description"}
        uri = f"api/v1/dataset/{dataset.id}"
        rv = self.client.put(uri, json=table_data)
        data = json.loads(rv.data.decode("utf-8"))
        assert rv.status_code == 422
        assert data == {"message": "Dataset could not be updated."}

        db.session.delete(dataset)
        db.session.commit()
コード例 #4
0
ファイル: base.py プロジェクト: Sareni/superset
    def update(cls,
               model: Model,
               properties: Dict[str, Any],
               commit: bool = True) -> Model:
        """
        Generic update a model
        :raises: DAOCreateFailedError
        """

        logging.debug('XXXXXXXXXXXXXXXXX')
        logging.debug(str(model.__dict__))

        for key, value in properties.items():
            logging.debug(str(key) + ': ' + str(value))
            setattr(model, key, value)
        logging.debug('fin ------------')
        try:
            db.session.merge(model)
            if commit:
                db.session.commit()
        except SQLAlchemyError as ex:  # pragma: no cover
            db.session.rollback()
            raise DAOUpdateFailedError(exception=ex)
        return model