Skip to content

Commit

Permalink
Update AIPScan database with deleted SS AIPs, #199
Browse files Browse the repository at this point in the history
  • Loading branch information
melaniekung committed Sep 5, 2023
1 parent c45b917 commit 8f62b55
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
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 @@ def parse_packages_and_load_mets(
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 @@ def parse_packages_and_load_mets(
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
16 changes: 16 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 @@ -12,6 +13,7 @@
get_mets,
make_request,
parse_packages_and_load_mets,
delete_aip,
)
from AIPscan.Aggregator.tests import (
INVALID_JSON,
Expand Down Expand Up @@ -208,3 +210,17 @@ 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

0 comments on commit 8f62b55

Please sign in to comment.