def purge_data_package(publisher, package): """ DPR data package hard delete operation. This API is responsible for deletion of data package --- tags: - package parameters: - in: path name: publisher type: string required: true description: publisher name - in: path name: package type: string required: true description: package name - in: header name: Authorization type: string required: true description: > Jwt token in format of "bearer {token}. The token can be generated from /api/auth/token" responses: 500: description: Internal Server Error 200: description: Success Message schema: id: put_package_success properties: status: type: string default: OK """ try: bitstore = BitStore(publisher=publisher, package=package) status_acl = bitstore.delete_data_package() status_db = Package.delete_data_package(publisher, package) if status_acl and status_db: return jsonify({"status": "OK"}), 200 if not status_acl: raise Exception('Failed to delete from s3') if not status_db: raise Exception('Failed to delete from db') except Exception as e: app.logger.error(e) return handle_error('GENERIC_ERROR', e.message, 500)
def test_delete_data_package(self): with self.app.app_context(): bit_store = BitStore('test_pub', 'test_package') s3 = boto3.client('s3') bucket_name = self.app.config['S3_BUCKET_NAME'] s3.create_bucket(Bucket=bucket_name) read_me_key = bit_store.build_s3_key('test.md') data_key = bit_store.build_s3_key('data.csv') metadata_key = bit_store.build_s3_key('datapackage.json') s3.put_object(Bucket=bucket_name, Key=read_me_key, Body='readme') s3.put_object(Bucket=bucket_name, Key=data_key, Body='data') s3.put_object(Bucket=bucket_name, Key=metadata_key, Body='metedata') status = bit_store.delete_data_package() read_me_res = s3.list_objects(Bucket=bucket_name, Prefix=read_me_key) self.assertTrue('Contents' not in read_me_res) data_res = s3.list_objects(Bucket=bucket_name, Prefix=data_key) self.assertTrue('Contents' not in data_res) self.assertTrue(status)