Skip to content

Commit

Permalink
Merge pull request #3782 from GSA-TTS/main
Browse files Browse the repository at this point in the history
  • Loading branch information
jadudm authored May 1, 2024
2 parents d5e6405 + 6123204 commit a724b1a
Show file tree
Hide file tree
Showing 3 changed files with 319 additions and 0 deletions.
29 changes: 29 additions & 0 deletions backend/census_historical_migration/test_federal_awards_xforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
xform_populate_default_passthrough_amount,
xform_populate_default_passthrough_names_ids,
xform_replace_invalid_extension,
xform_is_passthrough_award,
is_valid_extension,
)

Expand Down Expand Up @@ -306,6 +307,34 @@ def test_passthrough_award_Y_empty_amount(self):
self.assertEqual(xform_populate_default_passthrough_amount(audits), expected)


class TestXformIsPassthroughAward(SimpleTestCase):
class MockAudit:
def __init__(self, PASSTHROUGHAWARD, PASSTHROUGHAMOUNT):
self.PASSTHROUGHAWARD = PASSTHROUGHAWARD
self.PASSTHROUGHAMOUNT = PASSTHROUGHAMOUNT

def test_passthrough_award_Y(self):
"""Test the function with a valid passthrough award."""
audits = [self.MockAudit(PASSTHROUGHAWARD="Y", PASSTHROUGHAMOUNT="0")]
expected = "Y"
xform_is_passthrough_award(audits)
self.assertEqual(audits[0].PASSTHROUGHAWARD, expected)

def test_passthrough_award_empty_with_amount(self):
"""Test the function with an empty passthrough award and truthy amount."""
audits = [self.MockAudit(PASSTHROUGHAWARD="", PASSTHROUGHAMOUNT="42")]
expected = "Y"
xform_is_passthrough_award(audits)
self.assertEqual(audits[0].PASSTHROUGHAWARD, expected)

def test_passthrough_award_empty_with_no_amount(self):
"""Test the function with an empty passthrough award and falsy amount."""
audits = [self.MockAudit(PASSTHROUGHAWARD="", PASSTHROUGHAMOUNT="0")]
expected = "N"
xform_is_passthrough_award(audits)
self.assertEqual(audits[0].PASSTHROUGHAWARD, expected)


class TestCFDAFunctions(SimpleTestCase):
def test_is_valid_prefix(self):
"""Test the function with valid and invalid prefixes."""
Expand Down
259 changes: 259 additions & 0 deletions backend/census_historical_migration/test_notes_to_sefa_xforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .workbooklib.notes_to_sefa import (
xform_is_minimis_rate_used,
xform_missing_note_title_and_content,
xform_missing_notes_records_v2,
)


Expand Down Expand Up @@ -154,22 +155,26 @@ def __init__(
self,
TITLE,
CONTENT,
TYPE_ID,
):
self.TITLE = TITLE
self.CONTENT = CONTENT
self.TYPE_ID = TYPE_ID

def _mock_notes_no_title(self):
notes = []
notes.append(
self.MockNote(
TITLE="",
CONTENT="SUPPORTIVE HOUSING FOR THE ELDERLY (14.157) - Balances outstanding at the end of the audit period were 3356.",
TYPE_ID=3,
)
)
notes.append(
self.MockNote(
TITLE="",
CONTENT="MORTGAGE INSURANCE FOR THE PURCHASE OR REFINANCING OF EXISTING MULTIFAMILY HOUSING PROJECTS (14.155) - Balances outstanding at the end of the audit period were 4040.",
TYPE_ID=3,
)
)
return notes
Expand All @@ -180,12 +185,14 @@ def _mock_notes_no_content(self):
self.MockNote(
TITLE="Loan/loan guarantee outstanding balances",
CONTENT="",
TYPE_ID=3,
)
)
notes.append(
self.MockNote(
TITLE="Federally Funded Insured Mortgages and Capital Advances",
CONTENT="",
TYPE_ID=3,
)
)
return notes
Expand All @@ -196,12 +203,14 @@ def _mock_notes_with_title_content(self):
self.MockNote(
TITLE="Loan/loan guarantee outstanding balances",
CONTENT="SUPPORTIVE HOUSING FOR THE ELDERLY (14.157) - Balances outstanding at the end of the audit period were 4000.",
TYPE_ID=3,
)
)
notes.append(
self.MockNote(
TITLE="Federally Funded Insured Mortgages and Capital Advances",
CONTENT="MORTGAGE INSURANCE FOR THE PURCHASE OR REFINANCING OF EXISTING MULTIFAMILY HOUSING PROJECTS (14.155) - Balances outstanding at the end of the audit period were 5000.",
TYPE_ID=3,
)
)
return notes
Expand All @@ -226,3 +235,253 @@ def test_note_with_title_content(self):
for note in result:
self.assertNotIn(settings.GSA_MIGRATION, note.TITLE)
self.assertNotIn(settings.GSA_MIGRATION, note.CONTENT)


