Skip to content

Commit

Permalink
3718 address historical audits with missing planned actions (#3791)
Browse files Browse the repository at this point in the history
* #3718 Updated logic to replace missing cap text with gsa_migration keyword

* #3718 Added test cases

* #3718 code improvement

* #3718 Added logic to replace missing text of finding

* Linting required after adding logic for #3804

* Code improvement

* Fixed import
  • Loading branch information
sambodeme authored May 8, 2024
1 parent 694b8b7 commit 29cb534
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.test import SimpleTestCase

from .workbooklib.corrective_action_plan import (
xform_add_placeholder_for_missing_action_planned_text,
xform_add_placeholder_for_missing_references,
)

Expand Down Expand Up @@ -59,3 +60,37 @@ def test_no_placeholder_addition_when_all_references_present(self):
) # Expecting two items in findings_texts
self.assertEqual(findings_texts[0].FINDINGREFNUMS, "ref1")
self.assertEqual(findings_texts[1].FINDINGREFNUMS, "ref2")


class TestXformAddPlaceholderForMissingActionPlannedText(SimpleTestCase):
class CapText:
def __init__(self, FINDINGREFNUMS=None, TEXT=None):
self.FINDINGREFNUMS = FINDINGREFNUMS
self.TEXT = TEXT

def test_add_placeholder_to_empty_text(self):
captexts = [self.CapText(FINDINGREFNUMS="123", TEXT="")]
expected_text = settings.GSA_MIGRATION
xform_add_placeholder_for_missing_action_planned_text(captexts)
self.assertEqual(
captexts[0].TEXT,
expected_text,
"The TEXT field should have the placeholder text.",
)

def test_no_placeholder_if_text_present(self):
captexts = [self.CapText(FINDINGREFNUMS="123", TEXT="Existing text")]
expected_text = "Existing text"
xform_add_placeholder_for_missing_action_planned_text(captexts)
self.assertEqual(
captexts[0].TEXT, expected_text, "The TEXT field should not be modified."
)

def test_empty_finding_refnums_no_change(self):
captexts = [self.CapText(FINDINGREFNUMS="", TEXT="")]
xform_add_placeholder_for_missing_action_planned_text(captexts)
self.assertEqual(
captexts[0].TEXT,
"",
"The TEXT field should remain empty if FINDINGREFNUMS is empty.",
)
42 changes: 41 additions & 1 deletion backend/census_historical_migration/test_findings_xforms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from django.conf import settings
from django.test import SimpleTestCase

from .workbooklib.findings_text import xform_add_placeholder_for_missing_references
from .workbooklib.findings_text import (
xform_add_placeholder_for_missing_text_of_finding,
xform_add_placeholder_for_missing_references,
)

from .workbooklib.findings import (
xform_sort_compliance_requirement,
Expand Down Expand Up @@ -102,6 +105,43 @@ def test_no_placeholder_addition_when_all_references_present(self):
self.assertEqual(findings_texts[1].FINDINGREFNUMS, "ref2")


class TestXformAddPlaceholderForMissingTextOfFinding(SimpleTestCase):

class FindingsText:
def __init__(self, FINDINGREFNUMS=None, TEXT=None):
self.FINDINGREFNUMS = FINDINGREFNUMS
self.TEXT = TEXT

def test_add_placeholder_to_empty_text(self):
findings_texts = [self.FindingsText(FINDINGREFNUMS="123", TEXT="")]
expected_text = settings.GSA_MIGRATION
xform_add_placeholder_for_missing_text_of_finding(findings_texts)
self.assertEqual(
findings_texts[0].TEXT,
expected_text,
"The TEXT field should have the placeholder text.",
)

def test_no_placeholder_if_text_present(self):
findings_texts = [self.FindingsText(FINDINGREFNUMS="123", TEXT="Existing text")]
expected_text = "Existing text"
xform_add_placeholder_for_missing_text_of_finding(findings_texts)
self.assertEqual(
findings_texts[0].TEXT,
expected_text,
"The TEXT field should not be modified.",
)

def test_empty_finding_refnums_no_change(self):
findings_texts = [self.FindingsText(FINDINGREFNUMS="", TEXT="")]
xform_add_placeholder_for_missing_text_of_finding(findings_texts)
self.assertEqual(
findings_texts[0].TEXT,
"",
"The TEXT field should remain empty if FINDINGREFNUMS is empty.",
)


class TestXformMissingComplianceRequirement(SimpleTestCase):
class Findings:
def __init__(self, type_requirement):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from django.conf import settings

from ..transforms.xform_string_to_string import string_to_string

from ..workbooklib.findings import get_findings
from ..transforms.xform_retrieve_uei import xform_retrieve_uei
from ..transforms.xform_uppercase_y_or_n import uppercase_y_or_n
Expand Down Expand Up @@ -71,6 +73,17 @@ def xform_add_placeholder_for_missing_references(findings, captexts):
return captexts


def xform_add_placeholder_for_missing_action_planned_text(captexts):
"""
Add placeholder for missing action planned texts.
"""
for captext in captexts:
if string_to_string(captext.FINDINGREFNUMS) and not string_to_string(
captext.TEXT
):
captext.TEXT = settings.GSA_MIGRATION


def generate_corrective_action_plan(audit_header, outfile):
"""
Generates a corrective action plan workbook for a given audit header.
Expand All @@ -87,6 +100,7 @@ def generate_corrective_action_plan(audit_header, outfile):
captexts = _get_cap_text(audit_header.DBKEY, audit_header.AUDITYEAR)
findings = get_findings(audit_header.DBKEY, audit_header.AUDITYEAR)
captexts = xform_add_placeholder_for_missing_references(findings, captexts)
xform_add_placeholder_for_missing_action_planned_text(captexts)
xform_sanitize_for_excel(captexts)
map_simple_columns(wb, mappings, captexts)
wb.save(outfile)
Expand Down
16 changes: 16 additions & 0 deletions backend/census_historical_migration/workbooklib/findings_text.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from django.conf import settings

from ..transforms.xform_string_to_string import (
string_to_string,
)
from ..workbooklib.findings import get_findings
from ..transforms.xform_retrieve_uei import xform_retrieve_uei
from ..transforms.xform_uppercase_y_or_n import uppercase_y_or_n
Expand Down Expand Up @@ -68,6 +72,17 @@ def xform_add_placeholder_for_missing_references(findings, findings_texts):
return findings_texts


def xform_add_placeholder_for_missing_text_of_finding(findings_texts):
"""
Add placeholder text for missing findings_text.
"""
for findings_text in findings_texts:
if string_to_string(findings_text.FINDINGREFNUMS) and not string_to_string(
findings_text.TEXT
):
findings_text.TEXT = settings.GSA_MIGRATION


def generate_findings_text(audit_header, outfile):
"""
Generates a findings text workbook for a given audit header.
Expand All @@ -84,6 +99,7 @@ def generate_findings_text(audit_header, outfile):
findings_texts = xform_add_placeholder_for_missing_references(
findings, findings_texts
)
xform_add_placeholder_for_missing_text_of_finding(findings_texts)
xform_sanitize_for_excel(findings_texts)
map_simple_columns(wb, mappings, findings_texts)

Expand Down

0 comments on commit 29cb534

Please sign in to comment.