Skip to content

Commit

Permalink
Merge pull request #8433 from cfpb/check-in-smoketest-urls
Browse files Browse the repository at this point in the history
Check in smoketest urls
  • Loading branch information
wpears committed May 24, 2024
2 parents 69adbfc + daf46ae commit 196d528
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 109 deletions.
4 changes: 2 additions & 2 deletions cfgov/cfgov/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,15 +299,15 @@ def empty_200_response(request, *args, **kwargs):
re_path(
r"^empowerment/$",
RedirectView.as_view(
url="/consumer-tools/educator-tools/economically-vulnerable/",
url="/consumer-tools/educator-tools/your-money-your-goals/",
permanent=True,
),
),
# students redirects
re_path(
r"^students/(?P<path>.*)$",
RedirectView.as_view(
url="/consumer-tools/educator-tools/students/%(path)s",
url="/paying-for-college/",
permanent=True,
),
),
Expand Down
131 changes: 58 additions & 73 deletions cfgov/scripts/http_smoke_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,116 +63,101 @@
BASE = "https://www.consumerfinance.gov"
S3_URI = "https://files.consumerfinance.gov/build/smoketests/smoketest_urls.json" # noqa: E501

# Fall-back list of top 25 URLs, as of July 2, 2020, from hubcap/wiki
# Fall-back list of top 25 URLs, as of May 2024
# All URLs in the list should be canonical locations of the given pages,
# not redirects.
TOP = [
"/", # home page
"/about-us/blog/guide-covid-19-economic-stimulus-checks/",
"/about-us/blog/guide-coronavirus-mortgage-relief-options/",
"/find-a-housing-counselor/",
"/",
"/complaint/",
"/find-a-housing-counselor/",
"/housing/housing-insecurity/help-for-renters/get-help-paying-rent-and-bills/",
"/learnmore/",
"/ask-cfpb/what-is-the-best-way-to-negotiate-a-settlement-with-a-debt-collector-en-1447/", # noqa: E501
"/coronavirus/",
"/about-us/blog/guide-covid-19-economic-stimulus-checks/#qualify/",
"/consumer-tools/prepaid-cards/",
"/coronavirus/cares-act-mortgage-forbearance-what-you-need-know/",
"/about-us/blog/economic-impact-payment-prepaid-card/",
"/about-us/blog/what-you-need-to-know-about-student-loans-and-coronavirus-pandemic/", # noqa: E501
"/complaint/getting-started/",
"/coronavirus/mortgage-and-housing-assistance/",
"/ask-cfpb/what-is-forbearance-en-289/",
"/about-us/blog/guide-covid-19-economic-stimulus-checks/#when/",
"/consumer-tools/debt-collection/",
"/consumer-tools/guide-to-filing-your-taxes/",
"/ask-cfpb/what-should-i-do-when-a-debt-collector-contacts-me-en-1695/",
"/about-us/blog/protect-yourself-financially-from-impact-of-coronavirus/",
"/about-us/contact-us/",
"/about-us/blog/guide-coronavirus-mortgage-relief-options/#relief-options/", # noqa: E501
"/coronavirus/managing-your-finances/economic-impact-payment-prepaid-debit-cards/", # noqa: E501
"/ask-cfpb/how-can-i-tell-who-owns-my-mortgage-en-214/",
"/ask-cfpb/how-do-i-negotiate-a-settlement-with-a-debt-collector-en-1447/",
"/ask-cfpb/how-do-i-get-a-free-copy-of-my-credit-reports-en-5/",
"/rules-policy/regulations/",
"/ask-cfpb/what-is-a-debt-to-income-ratio-why-is-the-43-debt-to-income-ratio-important-en-1791/", # noqa: E501
"/about-us/newsroom/consumer-advisory-opportunity-to-cancel-student-loan-debt-ends-soon/",
"/ask-cfpb/what-is-a-money-market-account-en-1007/",
"/data-research/consumer-complaints/search/",
"/about-us/newsroom/",
"/enforcement/actions/",
"/ask-cfpb/does-a-persons-debt-go-away-when-they-die-en-1463/",
"/about-us/contact-us/",
"/ask-cfpb/where-can-i-get-my-credit-scores-en-316/",
"/ask-cfpb/what-is-a-reverse-mortgage-en-224/",
"/ask-cfpb/how-do-i-get-my-money-back-after-i-discover-an-unauthorized-transaction-or-money-missing-from-my-bank-account-en-1017/",
"/paying-for-college/student-loan-forgiveness/",
"/ask-cfpb/what-do-i-need-to-know-if-im-thinking-about-consolidating-my-credit-card-debt-en-1861/",
"/rules-policy/regulations/1026/",
"/ask-cfpb/what-should-i-do-if-im-sued-by-a-debt-collector-or-creditor-en-334/",
]

