From 73cc929dbf0845303aa5d75fa82e63fb5f5f4520 Mon Sep 17 00:00:00 2001 From: Wyatt Pearsall Date: Tue, 21 May 2024 09:50:47 -0400 Subject: [PATCH 1/3] Use local url list instead of S3 copy --- cfgov/scripts/http_smoke_test.py | 65 +++++++++++++------------------- 1 file changed, 27 insertions(+), 38 deletions(-) diff --git a/cfgov/scripts/http_smoke_test.py b/cfgov/scripts/http_smoke_test.py index 2b79b2572a..d885caadbc 100755 --- a/cfgov/scripts/http_smoke_test.py +++ b/cfgov/scripts/http_smoke_test.py @@ -63,35 +63,35 @@ 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 @@ -155,24 +155,13 @@ "/compliance/implementation-guidance/hmda-implementation/", "/compliance/implementation-guidance/mortserv/", "/compliance/implementation-guidance/tila-respa-disclosure-rule/", + "/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", + "/consumer-tools/retirement/retirement-api/estimator/1-1-1970/99000/", + "/data-research/consumer-complaints/search/api/v1/?size=1", ] # 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): @@ -199,7 +188,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 From 355275a9bc52473fce9ced2213eff0b033de0ef8 Mon Sep 17 00:00:00 2001 From: Wyatt Pearsall Date: Tue, 21 May 2024 10:15:18 -0400 Subject: [PATCH 2/3] Sort app list and cleanup 301s --- cfgov/cfgov/urls.py | 4 +- cfgov/scripts/http_smoke_test.py | 72 +++++++++++++++----------------- 2 files changed, 36 insertions(+), 40 deletions(-) diff --git a/cfgov/cfgov/urls.py b/cfgov/cfgov/urls.py index eec23d093d..37e363096e 100644 --- a/cfgov/cfgov/urls.py +++ b/cfgov/cfgov/urls.py @@ -299,7 +299,7 @@ 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, ), ), @@ -307,7 +307,7 @@ def empty_200_response(request, *args, **kwargs): re_path( r"^students/(?P.*)$", RedirectView.as_view( - url="/consumer-tools/educator-tools/students/%(path)s", + url="/paying-for-college/", permanent=True, ), ), diff --git a/cfgov/scripts/http_smoke_test.py b/cfgov/scripts/http_smoke_test.py index d885caadbc..0d84d51adf 100755 --- a/cfgov/scripts/http_smoke_test.py +++ b/cfgov/scripts/http_smoke_test.py @@ -98,66 +98,62 @@ # 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/", - "/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", - "/consumer-tools/retirement/retirement-api/estimator/1-1-1970/99000/", - "/data-research/consumer-complaints/search/api/v1/?size=1", + "/your-story/", ] # call `set` on the combined list to weed out dupes From daf46ae68c0f813222ce7428fdbb7cec3392500d Mon Sep 17 00:00:00 2001 From: Wyatt Pearsall Date: Tue, 21 May 2024 11:04:23 -0400 Subject: [PATCH 3/3] fixup unittests --- cfgov/scripts/tests/test_smoke_tests.py | 42 +++++-------------------- 1 file changed, 8 insertions(+), 34 deletions(-) diff --git a/cfgov/scripts/tests/test_smoke_tests.py b/cfgov/scripts/tests/test_smoke_tests.py index 80b10d2916..1529034409 100755 --- a/cfgov/scripts/tests/test_smoke_tests.py +++ b/cfgov/scripts/tests/test_smoke_tests.py @@ -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): @@ -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() @@ -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): @@ -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", @@ -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) @@ -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( @@ -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",