Skip to content

Commit

Permalink
Merge branch 'main' into tadhg/mypy-weirdness
Browse files Browse the repository at this point in the history
  • Loading branch information
tadhg-ohiggins committed Sep 25, 2023
2 parents dabd5dc + 9cadd56 commit ae8d523
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 72 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/regression-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
env:
CYPRESS_API_GOV_KEY: ${{ secrets.CYPRESS_API_GOV_KEY }}
CYPRESS_API_GOV_URL: ${{ secrets.CYPRESS_API_GOV_URL }}
CYPRESS_BASE_URL: ${{ inputs.url }}
CYPRESS_LOGIN_TEST_EMAIL: ${{ secrets.CYPRESS_LOGIN_TEST_EMAIL }}
CYPRESS_LOGIN_TEST_PASSWORD: ${{ secrets.CYPRESS_LOGIN_TEST_PASSWORD }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/testing-from-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18

- name: Create .env
working-directory: ./backend
Expand Down Expand Up @@ -73,7 +73,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
- name: Start services
working-directory: ./backend
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/testing-from-ghcr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18

- name: Create .env file
working-directory: ./backend
Expand Down
15 changes: 9 additions & 6 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ RUN \
apt-get update && \
apt-get install -yqq apt-transport-https wget gnupg2

# Updated nodesource install via: https://github.com/nodesource/distributions#ubuntu-versions
RUN \
apt-get update -yq && \
apt install curl -y && \
apt-get install -y gcc && \
curl -fsSL https://deb.nodesource.com/setup_14.x | bash - && \
apt-get install -y nodejs && \
apt-get install -y npm && \
npm i -g npm@^8
apt install build-essential curl -y && \
apt-get install -y gcc ca-certificates gnupg && \
mkdir -p /etc/apt/keyrings && \
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
NODE_MAJOR=18 && \
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && \
apt-get update && \
apt-get install nodejs -y

COPY requirements.txt /tmp/requirements.txt
COPY dev-requirements.txt /tmp/dev-requirements.txt
Expand Down
12 changes: 6 additions & 6 deletions backend/audit/intake_to_dissemination.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,15 @@ def _get_dates_from_sac(self):
return_dict[status] = None
return return_dict

def _convert_utc_to_utc_minus_12(self, date):
utc_minus_12_zone = pytz.timezone("Etc/GMT+12")
def _convert_utc_to_american_samoa_zone(self, date):
us_samoa_zone = pytz.timezone("US/Samoa")
# Ensure the datetime object is time zone aware
if date.tzinfo is None or date.tzinfo.utcoffset(date) is None:
date = pytz.utc.localize(date)
# Convert to UTC-12
utc_minus_12_time = date.astimezone(utc_minus_12_zone)
# Convert to American Samoa timezone (UTC-11)
american_samoa_time = date.astimezone(us_samoa_zone)
# Extract the date and format it as YYYY-MM-DD
formatted_date = utc_minus_12_time.strftime("%Y-%m-%d")
formatted_date = american_samoa_time.strftime("%Y-%m-%d")

return formatted_date

Expand All @@ -274,7 +274,7 @@ def load_general(self):
ready_for_certification_date = dates_by_status[status.READY_FOR_CERTIFICATION]
auditor_certified_date = dates_by_status[status.AUDITOR_CERTIFIED]
auditee_certified_date = dates_by_status[status.AUDITEE_CERTIFIED]
submitted_date = self._convert_utc_to_utc_minus_12(
submitted_date = self._convert_utc_to_american_samoa_zone(
dates_by_status[status.SUBMITTED]
)
auditee_certify_name = auditee_certification.get("auditee_signature", {}).get(
Expand Down
90 changes: 61 additions & 29 deletions backend/audit/test_intake_to_dissemination.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from datetime import datetime, time, timezone, timedelta
import json
from django.test import TestCase
import random
from model_bakery import baker
from faker import Faker

Expand All @@ -22,6 +21,35 @@
from audit.utils import Util


def _set_transitions_hour(sac, hour):
statuses = [
SingleAuditChecklist.STATUS.READY_FOR_CERTIFICATION,
SingleAuditChecklist.STATUS.AUDITOR_CERTIFIED,
SingleAuditChecklist.STATUS.AUDITEE_CERTIFIED,
SingleAuditChecklist.STATUS.SUBMITTED,
]
# Get the current time in UTC
current = datetime.now(timezone.utc).date()
transition_date = datetime.combine(
current,
time(
hour=hour,
minute=0,
second=0,
microsecond=0,
tzinfo=timezone.utc,
),
)

for status in statuses:
sac.transition_date.append(transition_date)
sac.transition_name.append(status)
# Increment the minute by 2
transition_date += timedelta(minutes=2)

return sac


class IntakeToDisseminationTests(TestCase):
def __init__(self, methodName: str = "runTest") -> None:
super().__init__(methodName)
Expand All @@ -33,27 +61,17 @@ def _run_state_transition(self, sac):
SingleAuditChecklist.STATUS.AUDITEE_CERTIFIED,
SingleAuditChecklist.STATUS.SUBMITTED,
]
# Get the current date in UTC
current_date_utc = datetime.now(timezone.utc).date()
# Create a datetime object for the current date with a time between 0:00 a.m. and 11:00 a.m.
transition_date = datetime.combine(
current_date_utc,
time(
hour=random.randint(0, 11), # nosec
minute=0,
second=0,
microsecond=0,
tzinfo=timezone.utc,
),
)
# Get the current time in UTC
transition_date = datetime.now(timezone.utc)

for status in statuses:
sac.transition_date.append(transition_date)
sac.transition_name.append(status)
sac.save()
# Increment the minute by 2
transition_date += timedelta(minutes=2)

return sac

def setUp(self):
self.user = baker.make(User)

Expand All @@ -73,7 +91,7 @@ def setUp(self):
cognizant_agency="42",
oversight_agency="42",
)
self._run_state_transition(sac)
sac = self._run_state_transition(sac)
self.sac = sac
self.intake_to_dissemination = IntakeToDissemination(self.sac)
self.report_id = sac.report_id
Expand Down Expand Up @@ -349,17 +367,31 @@ def test_load_general(self):
)

