Skip to content

Commit

Permalink
only download and store one package at a time, fixes #44
Browse files Browse the repository at this point in the history
  • Loading branch information
helrond committed Sep 13, 2019
1 parent ee1a6c4 commit 354ee25
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
10 changes: 9 additions & 1 deletion storer/routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class CleanupError(Exception): pass


class DownloadRoutine:
"""Downloads a package from Archivematica."""

def __init__(self, dirs):
self.am_client = ArchivematicaClient(settings.ARCHIVEMATICA['username'],
settings.ARCHIVEMATICA['api_key'],
Expand Down Expand Up @@ -43,8 +45,8 @@ def run(self):
data=package,
process_status=Package.DOWNLOADED
)

package_ids.append(self.uuid)
break
return ("All packages downloaded.", package_ids)

def download_package(self, package_json):
Expand All @@ -60,6 +62,10 @@ def download_package(self, package_json):


class StoreRoutine:
"""
Uploads the contents of a package to Fedora.
AIPS are uploaded as single 7z files. DIPs are extracted and each file is uploaded.
"""
def __init__(self, url, dirs):
self.url = url
self.fedora_client = FedoraClient(root=settings.FEDORA['baseurl'],
Expand Down Expand Up @@ -104,6 +110,8 @@ def run(self):

package_ids.append(self.uuid)

break

try:
self.clean_up()
return ("All packages stored.", package_ids)
Expand Down
4 changes: 3 additions & 1 deletion storer/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ def store_views(self):
request = self.factory.post(reverse('download-packages'), {"test": True})
response = DownloadView.as_view()(request)
self.assertEqual(response.status_code, 200, "Wrong HTTP code")
self.assertEqual(response.data['count'], 1, "Wrong number of packages downloaded")
with storer_vcr.use_cassette('store.yml'):
request = self.factory.post(reverse('store-packages'), {"test": True})
response = StoreView.as_view()(request)
self.assertEqual(response.status_code, 200, "Wrong HTTP code")
self.assertEqual(response.data['count'], 1, "Wrong number of packages stored")
with storer_vcr.use_cassette('cleanup.yml'):
request = self.factory.post(reverse('request-cleanup'), {"test": True})
request = self.factory.post("{}?post_service_url=http://fornax-web:8003/cleanup/".format(reverse('request-cleanup')), {"test": True})
response = CleanupRequestView.as_view()(request)
self.assertEqual(response.status_code, 200, "Wrong HTTP code")

Expand Down
1 change: 1 addition & 0 deletions storer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class CleanupRequestView(APIView):
def post(self, request):
url = request.GET.get('post_service_url')
url = (urllib.parse.unquote(url) if url else '')
print(url)
try:
response = CleanupRequester(url).run()
return Response(tuple_to_dict(response), status=200)
Expand Down

0 comments on commit 354ee25

Please sign in to comment.