Skip to content

Commit

Permalink
Merge pull request #2364 from GSA-TTS/main
Browse files Browse the repository at this point in the history
  • Loading branch information
jadudm authored Oct 3, 2023
2 parents 7ae174f + 9884d58 commit 0f610a6
Show file tree
Hide file tree
Showing 24 changed files with 412 additions and 69 deletions.
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/bug-template.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: Bug Report 🐞
description: Report a bug and help the FAC improve.
title: "FAC - Bug: [YOUR TITLE]"
labels: ['Type: Bug','Status: Triage','Needs: Confirmation']
labels: ["bug"]
projects: ["GSA-TTS/11"]
body:
- type: textarea
id: problem
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/helpdesk-issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Helpdesk Issue
description: Used as output from helpdesk issue triage.
title: "[HD]: "
labels: ["helpdesk"]
projects: ["GSA-TTS/11"]
assignees:
- jadudm
- carley-sullivan
Expand Down
5 changes: 4 additions & 1 deletion backend/.profile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ if [[ "$CF_INSTANCE_INDEX" == 0 ]]; then
echo 'Finished view creation' &&
echo 'Starting collectstatic' &&
python manage.py collectstatic --noinput &&
echo 'Finished collectstatic'
echo 'Finished collectstatic' &&
echo 'Starting seed_cog_baseline' &&
python manage.py seed_cog_baseline &&
echo 'Finished seed_cog_baseline'
fi

# Make psql usable by scripts, for debugging, etc.
Expand Down
2 changes: 1 addition & 1 deletion backend/api/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def test_success_and_failure(self):
client.force_authenticate(user=user)

# Valid
with patch("api.uei.requests.get") as mock_get:
with patch("api.uei.SESSION.get") as mock_get:
mock_get.return_value.status_code = 200 # Mock the status code
mock_get.return_value.json.return_value = json.loads(
valid_uei_results
Expand Down
1 change: 0 additions & 1 deletion backend/audit/fixtures/CognizantBaseline.json

This file was deleted.

5 changes: 1 addition & 4 deletions backend/audit/intake_to_dissemination.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
from datetime import datetime
import pytz
from django.db import IntegrityError

Expand Down Expand Up @@ -29,9 +28,7 @@ class IntakeToDissemination(object):
def __init__(self, sac) -> None:
self.single_audit_checklist = sac
self.report_id = sac.report_id
audit_date = sac.general_information.get(
"auditee_fiscal_period_start", datetime.now
)
audit_date = sac.general_information["auditee_fiscal_period_end"]
self.audit_year = int(audit_date.split("-")[0])
self.loaded_objects: dict[str, list] = {}

Expand Down
12 changes: 0 additions & 12 deletions backend/audit/management/commands/make_cog_baseline.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.5 on 2023-09-29 23:29

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("audit", "0001_initial"),
]

operations = [
migrations.AlterField(
model_name="singleauditchecklist",
name="report_id",
field=models.CharField(unique=True),
),
]
58 changes: 43 additions & 15 deletions backend/audit/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import calendar
from datetime import datetime, timezone
from itertools import chain
import json
Expand Down Expand Up @@ -41,31 +40,60 @@
logger = logging.getLogger(__name__)


def generate_sac_report_id(end_date=None, source="GSAFAC", count=None):
"""
Convenience method for generating report_id, a value consisting of:
- Four-digit year based on submission fiscal end date.
- Two-digit month based on submission fiscal end date.
- Audit source: either GSAFAC or CENSUS.
- Zero-padded 10-digit numeric monotonically increasing.
- Separated by hyphens.
For example: `2023-09-GSAFAC-0000000001`, `2020-09-CENSUS-0000000001`.
"""
source = source.upper()
if source not in ("CENSUS", "GSAFAC"):
raise Exception("Unknown source for report_id")
if not end_date:
raise Exception("generate_sac_report_id requires end_date.")
if not count:
count = str(SingleAuditChecklist.objects.count() + 1).zfill(10)
year, month, _ = end_date.split("-")
if not (int(year) >= 2000 and int(year) < 2200):
raise Exception("Unexpected year value for report_id")
if int(month) not in range(1, 13):
raise Exception("Unexpected month value for report_id")
separator = "-"
report_id = separator.join([year, month, source, count])
return report_id


class SingleAuditChecklistManager(models.Manager):
"""Manager for SAC"""

def create(self, **obj_data):
"""
Custom create method so that we can add derived fields.
Currently only used for report_id, a 17-character value consisting of:
- Four-digit year of start of audit period.
- Three-character all-caps month abbrevation (start of audit period)
- 10-digit numeric monotonically increasing, but starting from
0001000001 because the Census numbers are six-digit values. The
formula for creating this is basically "how many non-legacy
entries there are in the system plus 1,000,000".
Currently only used for report_id, a value consisting of:
- Four-digit year based on submission fiscal end date.
- Two-digit month based on submission fiscal end date.
- Audit source: either GSAFAC or CENSUS.
- Zero-padded 10-digit numeric monotonically increasing.
- Separated by hyphens.
For example: `2023-09-GSAFAC-0000000001`, `2020-09-CENSUS-0000000001`.
"""

