diff --git a/.github/workflows/daily-csv-upload.yaml b/.github/workflows/daily-csv-upload.yaml index 558b9e0b5..245f19fcc 100644 --- a/.github/workflows/daily-csv-upload.yaml +++ b/.github/workflows/daily-csv-upload.yaml @@ -32,7 +32,7 @@ on: jobs: variables: outputs: - environment: ${{ steps.var.outputs.environment }} + environment: 'za' runs-on: "ubuntu-latest" steps: - name: Setting global variables diff --git a/src/registrar/tests/test_reports.py b/src/registrar/tests/test_reports.py index c0c520955..b3cbb72fd 100644 --- a/src/registrar/tests/test_reports.py +++ b/src/registrar/tests/test_reports.py @@ -7,7 +7,7 @@ from registrar.models.user import User from django.contrib.auth import get_user_model from registrar.utility.csv_export import export_domains_to_writer from django.core.management import call_command -from unittest.mock import call, mock_open, patch +from unittest.mock import MagicMock, call, mock_open, patch from api.views import get_current_federal, get_current_full import boto3_mocking # type: ignore @@ -73,7 +73,7 @@ class CsvReportsTest(TestCase): call_command("generate_current_federal_report") error = err.exception self.assertEqual(str(error), "Could not find newly created file at 'migrationdata/current-federal.csv'") - + def test_create_failed_full(self): """Ensures that we return an error when we cannot find our created file""" fake_open = mock_open() @@ -119,15 +119,22 @@ class CsvReportsTest(TestCase): # Now you can make assertions about how you expect 'file' to be used. content.write.assert_has_calls(expected_file_content) + @boto3_mocking.patching def test_not_found_full_report(self): """Ensures that we get a not found when the report doesn't exist""" - response = self.client.get("/api/v1/get-report/current-full") + mock_client = MagicMock() + mock_client_instance = mock_client.return_value + with boto3_mocking.clients.handler_for("s3", mock_client): + response = self.client.get("/api/v1/get-report/current-full") + call_args = mock_client_instance + args, kwargs = call_args # Check that the response has status code 404 self.assertEqual(response.status_code, 404) # Check that the response body contains "File not found" self.assertEqual(response.content.decode(), "File not found") + @boto3_mocking.patching def test_not_found_federal_report(self): """Ensures that we get a not found when the report doesn't exist""" response = self.client.get("/api/v1/get-report/current-federal") @@ -140,6 +147,8 @@ class CsvReportsTest(TestCase): @boto3_mocking.patching def test_load_federal_report(self): """Tests the current-federal api link""" + if not boto3_mocking.patching_engaged(): + raise Exception("test123") request = self.factory.get("/fake-path") response = get_current_federal(request, file_path="registrar/tests/data/fake_current_federal.csv") # Check that the response has status code 200 diff --git a/src/registrar/utility/s3_bucket.py b/src/registrar/utility/s3_bucket.py index 9e7f0da31..329a68c40 100644 --- a/src/registrar/utility/s3_bucket.py +++ b/src/registrar/utility/s3_bucket.py @@ -23,20 +23,12 @@ class S3ClientHelper: config=settings.BOTO_CONFIG, ) except Exception as exc: - raise S3ClientError("Could not access the S3 client.") from exc + raise S3ClientError("Could not access the S3 client") from exc def get_bucket_name(self): """Gets the name of our S3 Bucket""" return settings.AWS_S3_BUCKET_NAME - def list_objects(self): - """Returns a list of the top 1000 objects within our S3 instance""" - try: - response = self.boto_client.list_objects_v2(Bucket=self.get_bucket_name()) - except Exception as exc: - raise S3ClientError("Couldn't list objects") from exc - return response - def upload_file(self, file_path, file_name): """Uploads a file to our S3 instance""" try: @@ -53,6 +45,7 @@ class S3ClientHelper: raise S3ClientError("File was not found") from exc except Exception as exc: raise S3ClientError("Couldn't get file, an unspecified error occured") from exc + file_content = response["Body"].read() if decode_to_utf: return file_content.decode("utf-8")