def test_del(stub, id) -> None: try: task = stub.delTask(wrappers_pb2.UInt64Value(value=id)) logging.debug(f"dekl Task {pformat(task)}") except grpc.RpcError as e: print(e.details())
def destructive_editTask( self, request, context ) -> task_pb2.Task: # destructive_editTask , deletes the task and creates a new task with the edits. self.delTask(wrappers_pb2.UInt64Value(value=request.id), context=context) # delet item return self.addTask( wrappers_pb2.StringValue(value=request.description), context=context) # add new item and return
def destructive_editTask(self, request: task_pb2.Task, context): logging.debug(f"editTask parameters {pformat(request)}") # check whether the key is exist and description length if request.id in self.tasks.keys() and len( request.description) <= 1024: #delete task self.delTask(wrappers_pb2.UInt64Value(value=request.id), context) # adding agin return (self.addTask( wrappers_pb2.StringValue(value=request.description), context)) context.set_code(grpc.StatusCode.NOT_FOUND) context.set_details( f"There is no Task with Id : {pformat(request.id)} or Description is too long" ) return task_pb2.Task()
def test_del(stub, tasks: Mapping[int, str]) -> None: for id, desc in tasks.items(): task = stub.delTask(wrappers_pb2.UInt64Value(value=id)) logging.debug(f"Deleted Task {pformat(task)}") assert desc == task.description