mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-26 04:28:39 +02:00
Test
This commit is contained in:
parent
bb175bd3d4
commit
72ef5bb0b1
3 changed files with 15 additions and 13 deletions
2
.github/workflows/daily-csv-upload.yaml
vendored
2
.github/workflows/daily-csv-upload.yaml
vendored
|
@ -32,7 +32,7 @@ on:
|
|||
jobs:
|
||||
variables:
|
||||
outputs:
|
||||
environment: ${{ steps.var.outputs.environment }}
|
||||
environment: 'za'
|
||||
runs-on: "ubuntu-latest"
|
||||
steps:
|
||||
- name: Setting global variables
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -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"""
|
||||
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
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue