Пример #1
0
    def delete(self, id_: str, path: str) -> Response:
        """Delete object with id=id_ from database."""
        id_ = str(id_)
        auth_response = check_authentication_response()
        if isinstance(auth_response, Response):
            return auth_response

        class_type = get_doc().collections[path]["collection"].class_.title

        if checkClassOp(class_type, "DELETE"):
            # Check if class_type supports PUT operation
            try:
                # Delete the Item with ID == id_
                crud.delete(id_, class_type, session=get_session())
                response = {
                    "message": "Object with ID %s successfully deleted" % (id_)
                }
                return set_response_headers(jsonify(response))

            except (ClassNotFound, InstanceNotFound) as e:
                status_code, message = e.get_HTTP()
                return set_response_headers(jsonify(message),
                                            status_code=status_code)

        abort(405)
Пример #2
0
def items_delete_check_support(id_, class_type, path, is_collection):
    """Check if class_type supports PUT operation"""
    try:
        # Delete the Item with ID == id_
        # for colletions, id_ is corresponding to their collection_id and not the id_
        # primary key
        crud.delete(id_,
                    class_type,
                    session=get_session(),
                    collection=is_collection)
        method = "DELETE"
        resource_url = f"{get_hydrus_server_url()}{get_api_name()}/{path}/{id_}"
        last_job_id = crud.get_last_modification_job_id(session=get_session())
        new_job_id = crud.insert_modification_record(method,
                                                     resource_url,
                                                     session=get_session())
        send_sync_update(socketio=socketio,
                         new_job_id=new_job_id,
                         last_job_id=last_job_id,
                         method=method,
                         resource_url=resource_url)
        status_description = f"Object with ID {id_} successfully deleted"
        status = HydraStatus(code=200,
                             title="Object successfully deleted.",
                             desc=status_description)
        return set_response_headers(jsonify(status.generate()))

    except (ClassNotFound, InstanceNotFound) as e:
        error = e.get_HTTP()
        return error_response(error)
Пример #3
0
    def delete(self, id_, type_):
        """Delete object with id=id_ from database."""
        if get_authentication():
            if request.authorization is None:
                return failed_authentication()
            else:
                auth = check_authorization(request, get_session())
                if auth is False:
                    return failed_authentication()

        class_type = get_doc().collections[type_]["collection"].class_.title

        if checkClassOp(class_type, "DELETE"):
            try:
                crud.delete(id_, class_type, session=get_session())
                response = {
                    "message": "Object with ID %s successfully deleted" % (id_)
                }
                return set_response_headers(jsonify(response))

            except Exception as e:
                status_code, message = e.get_HTTP()
                return set_response_headers(jsonify(message),
                                            status_code=status_code)

        abort(405)
Пример #4
0
    def on_delete(self, req, resp, id_: int, type_: str):
        """Delete object with id=id_ from database."""

        if get_authentication(resp):
            if req.auth is None:
                return failed_authentication(resp)
            else:
                try:
                    auth = check_authorization(req, get_session(resp))
                    if auth is False:
                        return failed_authentication(resp)
                except Exception as e:
                    status_code, message = e.get_HTTP()  # type: ignore
                    resp.media = message
                    return set_response_headers(resp, status_code=status_code)

        class_type = get_doc(resp).collections[type_]["collection"].class_.title

        if checkClassOp(resp, class_type, "DELETE"):
            # Check if class_type supports PUT operation
            try:
                # Delete the Item with ID == id_
                crud.delete(id_, class_type, session=get_session(resp))
                response = {
                    "message": "Object with ID %s successfully deleted" % (id_)}
                resp.media = response
                return set_response_headers(resp)

            except Exception as e:
                status_code, message = e.get_HTTP()
                resp.media = message
                return set_response_headers(resp, status_code= status_code)

        resp.status = falcon.HTTP_405
Пример #5
0
 def test_delete(self):
     """Test CRUD delete."""
     object_ = gen_dummy_object("dummyClass", self.doc)
     id_ = 4
     insert_response = crud.insert(object_=object_, id_=id_, session=self.session)
     delete_response = crud.delete(id_=id_, type_=object_["@type"], session=self.session)
     assert type(insert_response) is int
     response_code = None
     try:
         get_response = crud.get(id_=id_, type_=object_["@type"], session=self.session, api_name="api")
     except Exception as e:
         response_code, message = e.get_HTTP()
     assert 404 == response_code