# remove event_user & event_type keys so that they're not passed into super().create below
event_user = obj_data.pop("event_user", None)
event_type = obj_data.pop("event_type", None)

fiscal_start = obj_data["general_information"]["auditee_fiscal_period_start"]
year = fiscal_start[:4]
month = calendar.month_abbr[int(fiscal_start[5:7])].upper()
count = SingleAuditChecklist.objects.count() + 1_000_001
report_id = f"{year}{month}{str(count).zfill(10)}"
end_date = obj_data["general_information"]["auditee_fiscal_period_end"]
report_id = generate_sac_report_id(end_date=end_date, source="GSAFAC")
updated = obj_data | {"report_id": report_id}

result = super().create(**updated)
Expand Down Expand Up @@ -271,7 +299,7 @@ class STATUS:
submitted_by = models.ForeignKey(User, on_delete=models.PROTECT)
date_created = models.DateTimeField(auto_now_add=True)
submission_status = FSMField(default=STATUS.IN_PROGRESS, choices=STATUS_CHOICES)
data_source = models.CharField(default="GSA")
data_source = models.CharField(default="GSAFAC")

# implement an array of tuples as two arrays since we can only have simple fields inside an array
transition_name = ArrayField(
Expand All @@ -289,7 +317,7 @@ class STATUS:
null=True,
)

report_id = models.CharField(max_length=17, unique=True)
report_id = models.CharField(unique=True)

# Q2 Type of Uniform Guidance Audit
audit_type = models.CharField(
Expand Down
48 changes: 36 additions & 12 deletions backend/audit/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
SingleAuditChecklist,
SingleAuditReportFile,
User,
generate_sac_report_id,
)


Expand All @@ -31,12 +32,13 @@ def test_report_id(self):
- There is a report_id value
- The report_id value consists of:
- Four-digit year of start of audit period.
- Three-character all-caps month abbrevation (start of audit period)
- 10-digit numeric monotonically increasing, but starting from
0001000001 because the Census numbers are six-digit values. The
formula for creating this is basically "how many non-legacy
entries there are in the system plus 1,000,000".
- Four-digit year based on submission fiscal end date.
- Two-digit month based on submission fiscal end date.
- Audit source: either GSAFAC or CENSUS.
- Zero-padded 10-digit numeric monotonically increasing.
- Separated by hyphens.
For example: `2023-09-GSAFAC-0000000001`, `2020-09-CENSUS-0000000001`.
"""
user = baker.make(User)
general_information = {
Expand All @@ -50,12 +52,15 @@ def test_report_id(self):
submission_status="in_progress",
general_information=general_information,
)
self.assertEqual(len(sac.report_id), 17)
self.assertEqual(sac.report_id[:4], "2022")
self.assertEqual(sac.report_id[4:7], "NOV")
self.assertEqual(len(sac.report_id), 25)
separator = "-"
year, month, source, count = sac.report_id.split(separator)
self.assertEqual(year, "2023")
self.assertEqual(month, "11")
self.assertEqual(source, "GSAFAC")
# This one is a little dubious because it assumes this will always be
# the first entry in the test database:
self.assertEqual(sac.report_id[7:], "0001000001")
self.assertEqual(count, "0000000001")

def test_submission_status_transitions(self):
"""
Expand Down Expand Up @@ -193,7 +198,17 @@ def test_filename_generated(self):
"""
file = SimpleUploadedFile("this is a file.xlsx", b"this is a file")

excel_file = baker.make(ExcelFile, file=file, form_section="sectionname")
excel_file = baker.make(
ExcelFile,
file=file,
form_section="sectionname",
sac=baker.make(
SingleAuditChecklist,
report_id=generate_sac_report_id(
end_date=datetime.now().date().isoformat()
),
),
)
report_id = SingleAuditChecklist.objects.get(id=excel_file.sac.id).report_id

self.assertEqual(f"{report_id}--sectionname.xlsx", excel_file.filename)
Expand All @@ -208,7 +223,16 @@ def test_filename_generated(self):
"""
file = SimpleUploadedFile("this is a file.pdf", b"this is a file")

sar_file = baker.make(SingleAuditReportFile, file=file)
sar_file = baker.make(
SingleAuditReportFile,
file=file,
sac=baker.make(
SingleAuditChecklist,
report_id=generate_sac_report_id(
end_date=datetime.now().date().isoformat()
),
),
)
report_id = SingleAuditChecklist.objects.get(id=sar_file.sac.id).report_id

self.assertEqual(f"{report_id}.pdf", sar_file.filename)
Expand Down
Loading

0 comments on commit 0f610a6

Please sign in to comment.