Skip to content

Commit

Permalink
Merge pull request #4230 from GSA-TTS/main
Browse files Browse the repository at this point in the history
  • Loading branch information
jadudm committed Aug 28, 2024
2 parents 9e28058 + 2a16a0d commit 55a177c
Show file tree
Hide file tree
Showing 67 changed files with 8,554 additions and 8,554 deletions.
80 changes: 40 additions & 40 deletions backend/audit/cross_validation/check_award_ref_declaration.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
from .errors import (
err_award_ref_not_declared,
)


def check_award_ref_declaration(sac_dict, *_args, **_kwargs):
"""
Check that the award references reported in the Federal Awards Audit Findings workbook
are present within the Federal Awards workbook.
"""

all_sections = sac_dict.get("sf_sac_sections", {})
federal_awards_section = all_sections.get("federal_awards") or {}
federal_awards = federal_awards_section.get("federal_awards", [])
findings_uniform_guidance_section = (
all_sections.get("findings_uniform_guidance") or {}
)
findings_uniform_guidance = findings_uniform_guidance_section.get(
"findings_uniform_guidance_entries", []
)

declared_award_refs = set()
reported_award_refs = set()
errors = []

for award in federal_awards:
award_ref = award.get("award_reference")
if award_ref:
declared_award_refs.add(award_ref)

for finding in findings_uniform_guidance:
award_ref = finding["program"]["award_reference"]
if award_ref:
reported_award_refs.add(award_ref)

difference = reported_award_refs.difference(declared_award_refs)
if difference:
errors.append({"error": err_award_ref_not_declared(list(difference))})

return errors
from .errors import (
err_award_ref_not_declared,
)


def check_award_ref_declaration(sac_dict, *_args, **_kwargs):
"""
Check that the award references reported in the Federal Awards Audit Findings workbook
are present within the Federal Awards workbook.
"""

all_sections = sac_dict.get("sf_sac_sections", {})
federal_awards_section = all_sections.get("federal_awards") or {}
federal_awards = federal_awards_section.get("federal_awards", [])
findings_uniform_guidance_section = (
all_sections.get("findings_uniform_guidance") or {}
)
findings_uniform_guidance = findings_uniform_guidance_section.get(
"findings_uniform_guidance_entries", []
)

declared_award_refs = set()
reported_award_refs = set()
errors = []

for award in federal_awards:
award_ref = award.get("award_reference")
if award_ref:
declared_award_refs.add(award_ref)

for finding in findings_uniform_guidance:
award_ref = finding["program"]["award_reference"]
if award_ref:
reported_award_refs.add(award_ref)

difference = reported_award_refs.difference(declared_award_refs)
if difference:
errors.append({"error": err_award_ref_not_declared(list(difference))})

return errors
74 changes: 37 additions & 37 deletions backend/audit/cross_validation/check_award_ref_existence.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
from audit.fixtures.excel import (
FEDERAL_AWARDS_TEMPLATE_DEFINITION,
)
from .errors import (
err_missing_award_reference,
)
from django.conf import settings
import json

TEMPLATE_DEFINITION_PATH = (
settings.XLSX_TEMPLATE_JSON_DIR / FEDERAL_AWARDS_TEMPLATE_DEFINITION
)
FEDERAL_AWARDS_TEMPLATE = json.loads(
TEMPLATE_DEFINITION_PATH.read_text(encoding="utf-8")
)


def check_award_ref_existence(sac_dict, *_args, **_kwargs):
"""
Check that all awards have a reference code.
"""
first_row = FEDERAL_AWARDS_TEMPLATE["title_row"]
all_sections = sac_dict.get("sf_sac_sections", {})
federal_awards_section = all_sections.get("federal_awards") or {}
federal_awards = federal_awards_section.get("federal_awards", [])
missing_refs = []
errors = []
for index, award in enumerate(federal_awards):
if (
"award_reference" not in award
): # When award_reference exists the schema ensures it is not empty and has the correct shape
missing_refs.append(first_row + index + 1)

for row_num in missing_refs:
errors.append({"error": err_missing_award_reference(row_num)})

return errors
from audit.fixtures.excel import (
FEDERAL_AWARDS_TEMPLATE_DEFINITION,
)
from .errors import (
err_missing_award_reference,
)
from django.conf import settings
import json

TEMPLATE_DEFINITION_PATH = (
settings.XLSX_TEMPLATE_JSON_DIR / FEDERAL_AWARDS_TEMPLATE_DEFINITION
)
FEDERAL_AWARDS_TEMPLATE = json.loads(
TEMPLATE_DEFINITION_PATH.read_text(encoding="utf-8")
)


def check_award_ref_existence(sac_dict, *_args, **_kwargs):
"""
Check that all awards have a reference code.
"""
first_row = FEDERAL_AWARDS_TEMPLATE["title_row"]
all_sections = sac_dict.get("sf_sac_sections", {})
federal_awards_section = all_sections.get("federal_awards") or {}
federal_awards = federal_awards_section.get("federal_awards", [])
missing_refs = []
errors = []
for index, award in enumerate(federal_awards):
if (
"award_reference" not in award
): # When award_reference exists the schema ensures it is not empty and has the correct shape
missing_refs.append(first_row + index + 1)

