Fix slug lookup and add regression test
This commit is contained in:
@@ -3167,6 +3167,11 @@ export const calculators: CalculatorDef[] = [
|
|||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const slugIndex: Map<string, CalculatorDef> = new Map(
|
||||||
|
calculators.map(calc => [calc.slug, calc])
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
export function getCalculatorBySlug(slug: string): CalculatorDef | undefined {
|
export function getCalculatorBySlug(slug: string): CalculatorDef | undefined {
|
||||||
return slugIndex.get(slug);
|
return slugIndex.get(slug);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -463,6 +463,11 @@ export const calculators: CalculatorDef[] = [
|
|||||||
|
|
||||||
out += """
|
out += """
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const slugIndex: Map<string, CalculatorDef> = new Map(
|
||||||
|
calculators.map(calc => [calc.slug, calc])
|
||||||
|
);
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
out += """
|
out += """
|
||||||
|
|||||||
27
tests/test_apothecary_page.py
Normal file
27
tests/test_apothecary_page.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import urllib.error
|
||||||
|
import urllib.request
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
URL = 'https://howdoyouconvert.com/apothecary-ounces-to-amu'
|
||||||
|
|
||||||
|
|
||||||
|
class ApothecaryPageTests(unittest.TestCase):
|
||||||
|
def test_apothecary_page_returns_success(self) -> None:
|
||||||
|
"""The published URL should return a 200 so the calculator page stays healthy."""
|
||||||
|
request = urllib.request.Request(
|
||||||
|
URL,
|
||||||
|
headers={
|
||||||
|
'User-Agent': 'Mozilla/5.0',
|
||||||
|
'Accept': 'text/html,application/xhtml+xml',
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
with urllib.request.urlopen(request, timeout=15) as response:
|
||||||
|
status = response.getcode()
|
||||||
|
except urllib.error.HTTPError as exc:
|
||||||
|
self.fail(f'{URL} returned HTTP {exc.code} ({exc.reason})')
|
||||||
|
except urllib.error.URLError as exc:
|
||||||
|
self.fail(f'{URL} could not be fetched: {exc}')
|
||||||
|
|
||||||
|
self.assertEqual(status, 200, f'{URL} returned {status}')
|
||||||
Reference in New Issue
Block a user