def test_delete_multiple_id(drone_doc_parsed_classes, drone_doc, session): """Test CRUD insert when multiple ID's are given """ objects = list() ids = '{},{}'.format(str(uuid.uuid4()), str(uuid.uuid4())) random_class = random.choice(drone_doc_parsed_classes) for index in range(len(ids.split(','))): object = gen_dummy_object(random_class, drone_doc) objects.append(object) insert_response = crud.insert_multiple(objects_=objects, session=session, id_=ids) delete_response = crud.delete_multiple(id_=ids, type_=random_class, session=session) response_code = None id_list = ids.split(',') try: for index in range(len(id_list)): get_response = crud.get(id_=id_list[index], type_=objects[index]['@type'], session=session, api_name='api') except Exception as e: error = e.get_HTTP() response_code = error.code assert 404 == response_code
def test_delete_ids(self): objects = list() ids = "1,2,3" for index in range(len(ids.split(','))): object = gen_dummy_object( random.choice(self.doc_collection_classes), self.doc) objects.append(object) insert_response = crud.insert_multiple(objects_=objects, session=self.session, id_=ids) delete_response = crud.delete_multiple(id_=ids, type_=objects[0]["@type"], session=self.session) response_code = None id_list = ids.split(',') try: for index in range(len(id_list)): get_response = crud.get(id_=id_list[index], type_=objects[index]["@type"], session=self.session, api_name="api") except Exception as e: response_code, message = e.get_HTTP() assert 404 == response_code
def put(self, path, int_list="") -> Response: """ To insert multiple objects into the database :param path: endpoint :param int_list: Optional String containing ',' separated ID's :return: """ auth_response = check_authentication_response() if isinstance(auth_response, Response): return auth_response endpoint_ = checkEndpoint("PUT", path) if endpoint_['method']: # If endpoint and PUT method is supported in the API object_ = json.loads(request.data.decode('utf-8')) object_ = object_["data"] if path in get_doc().collections: # If collection name in document's collections collection = get_doc().collections[path]["collection"] # title of HydraClass object corresponding to collection obj_type = collection.class_.title if validObjectList(object_): type_result = type_match(object_, obj_type) # If Item in request's JSON is a valid object # ie. @type is one of the keys in object_ if type_result: # If the right Item type is being added to the # collection try: # Insert object and return location in Header object_id = crud.insert_multiple( objects_=object_, session=get_session(), id_=int_list) headers_ = [{ "Location": "{}/{}/{}".format(get_hydrus_server_url(), get_api_name(), path, object_id) }] response = { "message": "Object with ID {} successfully added".format( object_id) } return set_response_headers(jsonify(response), headers=headers_, status_code=201) except (ClassNotFound, InstanceExists, PropertyNotFound) as e: status_code, message = e.get_HTTP() return set_response_headers( jsonify(message), status_code=status_code) return set_response_headers(jsonify({400: "Data is not valid"}), status_code=400) abort(endpoint_['status'])
def items_put_response(path: str, int_list="") -> Response: """ Handles PUT operation to insert multiple items. :param path: Path for Item Collection :type path: str :param int_list: Optional String containing ',' separated ID's :type int_list: List :return: Appropriate response for the PUT operation on multiple items. :rtype: Response """ object_ = json.loads(request.data.decode('utf-8')) object_ = object_["data"] _, parsed_classes = get_collections_and_parsed_classes() if path in parsed_classes: class_path = path obj_type = getType(path, "PUT") incomplete_objects = [] for obj in object_: if not check_required_props(class_path, obj): incomplete_objects.append(obj) object_.remove(obj) link_props_list, link_type_check = get_link_props_for_multiple_objects(class_path, object_) if validObjectList(object_) and link_type_check: type_result = type_match(object_, obj_type) # If Item in request's JSON is a valid object # ie. @type is one of the keys in object_ if type_result: # If the right Item type is being added to the # collection try: # Insert object and return location in Header object_id = crud.insert_multiple( objects_=object_, session=get_session(), id_=int_list) headers_ = [{"Location": f"{get_hydrus_server_url()}" f"{get_api_name()}/{path}/{object_id}"}] if len(incomplete_objects) > 0: status = HydraStatus(code=202, title="Object(s) missing required property") response = status.generate() response["objects"] = incomplete_objects return set_response_headers( jsonify(response), headers=headers_, status_code=status.code) else: status_description = f"Objects with ID {object_id} successfully added" status = HydraStatus(code=201, title="Objects successfully added", desc=status_description) return set_response_headers( jsonify(status.generate()), headers=headers_, status_code=status.code) except (ClassNotFound, InstanceExists, PropertyNotFound) as e: error = e.get_HTTP() return error_response(error) error = HydraError(code=400, title="Data is not valid") return error_response(error)
def test_insert_ids(self): """Test CRUD insert when multiple ID's are given """ objects = list() ids = "{},{}".format(str(uuid.uuid4()), str(uuid.uuid4())) ids_list = ids.split(',') for index in range(len(ids_list)): object = gen_dummy_object( random.choice(self.doc_collection_classes), self.doc) objects.append(object) insert_response = crud.insert_multiple(objects_=objects, session=self.session, id_=ids) for id_ in ids_list: assert id_ in insert_response
def test_insert_multiple_id(drone_doc_parsed_classes, drone_doc, session): """Test CRUD insert when multiple ID's are given """ objects = list() ids = '{},{}'.format(str(uuid.uuid4()), str(uuid.uuid4())) ids_list = ids.split(',') for index in range(len(ids_list)): object = gen_dummy_object(random.choice(drone_doc_parsed_classes), drone_doc) objects.append(object) insert_response = crud.insert_multiple(objects_=objects, session=session, id_=ids) for id_ in ids_list: assert id_ in insert_response
def test_insert_ids(self): """Test CRUD insert when multiple ID's are given """ objects = list() ids = "1,2,3" for index in range(len(ids.split(','))): object = gen_dummy_object("dummyClass", self.doc) objects.append(object) response_code = None try: insert_response = crud.insert_multiple( objects_=objects, session=self.session, id_=ids) except Exception as e: response_code, message = e.get_HTTP() assert 400 == response_code