class TestXformMissingNotesRecordsV2(SimpleTestCase):
class MockAuditHeader:
def __init__(
self,
DBKEY,
AUDITYEAR,
):
self.DBKEY = DBKEY
self.AUDITYEAR = AUDITYEAR

class MockNote:
def __init__(
self,
TITLE,
CONTENT,
TYPE_ID,
DBKEY,
AUDITYEAR,
):
self.TITLE = TITLE
self.CONTENT = CONTENT
self.TYPE_ID = TYPE_ID
self.DBKEY = DBKEY
self.AUDITYEAR = AUDITYEAR

def _mock_notes_valid_year_policies_no_rate(self):
notes = []
notes.append(
self.MockNote(
TITLE="Significant Accounting Policies Used in Preparing the SEFA",
CONTENT="Expenditures reported on the Schedule are reported on the accrual basis of accounting. Such expenditures are recognized following the cost principles contained in the Uniform Guidance, wherein certain types of expenditures are not allowable or are limited as to reimbursement.",
TYPE_ID=1,
DBKEY="123456789",
AUDITYEAR="2022",
)
)
audit_header = self.MockAuditHeader(
DBKEY="123456789",
AUDITYEAR="2022",
)
return notes, audit_header

def _mock_notes_valid_year_rate_no_policies(self):
notes = []
notes.append(
self.MockNote(
TITLE="10% De Minimis Cost Rate",
CONTENT="The auditee did not elect to use the de minimis cost rate.",
TYPE_ID=2,
DBKEY="223456789",
AUDITYEAR="2021",
)
)
audit_header = self.MockAuditHeader(
DBKEY="223456789",
AUDITYEAR="2021",
)
return notes, audit_header

def _mock_notes_valid_year_no_rate_no_policies(self):
notes = []
audit_header = self.MockAuditHeader(
DBKEY="223456788",
AUDITYEAR="2020",
)
return notes, audit_header

def _mock_notes_valid_year_rate_policies(self):
notes = []
notes.append(
self.MockNote(
TITLE="10% De Minimis Cost Rate",
CONTENT="The auditee did not elect to use the de minimis cost rate.",
TYPE_ID=2,
DBKEY="123456788",
AUDITYEAR="2018",
)
)
notes.append(
self.MockNote(
TITLE="Significant Accounting Policies Used in Preparing the SEFA",
CONTENT="Expenditures reported on the Schedule are reported on the accrual basis of accounting. Such expenditures are recognized following the cost principles contained in the Uniform Guidance, wherein certain types of expenditures are not allowable or are limited as to reimbursement.",
TYPE_ID=1,
DBKEY="123456788",
AUDITYEAR="2018",
)
)
audit_header = self.MockAuditHeader(
DBKEY="123456788",
AUDITYEAR="2018",
)
return notes, audit_header

def _mock_notes_invalid_year_policies_no_rate(self):
notes = []
notes.append(
self.MockNote(
TITLE="Significant Accounting Policies Used in Preparing the SEFA",
CONTENT="Expenditures reported on the Schedule are reported on the accrual basis of accounting. Such expenditures are recognized following the cost principles contained in the Uniform Guidance, wherein certain types of expenditures are not allowable or are limited as to reimbursement.",
TYPE_ID=1,
DBKEY="124456788",
AUDITYEAR="2015",
)
)
audit_header = self.MockAuditHeader(
DBKEY="124456788",
AUDITYEAR="2015",
)
return notes, audit_header

def _mock_notes_invalid_year_rate_no_policies(self):
notes = []
notes.append(
self.MockNote(
TITLE="10% De Minimis Cost Rate",
CONTENT="The auditee did not elect to use the de minimis cost rate.",
TYPE_ID=2,
DBKEY="124456789",
AUDITYEAR="2014",
)
)
audit_header = self.MockAuditHeader(
DBKEY="124456789",
AUDITYEAR="2014",
)
return notes, audit_header

def _mock_notes_invalid_year_no_rate_no_policies(self):
notes = []
audit_header = self.MockAuditHeader(
DBKEY="134456788",
AUDITYEAR="2013",
)
return notes, audit_header

