-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
66 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,21 @@ | ||
|
||
import logging | ||
import os | ||
import sys | ||
|
||
import boto3 | ||
def get_bucket(): | ||
session = boto3.Session() | ||
S3 = session.resource('s3') | ||
return S3.Bucket("wellcomecollection-workflow-stage-upload") | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def upload(s3, zipfile_path, target_bucket_name="wellcomecollection-archivematica-staging-transfer-source"): | ||
logger.info(f"uploading {zipfile_path} to {target_bucket_name}") | ||
get_target_bucket(s3, target_bucket_name).upload_file(zipfile_path, f"born-digital-accessions/{os.path.basename(zipfile_path)}") | ||
|
||
|
||
def get_target_bucket(s3, target_bucket): | ||
return s3.Bucket(target_bucket) | ||
|
||
|
||
if __name__ == "__main__": | ||
upload( boto3.Session(profile_name=os.environ["AWS_TARGET_PROFILE"]).resource('s3'), sys.argv[1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import pytest | ||
import pyfakefs | ||
import boto3 | ||
from transferrer.upload import upload | ||
from transferrer.upload import upload | ||
|
||
|
||
def test_raises_on_missing_zip(moto_s3, target_bucket, fs): | ||
with pytest.raises(FileNotFoundError): | ||
upload(moto_s3, "missing.zip") | ||
|
||
|
||
def test_uploads_to_accessions_folder_in_bucket(moto_s3, target_bucket, fs): | ||
fs.create_file("present.zip") | ||
upload(moto_s3, "present.zip") | ||
assert [obj.key for obj in target_bucket.objects.all()] == ["born-digital-accessions/present.zip"] | ||
|
||
|