# URLs for cfgov sub-apps that are expected to be present
# All URLs in the list should be canonical locations of the given pages,
# not redirects.
APPS = [
"/about-us/budget-strategy/",
"/enforcement/payments-harmed-consumers/",
"/about-us/blog/",
"/about-us/newsroom/",
"/about-us/events/",
"/about-us/budget-strategy/",
"/about-us/careers/",
"/about-us/careers/current-openings/",
"/about-us/doing-business-with-us/",
"/rules-policy/competition-innovation/",
"/about-us/events/",
"/about-us/newsroom/",
"/activity-log/",
"/ask-cfpb/",
"/your-story/",
"/es/",
"/es/obtener-respuestas/",
"/students/",
"/consumer-tools/educator-tools/servicemembers/",
"/know-before-you-owe/",
"/fair-lending/",
"/paying-for-college/",
"/paying-for-college2/understanding-your-financial-aid-offer/about-this-tool/", # noqa: E501
"/retirement/before-you-claim/",
"/es/herramientas-del-consumidor/jubilacion/antes-de-solicitar/",
"/compliance/",
"/compliance/amicus/",
"/compliance/compliance-resources/mortgage-resources/hmda-reporting-requirements/",
"/compliance/compliance-resources/mortgage-resources/mortserv/",
"/compliance/compliance-resources/mortgage-resources/tila-respa-integrated-disclosures/",
"/consumer-tools/auto-loans/",
"/consumer-tools/credit-reports-and-scores/",
"/consumer-tools/debt-collection/",
"/consumer-tools/prepaid-cards/",
"/consumer-tools/sending-money/",
"/mortgagehelp/",
"/consumer-tools/educator-tools/your-money-your-goals/",
"/consumer-tools/educator-tools/adult-financial-education/",
"/consumer-tools/educator-tools/youth-financial-education/",
"/consumer-tools/educator-tools/library-resources/",
"/consumer-tools/educator-tools/resources-for-older-adults/",
"/consumer-tools/educator-tools/resources-for-tax-preparers/",
"/consumer-tools/educator-tools/servicemembers/",
"/consumer-tools/educator-tools/your-money-your-goals/",
"/consumer-tools/educator-tools/youth-financial-education/",
"/consumer-tools/educator-tools/youth-financial-education/",
"/consumer-tools/money-as-you-grow/",
"/empowerment/",
"/consumer-tools/educator-tools/resources-for-older-adults/",
"/consumer-tools/educator-tools/youth-financial-education/", # TDP
"/consumer-tools/prepaid-cards/",
"/consumer-tools/retirement/before-you-claim/",
"/consumer-tools/retirement/retirement-api/estimator/1-1-1970/99000/",
"/consumer-tools/sending-money/",
"/data-research/",
"/data-research/research-reports/",
"/data-research/cfpb-research-conference/",
"/data-research/cfpb-researchers/",
"/data-research/consumer-complaints/",
"/data-research/hmda/",
"/data-research/hmda/for-filers",
"/data-research/consumer-complaints/search/api/v1/?size=1",
"/data-research/consumer-credit-trends/",
"/data-research/credit-card-data/",
"/data-research/cfpb-researchers/",
"/data-research/hmda/",
"/data-research/mortgage-performance-trends/",
"/data-research/research-reports/",
"/enforcement/",
"/enforcement/payments-harmed-consumers/",
"/es/",
"/es/herramientas-del-consumidor/jubilacion/antes-de-solicitar/",
"/es/obtener-respuestas/",
"/fair-lending/",
"/know-before-you-owe/",
"/mortgagehelp/",
"/oah-api/rates/rate-checker?price=200000&loan_amount=180000&minfico=740&maxfico=759&state=AL&rate_structure=fixed&loan_term=30&loan_type=conf",
"/paying-for-college/",
"/paying-for-college2/understanding-your-financial-aid-offer/about-this-tool/", # noqa: E501
"/policy-compliance/",
"/rules-policy/",
"/compliance/",
"/compliance/implementation-guidance/",
"/enforcement/",
"/rules-policy/competition-innovation/",
"/rules-policy/notice-opportunities-comment/",
"/compliance/amicus/",
"/compliance/implementation-guidance/hmda-implementation/",
"/compliance/implementation-guidance/mortserv/",
"/compliance/implementation-guidance/tila-respa-disclosure-rule/",
"/your-story/",
]

# call `set` on the combined list to weed out dupes
FALLBACK_URLS = sorted(set(TOP + APPS))


def get_full_list():
"""Fetch a list of URLs to test from s3, or fall back to local default."""
try:
url_data = requests.get(S3_URI).json()
except Exception as e:
logger.warning(
"Using fallback because request for S3 list failed: {}".format(e)
)
url_list = FALLBACK_URLS
else:
url_list = sorted(set(url_data.get("top") + url_data.get("apps")))
return url_list
URLS = sorted(set(TOP + APPS))