def _mock_notes_invalid_year_rate_policies(self):
notes = []
notes.append(
self.MockNote(
TITLE="10% De Minimis Cost Rate",
CONTENT="The auditee did not elect to use the de minimis cost rate.",
TYPE_ID=2,
DBKEY="124466788",
AUDITYEAR="1800",
)
)
notes.append(
self.MockNote(
TITLE="Significant Accounting Policies Used in Preparing the SEFA",
CONTENT="Expenditures reported on the Schedule are reported on the accrual basis of accounting. Such expenditures are recognized following the cost principles contained in the Uniform Guidance, wherein certain types of expenditures are not allowable or are limited as to reimbursement.",
TYPE_ID=1,
DBKEY="124466788",
AUDITYEAR="1800",
)
)
audit_header = self.MockAuditHeader(
DBKEY="124466788",
AUDITYEAR="1800",
)
return notes, audit_header

def test_xform_missing_notes_records_v2_with_valid_year_policies_no_rate(self):
notes, audit_header = self._mock_notes_valid_year_policies_no_rate()
policies_content = list(filter(lambda note: note.TYPE_ID == 1, notes))[
0
].CONTENT
rate_content = ""
result_policies_content, result_rate_content = xform_missing_notes_records_v2(
audit_header, policies_content, rate_content
)
self.assertEqual(policies_content, result_policies_content)
self.assertEqual(rate_content, result_rate_content)

def test_xform_missing_notes_records_v2_with_valid_year_rate_no_policies(self):
notes, audit_header = self._mock_notes_valid_year_rate_no_policies()
policies_content = ""
rate_content = list(filter(lambda note: note.TYPE_ID == 2, notes))[0].CONTENT
result_policies_content, result_rate_content = xform_missing_notes_records_v2(
audit_header, policies_content, rate_content
)
self.assertEqual(rate_content, result_rate_content)
self.assertEqual(policies_content, result_policies_content)

def test_xform_missing_notes_records_v2_with_valid_year_no_rate_no_policies(self):
notes, audit_header = self._mock_notes_valid_year_no_rate_no_policies()
policies_content = ""
rate_content = ""
result_policies_content, result_rate_content = xform_missing_notes_records_v2(
audit_header, policies_content, rate_content
)
self.assertEqual(settings.GSA_MIGRATION, result_policies_content)
self.assertEqual(settings.GSA_MIGRATION, result_rate_content)

def test_xform_missing_notes_records_v2_with_valid_year_rate_policies(self):
notes, audit_header = self._mock_notes_valid_year_rate_policies()
policies_content = list(filter(lambda note: note.TYPE_ID == 1, notes))[
0
].CONTENT
rate_content = list(filter(lambda note: note.TYPE_ID == 2, notes))[0].CONTENT
result_policies_content, result_rate_content = xform_missing_notes_records_v2(
audit_header, policies_content, rate_content
)
self.assertEqual(policies_content, result_policies_content)
self.assertEqual(rate_content, result_rate_content)

def test_xform_missing_notes_records_v2_with_invalid_year_policies_no_rate(self):
notes, audit_header = self._mock_notes_invalid_year_policies_no_rate()
policies_content = list(filter(lambda note: note.TYPE_ID == 1, notes))[
0
].CONTENT
rate_content = ""
result_policies_content, result_rate_content = xform_missing_notes_records_v2(
audit_header, policies_content, rate_content
)
self.assertEqual(policies_content, result_policies_content)
self.assertEqual(rate_content, result_rate_content)

def test_xform_missing_notes_records_v2_with_invalid_year_rate_no_policies(self):
notes, audit_header = self._mock_notes_invalid_year_rate_no_policies()
policies_content = ""
rate_content = list(filter(lambda note: note.TYPE_ID == 2, notes))[0].CONTENT
result_policies_content, result_rate_content = xform_missing_notes_records_v2(
audit_header, policies_content, rate_content
)
self.assertEqual(policies_content, result_policies_content)
self.assertEqual(rate_content, result_rate_content)

def test_xform_missing_notes_records_v2_with_invalid_year_no_rate_no_policies(self):
notes, audit_header = self._mock_notes_invalid_year_no_rate_no_policies()
policies_content = ""
rate_content = ""
result_policies_content, result_rate_content = xform_missing_notes_records_v2(
audit_header, policies_content, rate_content
)
self.assertEqual(policies_content, result_policies_content)
self.assertEqual(rate_content, result_rate_content)

def test_xform_missing_notes_records_v2_with_invalid_year_rate_policies(self):
notes, audit_header = self._mock_notes_invalid_year_rate_policies()
policies_content = list(filter(lambda note: note.TYPE_ID == 1, notes))[
0
].CONTENT
rate_content = list(filter(lambda note: note.TYPE_ID == 2, notes))[0].CONTENT
result_policies_content, result_rate_content = xform_missing_notes_records_v2(
audit_header, policies_content, rate_content
)
self.assertEqual(policies_content, result_policies_content)
self.assertEqual(rate_content, result_rate_content)
Loading

0 comments on commit a724b1a

Please sign in to comment.