import tempfile import unittest from pathlib import Path from src.upload_limits import validate_upload class UploadLimitTests(unittest.TestCase): def test_accepts_expected_suffix_under_limit(self): with tempfile.TemporaryDirectory() as tmp: path = Path(tmp) / "site.geojson" path.write_text("{}", encoding="utf-8") self.assertEqual( validate_upload(path, allowed_suffixes={".geojson"}, max_mb=1, label="GeoJSON"), path, ) def test_rejects_wrong_suffix(self): with tempfile.TemporaryDirectory() as tmp: path = Path(tmp) / "site.txt" path.write_text("{}", encoding="utf-8") with self.assertRaisesRegex(ValueError, "GeoJSON must be"): validate_upload(path, allowed_suffixes={".geojson"}, max_mb=1, label="GeoJSON") def test_rejects_file_over_limit(self): with tempfile.TemporaryDirectory() as tmp: path = Path(tmp) / "site.geojson" path.write_bytes(b"x" * 2048) with self.assertRaisesRegex(ValueError, "Limit is 0 MB"): validate_upload(path, allowed_suffixes={".geojson"}, max_mb=0, label="GeoJSON") if __name__ == "__main__": unittest.main()