Пример #6
0
 def test_delete_id(self):
     """Test CRUD delete when wrong/undefined ID is given."""
     object_ = gen_dummy_object("dummyClass", self.doc)
     id_ = 6
     insert_response = crud.insert(object_=object_, id_=id_, session=self.session)
     response_code = None
     try:
         delete_response = crud.delete(id_=999, type_=object_["@type"], session=self.session)
     except Exception as e:
         response_code, message = e.get_HTTP()
     assert 404 == response_code
     assert type(insert_response) is int
     assert insert_response == id_
Пример #7
0
    def delete(self, id_: int, type_: str) -> Response:
        """Delete object with id=id_ from database."""
        auth_response = check_authentication_response()
        if type(auth_response) == Response:
            return auth_response

        class_type = get_doc().collections[type_]["collection"].class_.title

        if checkClassOp(class_type, "DELETE"):
            # Check if class_type supports PUT operation
            try:
                # Delete the Item with ID == id_
                crud.delete(id_, class_type, session=get_session())
                response = {
                    "message": "Object with ID %s successfully deleted" % (id_)
                }
                return set_response_headers(jsonify(response))

            except Exception as e:
                status_code, message = e.get_HTTP()  # type: ignore
                return set_response_headers(jsonify(message),
                                            status_code=status_code)

        abort(405)
Пример #8
0
 def test_delete_type(self):
     """Test CRUD delete when wrong/undefined class is given."""
     object_ = gen_dummy_object("dummyClass", self.doc)
     id_ = 50
     insert_response = crud.insert(
         object_=object_, id_=id_, session=self.session)
     assert isinstance(insert_response, int)
     assert insert_response == id_
     response_code = None
     try:
         delete_response = crud.delete(
             id_=id_, type_="otherClass", session=self.session)
     except Exception as e:
         response_code, message = e.get_HTTP()
     assert 400 == response_code
Пример #9
0
def test_delete_on_wrong_type(drone_doc_parsed_classes, drone_doc, session):
    """Test CRUD delete when wrong/undefined class is given."""
    object_ = gen_dummy_object(random.choice(drone_doc_parsed_classes),
                               drone_doc)
    id_ = str(uuid.uuid4())
    insert_response = crud.insert(object_=object_, id_=id_, session=session)
    assert isinstance(insert_response, str)
    assert insert_response == id_
    response_code = None
    try:
        delete_response = crud.delete(id_=id_,
                                      type_='otherClass',
                                      session=session)
    except Exception as e:
        error = e.get_HTTP()
        response_code = error.code
    assert 400 == response_code
Пример #10
0
 def test_delete_id(self):
     """Test CRUD delete when wrong/undefined ID is given."""
     object_ = gen_dummy_object(random.choice(self.doc_collection_classes),
                                self.doc)
     id_ = "6"
     insert_response = crud.insert(object_=object_,
                                   id_=id_,
                                   session=self.session)
     response_code = None
     try:
         delete_response = crud.delete(id_=999,
                                       type_=object_["@type"],
                                       session=self.session)
     except Exception as e:
         response_code, message = e.get_HTTP()
     assert 404 == response_code
     assert isinstance(insert_response, str)
     assert insert_response == id_
Пример #11
0
def test_delete_on_object(drone_doc_parsed_classes, drone_doc, session):
    """Test CRUD delete on object"""
    object_ = gen_dummy_object(random.choice(drone_doc_parsed_classes),
                               drone_doc)
    id_ = str(uuid.uuid4())
    insert_response = crud.insert(object_=object_, id_=id_, session=session)
    assert isinstance(insert_response, str)
    delete_response = crud.delete(id_=id_,
                                  type_=object_['@type'],
                                  session=session)
    response_code = None
    try:
        get_response = crud.get(id_=id_,
                                type_=object_['@type'],
                                session=session,
                                api_name='api')
    except Exception as e:
        error = e.get_HTTP()
        response_code = error.code
    assert 404 == response_code
Пример #12
0
 def test_delete(self):
     """Test CRUD delete."""
     object_ = gen_dummy_object(random.choice(self.doc_collection_classes),
                                self.doc)
     id_ = "4"
     insert_response = crud.insert(object_=object_,
                                   id_=id_,
                                   session=self.session)
     delete_response = crud.delete(id_=id_,
                                   type_=object_["@type"],
                                   session=self.session)
     assert isinstance(insert_response, str)
     response_code = None
     try:
         get_response = crud.get(id_=id_,
                                 type_=object_["@type"],
                                 session=self.session,
                                 api_name="api")
     except Exception as e:
         response_code, message = e.get_HTTP()
     assert 404 == response_code