The circuit and track routes walked circuits.json with chained lookups, so an unknown country, locality, circuit or layout, or a year no layout covers, raised and answered 500 (/circuits/photos.json among them). One lookup now names the first unknown part and the API answers it 404. numpy loads only where a script uses it, so the models, and this lookup's test, need the standard library alone. Claude-Session: https://claude.ai/code/session_01NcbgfJAa38xFpzy69BWrqh
36 lines
1.5 KiB
Python
36 lines
1.5 KiB
Python
"""An unknown country, locality, circuit or layout, or a year no layout covers, is named (the API answers it 404).
|
|
|
|
Standard library only: the models load numpy only where a script uses it.
|
|
"""
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from circuits_service import CircuitService, NotFound
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
|
|
|
|
class LookupTest(unittest.TestCase):
|
|
def test_the_first_unknown_part_is_named(self):
|
|
service = CircuitService(str(ROOT / "circuits" / "circuits.json"))
|
|
spa = ("belgium", "spa", "circuit-de-spa-francorchamps")
|
|
self.assertEqual(service.resolve(*spa, "1983-").slug, "1983-")
|
|
self.assertEqual(service.layout_for_year(*spa, 1960).slug, "1950-1970")
|
|
cases = {
|
|
("photos.json",): "No country 'photos.json'",
|
|
("belgium", "nowhere"): "No locality 'nowhere' in Belgium",
|
|
("belgium", "spa", "nothing"): "No circuit 'nothing' in Spa",
|
|
(*spa, "1999"): "No layout '1999' in Circuit de Spa-Francorchamps",
|
|
}
|
|
for slugs, named in cases.items():
|
|
with self.assertRaises(NotFound, msg=slugs) as caught:
|
|
service.resolve(*slugs)
|
|
self.assertEqual(str(caught.exception), named)
|
|
with self.assertRaises(NotFound) as caught:
|
|
service.layout_for_year(*spa, 1975) # Spa was not raced from 1971 to 1982
|
|
self.assertEqual(str(caught.exception), "No layout of Circuit de Spa-Francorchamps covers 1975")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|