Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search - Summary View Tests #2512

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 106 additions & 5 deletions backend/dissemination/tests.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
from django.test import TestCase

import os
from datetime import datetime


import jwt
import os
import requests

from model_bakery import baker

from django.test import Client, TestCase
from django.urls import reverse

from config import settings
from dissemination.templatetags.field_name_to_label import field_name_to_label
from dissemination.models import (
General,
FederalAward,
Passthrough,
Finding,
FindingText,
CapText,
Note,
)


class APIViewTests(TestCase):
Expand Down Expand Up @@ -60,3 +71,93 @@ def test_api_fails_with_wrong_role(self):
self.api_url, headers={"Authorization": f"Bearer {encoded_jwt}"}, timeout=10
)
self.assertEquals(response.status_code, 400)


class TemplateTagTests(TestCase):
def test_field_name_to_label(self):
"""
Given a field name with underscores like "report_id", it should be converted
to display like "Report Id"
"""
sample_field = "report_id"
converted_sample_field = field_name_to_label(sample_field)
self.assertEquals(converted_sample_field, "Report Id")

sample_field = "auditee_contact_title"
converted_sample_field = field_name_to_label(sample_field)
self.assertEquals(converted_sample_field, "Auditee Contact Title")


class SummaryViewTests(TestCase):
def setUp(self):
self.client = Client()

def test_public_summary(self):
"""
A public audit should have a viewable summary, and returns 200.
"""
baker.make(General, report_id="2022-12-GSAFAC-0000000001", is_public=True)
url = reverse(
"dissemination:Summary", kwargs={"report_id": "2022-12-GSAFAC-0000000001"}
)

response = self.client.get(url)
self.assertEquals(response.status_code, 200)

def test_private_summary(self):
"""
A private audit should not have a viewable summary, and returns 404.
"""
baker.make(General, report_id="2022-12-GSAFAC-0000000001", is_public=False)
url = reverse(
"dissemination:Summary", kwargs={"report_id": "2022-12-GSAFAC-0000000001"}
)

response = self.client.get(url)
self.assertEquals(response.status_code, 404)

def test_summary_context(self):
"""
The summary context should include the same data that is in the models.
Create a bunch of fake DB data under the same report_id. Then, check a few
fields in the context for the summary page to verify that the fake data persists.
"""
baker.make(General, report_id="2022-12-GSAFAC-0000000001", is_public=True)
award = baker.make(FederalAward, report_id="2022-12-GSAFAC-0000000001")
passthrough = baker.make(Passthrough, report_id="2022-12-GSAFAC-0000000001")
finding = baker.make(Finding, report_id="2022-12-GSAFAC-0000000001")
finding_text = baker.make(FindingText, report_id="2022-12-GSAFAC-0000000001")
cap_text = baker.make(CapText, report_id="2022-12-GSAFAC-0000000001")
note = baker.make(Note, report_id="2022-12-GSAFAC-0000000001")

url = reverse(
"dissemination:Summary", kwargs={"report_id": "2022-12-GSAFAC-0000000001"}
)

response = self.client.get(url)
self.assertEquals(
response.context["data"]["Awards"][0]["additional_award_identification"],
award.additional_award_identification,
)
self.assertEquals(
response.context["data"]["Passthrough Entities"][0]["award_reference"],
passthrough.award_reference,
)
self.assertEquals(
response.context["data"]["Audit Findings"][0]["reference_number"],
finding.reference_number,
)
self.assertEquals(
response.context["data"]["Audit Findings Text"][0]["finding_ref_number"],
finding_text.finding_ref_number,
)
self.assertEquals(
response.context["data"]["Corrective Action Plan"][0][
"contains_chart_or_table"
],
cap_text.contains_chart_or_table,
)
self.assertEquals(
response.context["data"]["Notes"][0]["accounting_policies"],
note.accounting_policies,
)