Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update AIPScan database with deleted SS AIPs, #199 #200

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions AIPscan/Aggregator/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@
for package_obj in package_list.get(OBJECTS, []):
package = process_package_object(package_obj)
packages.append(package)

if package.is_deleted():
delete_aip(package.uuid)

Check warning on line 119 in AIPscan/Aggregator/tasks.py

View check run for this annotation

Codecov / codecov/patch

AIPscan/Aggregator/tasks.py#L119

Added line #L119 was not covered by tests

if not package.is_aip():
continue
start_mets_task(
Expand All @@ -131,6 +135,16 @@
return packages


def delete_aip(uuid):
logger.warning("Package deleted from SS: '%s'", uuid)

deleted_aip = AIP.query.filter_by(uuid=uuid).first()

if deleted_aip is not None:
logger.warning("Deleting AIP: %s", uuid)
database_helpers.delete_aip_object(deleted_aip)


@celery.task(bind=True)
def workflow_coordinator(
self, api_url, timestamp, storage_service_id, fetch_job_id, packages_directory
Expand Down
17 changes: 17 additions & 0 deletions AIPscan/Aggregator/tests/test_tasks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import logging
import os
import uuid
from datetime import datetime
from io import StringIO

Expand All @@ -9,6 +10,7 @@
from AIPscan import test_helpers
from AIPscan.Aggregator.tasks import (
TaskError,
delete_aip,
get_mets,
make_request,
parse_packages_and_load_mets,
Expand Down Expand Up @@ -208,3 +210,18 @@ def test_parse_packages_and_load_mets(app_instance, tmpdir, mocker):
parse_packages_and_load_mets(json_file_path, {}, str(datetime.now()), 1, 1, 1)

delete_package_json.assert_called_with(json_file_path)


def test_delete_aip(app_instance):
"""Test that SS deleted AIPs gets deleted in aipscan.db."""
PACKAGE_UUID = str(uuid.uuid4())

test_helpers.create_test_aip(uuid=PACKAGE_UUID)

deleted_aip = AIP.query.filter_by(uuid=PACKAGE_UUID).first()
assert deleted_aip is not None

delete_aip(PACKAGE_UUID)

deleted_aip = AIP.query.filter_by(uuid=PACKAGE_UUID).first()
assert deleted_aip is None
Loading