Skip to content

Commit

Permalink
[Issue #3973] Guard against null mime type / description / file size (#…
Browse files Browse the repository at this point in the history
…3991)

## Summary
Fixes #3973

### Time to review: 5 mins

## Changes proposed
Quick follow on PR to check more fields.

## Context for reviewers
Test failed for other missing fields we want to guard against.
  • Loading branch information
mikehgrantsgov authored Feb 21, 2025
1 parent cd75f0d commit 09a36c1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ def transform_opportunity_attachment(
if source_attachment.mime_type is None:
raise ValueError("Opportunity attachment does not have a mime type, cannot process.")

# We should always have a file description. Raise an error if we don't
if source_attachment.file_desc is None:
raise ValueError("Opportunity attachment does not have a file description, cannot process.")

# We should always have a file size. Raise an error if we don't
if source_attachment.file_lob_size is None:
raise ValueError("Opportunity attachment does not have a file size, cannot process.")

file_location = attachment_util.get_s3_attachment_path(
file_name, source_attachment.syn_att_id, opportunity, s3_config
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,44 @@ def test_transform_opportunity_attachment_null_mime_type(
)

assert insert.transformed_at is None

def test_transform_opportunity_attachment_null_file_description(
self, db_session, transform_opportunity_attachment, s3_config
):
opportunity = f.OpportunityFactory.create(opportunity_attachments=[])
insert = setup_opportunity_attachment(
create_existing=False,
opportunity=opportunity,
config=s3_config,
source_values={"file_desc": None},
)

with pytest.raises(
ValueError,
match="Opportunity attachment does not have a file description, cannot process",
):
transform_opportunity_attachment.process_opportunity_attachment(
insert, None, opportunity
)

assert insert.transformed_at is None

def test_transform_opportunity_attachment_null_file_size(
self, db_session, transform_opportunity_attachment, s3_config
):
opportunity = f.OpportunityFactory.create(opportunity_attachments=[])
insert = setup_opportunity_attachment(
create_existing=False,
opportunity=opportunity,
config=s3_config,
source_values={"file_lob_size": None},
)

with pytest.raises(
ValueError, match="Opportunity attachment does not have a file size, cannot process"
):
transform_opportunity_attachment.process_opportunity_attachment(
insert, None, opportunity
)

assert insert.transformed_at is None

0 comments on commit 09a36c1

Please sign in to comment.