for row_num in missing_refs:
errors.append({"error": err_missing_award_reference(row_num)})

return errors
68 changes: 34 additions & 34 deletions backend/audit/cross_validation/check_award_reference_uniqueness.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
from .errors import (
err_duplicate_award_reference,
)
from collections import Counter


def check_award_reference_uniqueness(sac_dict, *_args, **_kwargs):
"""
Check that all award references in the Federal Award workbook are distinct.
"""

all_sections = sac_dict.get("sf_sac_sections", {})
federal_awards_section = all_sections.get("federal_awards") or {}
federal_awards = federal_awards_section.get("federal_awards", [])
award_refs = []
errors = []

for award in federal_awards:
award_reference = award.get("award_reference")

if award_reference:
award_refs.append(award_reference)

duplicated_award_refs = _find_duplicates(award_refs)

for dup_award_ref in duplicated_award_refs:
errors.append({"error": err_duplicate_award_reference(dup_award_ref)})

return errors


def _find_duplicates(lst):
count = Counter(lst)
return [item for item, count in count.items() if count > 1]
from .errors import (
err_duplicate_award_reference,
)
from collections import Counter


def check_award_reference_uniqueness(sac_dict, *_args, **_kwargs):
"""
Check that all award references in the Federal Award workbook are distinct.
"""

all_sections = sac_dict.get("sf_sac_sections", {})
federal_awards_section = all_sections.get("federal_awards") or {}
federal_awards = federal_awards_section.get("federal_awards", [])
award_refs = []
errors = []

for award in federal_awards:
award_reference = award.get("award_reference")

if award_reference:
award_refs.append(award_reference)

duplicated_award_refs = _find_duplicates(award_refs)

for dup_award_ref in duplicated_award_refs:
errors.append({"error": err_duplicate_award_reference(dup_award_ref)})

return errors


def _find_duplicates(lst):
count = Counter(lst)
return [item for item, count in count.items() if count > 1]
44 changes: 22 additions & 22 deletions backend/audit/cross_validation/check_biennial_low_risk.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
from .errors import err_biennial_low_risk


def check_biennial_low_risk(sac_dict, *_args, **_kwargs):
"""
Check that both biennial and low risk flags aren't both set.
"""
all_sections = sac_dict["sf_sac_sections"]

general_information = all_sections.get("general_information", {})
audit_information = all_sections.get("audit_information", {})

if not (general_information and audit_information):
return []

audit_period_covered = general_information.get("audit_period_covered")
is_low_risk_auditee = audit_information.get("is_low_risk_auditee")

if audit_period_covered == "biennial" and is_low_risk_auditee:
return [{"error": err_biennial_low_risk()}]
else:
return []
from .errors import err_biennial_low_risk


def check_biennial_low_risk(sac_dict, *_args, **_kwargs):
"""
Check that both biennial and low risk flags aren't both set.
"""
all_sections = sac_dict["sf_sac_sections"]

general_information = all_sections.get("general_information", {})
audit_information = all_sections.get("audit_information", {})

if not (general_information and audit_information):
return []

audit_period_covered = general_information.get("audit_period_covered")
is_low_risk_auditee = audit_information.get("is_low_risk_auditee")

if audit_period_covered == "biennial" and is_low_risk_auditee:
return [{"error": err_biennial_low_risk()}]
else:
return []
40 changes: 20 additions & 20 deletions backend/audit/cross_validation/check_certifying_contacts.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
from .errors import (
err_certifying_contacts_should_not_match,
)


def check_certifying_contacts(sac_dict, *_args, **_kwargs):
"""
Check that the certifying auditor and auditee do not have the same email address.
"""

sf_sac_meta = sac_dict.get("sf_sac_meta", {})
certifying_auditee_contact = sf_sac_meta.get("certifying_auditee_contact")
certifying_auditor_contact = sf_sac_meta.get("certifying_auditor_contact")
errors = []

if certifying_auditee_contact and certifying_auditor_contact:
if certifying_auditee_contact == certifying_auditor_contact:
errors.append({"error": err_certifying_contacts_should_not_match()})

return errors
from .errors import (
err_certifying_contacts_should_not_match,
)


def check_certifying_contacts(sac_dict, *_args, **_kwargs):
"""
Check that the certifying auditor and auditee do not have the same email address.
"""

sf_sac_meta = sac_dict.get("sf_sac_meta", {})
certifying_auditee_contact = sf_sac_meta.get("certifying_auditee_contact")
certifying_auditor_contact = sf_sac_meta.get("certifying_auditor_contact")
errors = []

if certifying_auditee_contact and certifying_auditor_contact:
if certifying_auditee_contact == certifying_auditor_contact:
errors.append({"error": err_certifying_contacts_should_not_match()})

return errors
Loading

0 comments on commit 55a177c

Please sign in to comment.