def check_urls(base, url_list=None):
Expand All @@ -199,7 +184,7 @@ def check_urls(base, url_list=None):
failures = []
starter = time.time()
if not url_list:
url_list = get_full_list()
url_list = URLS
for url_suffix in url_list:
logger.info(url_suffix)
count += 1
Expand Down
42 changes: 8 additions & 34 deletions cfgov/scripts/tests/test_smoke_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
import requests

from scripts import static_asset_smoke_test
from scripts.http_smoke_test import (
ALLOWED_TIMEOUTS,
FALLBACK_URLS,
check_urls,
get_full_list,
)
from scripts.http_smoke_test import ALLOWED_TIMEOUTS, URLS, check_urls


class StaticAssetTests(unittest.TestCase):
Expand Down Expand Up @@ -62,21 +57,6 @@ def test_link_check_failure(self, mock_extract, mock_get):
class HttpTests(unittest.TestCase):
"""Tests for the http smoke tests."""

@mock.patch("scripts.http_smoke_test.requests.get")
def test_get_full_list(self, mock_get):
mock_response = mock.Mock()
mock_response.json.return_value = {"top": ["url1"], "apps": ["url2"]}
mock_get.return_value = mock_response
full_list = get_full_list()
self.assertEqual(len(full_list), 2)
self.assertEqual(mock_get.call_count, 1)

@mock.patch("scripts.http_smoke_test.requests.get", side_effect=ValueError)
def test_get_full_list_fallback(self, mock_get):
"""Check that script falls back to hard-coded list."""
full_list = get_full_list()
self.assertEqual(len(full_list), len(FALLBACK_URLS))

@mock.patch("scripts.http_smoke_test.requests.get")
def test_http_success_url_list(self, mock_get):
mock_response = mock.Mock()
Expand All @@ -86,14 +66,12 @@ def test_http_success_url_list(self, mock_get):
self.assertEqual(mock_get.call_count, 2)

@mock.patch("scripts.http_smoke_test.requests.get")
@mock.patch("scripts.http_smoke_test.get_full_list")
def test_http_success_full(self, mock_list, mock_get):
mock_list.return_value = FALLBACK_URLS
def test_http_success_full(self, mock_get):
mock_response = mock.Mock()
mock_response.status_code = 200
mock_get.return_value = mock_response
self.assertTrue(check_urls("pro1"))
self.assertEqual(mock_get.call_count, len(FALLBACK_URLS))
self.assertEqual(mock_get.call_count, len(URLS))

@mock.patch("scripts.http_smoke_test.requests.get")
def test_http_fail_url_list(self, mock_get):
Expand All @@ -106,15 +84,13 @@ def test_http_fail_url_list(self, mock_get):
self.assertEqual(mock_get.call_count, 1)

@mock.patch("scripts.http_smoke_test.requests.get")
@mock.patch("scripts.http_smoke_test.get_full_list")
def test_http_fail_full(self, mock_list, mock_get):
def test_http_fail_full(self, mock_get):
mock_response = mock.Mock()
mock_list.return_value = FALLBACK_URLS
mock_response.status_code = 404
mock_get.return_value = mock_response
result = check_urls("pro1")
self.assertFalse(result)
self.assertEqual(mock_get.call_count, len(FALLBACK_URLS))
self.assertEqual(mock_get.call_count, len(URLS))

@mock.patch(
"scripts.http_smoke_test.requests.get",
Expand All @@ -129,7 +105,7 @@ def test_http_fail_timeout(self, mock_get):
side_effect=requests.exceptions.Timeout,
)
def test_http_fail_timeout_full(self, mock_get):
expected_call_count = len(FALLBACK_URLS) + 1 # one call for s3
expected_call_count = len(URLS)
self.assertFalse(check_urls("pro1"))
self.assertEqual(mock_get.call_count, expected_call_count)

Expand All @@ -139,7 +115,7 @@ def test_http_fail_timeout_full(self, mock_get):
)
def test_allowed_timeouts(self, mock_get):
too_many = ALLOWED_TIMEOUTS + 2
urls = FALLBACK_URLS[:too_many]
urls = URLS[:too_many]
self.assertFalse(check_urls("pro1", url_list=urls))

@mock.patch(
Expand All @@ -148,9 +124,7 @@ def test_allowed_timeouts(self, mock_get):
)
def test_http_fail_connection_error(self, mock_get):
check_urls("pro1")
self.assertEqual(
mock_get.call_count, len(FALLBACK_URLS) + 1
) # one call for s3
self.assertEqual(mock_get.call_count, len(URLS))

@mock.patch(
"scripts.http_smoke_test.requests.get",
Expand Down

0 comments on commit 196d528

Please sign in to comment.