test_id_list.py 887 B

12345678910111213141516171819202122232425262728
  1. """parse_id_list: the id lists the bulk routes take."""
  2. import pytest
  3. from fastapi import HTTPException
  4. from backend.app.utils.id_list import MAX_IDS, parse_id_list
  5. def test_parses_in_order_without_duplicates():
  6. assert parse_id_list("3,1,3, 2 ,") == [3, 1, 2]
  7. def test_empty_is_no_ids():
  8. assert parse_id_list("") == []
  9. @pytest.mark.parametrize("value", ["abc", "1,x", "-1", "0", "1.5", "²", "١٢", "+3"])
  10. def test_rejects_anything_but_positive_ascii_integers(value):
  11. with pytest.raises(HTTPException) as caught:
  12. parse_id_list(value)
  13. assert caught.value.status_code == 422
  14. def test_caps_the_list():
  15. assert len(parse_id_list(",".join(str(i) for i in range(1, MAX_IDS + 1)))) == MAX_IDS
  16. with pytest.raises(HTTPException) as caught:
  17. parse_id_list(",".join(str(i) for i in range(1, MAX_IDS + 2)))
  18. assert caught.value.status_code == 422