diff --git a/app/aws/s3.py b/app/aws/s3.py index 7886b8f3a..189c6b4a9 100644 --- a/app/aws/s3.py +++ b/app/aws/s3.py @@ -104,15 +104,20 @@ def download_from_s3( region_name=region, ) s3 = session.client("s3", config=AWS_CLIENT_CONFIG) + result = None try: - s3.download_file(bucket_name, s3_key, local_filename) + result = s3.download_file(bucket_name, s3_key, local_filename) print(f"File downloaded successfully to {local_filename}") - except botocore.exceptions.NoCredentialsError: + except botocore.exceptions.NoCredentialsError as nce: print("Credentials not found") - except botocore.exceptions.PartialCredentialsError: + raise Exception(nce) + except botocore.exceptions.PartialCredentialsError as pce: print("Incomplete credentials provided") + raise Exception(pce) except Exception as e: print(f"An error occurred {e}") + raise Exception(e) + return result def get_s3_object(bucket_name, file_location, access_key, secret_key, region): diff --git a/tests/app/test_commands.py b/tests/app/test_commands.py index 7b4885660..817f2e4bf 100644 --- a/tests/app/test_commands.py +++ b/tests/app/test_commands.py @@ -428,9 +428,7 @@ def test_promote_user_to_platform_admin( assert user.platform_admin is True -def test_download_csv_file_by_name( - notify_api, sample_platform_admin -): +def test_download_csv_file_by_name(notify_api, sample_platform_admin): assert sample_platform_admin.platform_admin is True result = notify_api.test_cli_runner().invoke( @@ -440,8 +438,9 @@ def test_download_csv_file_by_name( ], ) - print(result) - assert result == '404' + # if we get a 404, it means that the file is not in s3 (of course) + # but we are making the call to s3, etc. so that part is working + assert "404" in str(result) def test_promote_user_to_platform_admin_no_result_found(