def test_submitted_date(self):
"""The date of submission should be disseminated as the prior date if the submission occurs before 11 a.m."""
self.intake_to_dissemination.load_general()
self.intake_to_dissemination.save_dissemination_objects()
generals = General.objects.all()
self.assertEqual(len(generals), 1)
general = generals.first()

# Calculate the date before today
day_before = datetime.now().date() - timedelta(days=1)

self.assertEqual(general.submitted_date, day_before)
"""
The date of submission should be disseminated using the time in American Samoa.
"""
hours = range(0, 24)

for hour in hours:
with self.subTest():
self.setUp()
self.sac.transition_date = []
self.sac.transition_name = []
sac = _set_transitions_hour(self.sac, hour)
sac.save()
self.intake_to_dissemination.load_general()
self.intake_to_dissemination.save_dissemination_objects()
generals = General.objects.all()
self.assertEqual(len(generals), 1)
general = generals.first()

# Get the sac submitted date
subdate = self.sac.get_transition_date(self.sac.STATUS.SUBMITTED)
# Calculate the date at UTC-11 (the American Samoa timezone does not do DST)
date_in_american_samoa = (subdate - timedelta(hours=11)).date()

self.assertEqual(general.submitted_date, date_in_american_samoa)
general.delete()

def test_load_federal_award(self):
self.intake_to_dissemination.load_federal_award()
Expand Down Expand Up @@ -467,7 +499,7 @@ def test_load_all(self):
audit_information=self._fake_audit_information(),
auditee_certification=self._fake_auditee_certification(),
)
self._run_state_transition(sac)
sac = self._run_state_transition(sac)
self.sac = sac
self.intake_to_dissemination = IntakeToDissemination(self.sac)
self.intake_to_dissemination.load_all()
Expand All @@ -493,7 +525,7 @@ def test_load_and_return_objects(self):
audit_information=self._fake_audit_information(),
auditee_certification=self._fake_auditee_certification(),
)
self._run_state_transition(sac)
sac = self._run_state_transition(sac)
self.sac = sac
self.intake_to_dissemination = IntakeToDissemination(self.sac)
self.report_id = sac.report_id
Expand Down
14 changes: 12 additions & 2 deletions backend/cypress/e2e/full-submission.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { testAuditInformationForm } from '../support/audit-info-form.js';
import { testPdfAuditReport } from '../support/report-pdf.js';
import { testAuditorCertification } from '../support/auditor-certification.js';
import { testAuditeeCertification } from '../support/auditee-certification.js';
import { testReportIdFound, testReportIdNotFound } from '../support/dissemination-table.js';
import {
testWorkbookFederalAwards,
testWorkbookNotesToSEFA,
Expand All @@ -23,6 +24,7 @@ import {
const LOGIN_TEST_EMAIL_AUDITEE = Cypress.env('LOGIN_TEST_EMAIL_AUDITEE');
const LOGIN_TEST_PASSWORD_AUDITEE = Cypress.env('LOGIN_TEST_PASSWORD_AUDITEE');
const LOGIN_TEST_OTP_SECRET_AUDITEE = Cypress.env('LOGIN_TEST_OTP_SECRET_AUDITEE');
const API_GOV_JWT = Cypress.env('API_GOV_JWT');

describe('Full audit submission', () => {
before(() => {
Expand Down Expand Up @@ -53,6 +55,12 @@ describe('Full audit submission', () => {
// Now the accessandsubmission screen
testValidAccess();

// Report should not yet be in the dissemination table
cy.url().then(url => {
const reportId = url.split('/').pop();
testReportIdNotFound(reportId);
});

// Fill out the general info form
testValidGeneralInfo();

Expand Down Expand Up @@ -81,7 +89,6 @@ describe('Full audit submission', () => {
cy.get(".usa-link").contains("Secondary Auditors").click();
testWorkbookSecondaryAuditors(false);


cy.get(".usa-link").contains("Additional EINs").click();
testWorkbookAdditionalEINs(false);

Expand Down Expand Up @@ -126,6 +133,9 @@ describe('Full audit submission', () => {
'caption',
'The audits listed below have been submitted to the FAC for processing and may not be edited.',
).siblings().contains('td', reportId);
})

// Report should now be in the dissemination table
testReportIdFound(reportId);
});
});
});
36 changes: 36 additions & 0 deletions backend/cypress/support/dissemination-table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Re-useable code for testing the dissemination table.
*/

const API_GOV_JWT = Cypress.env('API_GOV_JWT') || '';
const API_GOV_KEY = Cypress.env('API_GOV_KEY') || '';
const API_GOV_URL = Cypress.env('API_GOV_URL');

const requestOptions = {
method: 'GET',
url: `${API_GOV_URL}/general`,
headers: {
Authorization: `Bearer ${API_GOV_JWT}`,
'X-Api-Key': API_GOV_KEY,
},
}

export function testReportIdNotFound(reportId) {
cy.request({
...requestOptions,
qs: {report_id: `eq.${reportId}`},
}).should((response) => {
expect(response.body).to.have.length(0);
});
}

export function testReportIdFound(reportId) {
cy.request({
...requestOptions,
qs: {report_id: `eq.${reportId}`},
}).should((response) => {
expect(response.body).to.have.length(1);
const hasAgency = !!(response.body[0]?.cognizant_agency || response.body[0]?.oversight_agency);
expect(hasAgency).to.be.true;
});
}
Loading

0 comments on commit ae8d523

Please sign in to comment.