11import pytest
22import os
3+
4+ import requests
35from icalendar import Calendar
46
7+ ICAL_VALIDATOR_URL = "https://icalendar.org/validator.html?json=1"
8+
59def find_ics_files (base_path = './' ):
610 ics_files = []
711 for root , _ , files in os .walk (base_path ):
@@ -41,3 +45,25 @@ def test_calendar_name_matches_filename_with_suffix(parsed_calendar):
4145 expected_name = build_expected_calendar_name (path )
4246 assert cal_name == expected_name , f"Expected calendar name '{ expected_name } ', but found '{ cal_name } ' (NAME) in { path } "
4347 assert x_wr_cal_name == expected_name , f"Expected calendar name '{ expected_name } ', but found '{ x_wr_cal_name } ' (X-WR-CALNAME) in { path } "
48+
49+ @pytest .mark .parametrize ("ics_path" , find_ics_files ())
50+ def test_icalendar_org_validator (ics_path ):
51+ with open (ics_path , 'rb' ) as f :
52+ files = {
53+ "jform[task]" : (None , "validate" ),
54+ "jform[ical_file]" : (os .path .basename (ics_path ), f , "text/calendar" ),
55+ }
56+ response = requests .post (ICAL_VALIDATOR_URL , files = files )
57+ response .raise_for_status ()
58+ data = response .json ()
59+
60+ errors = data .get ("totals" , {}).get ("errors" , 0 )
61+ warnings = data .get ("totals" , {}).get ("warnings" , 0 )
62+
63+ if errors > 0 :
64+ messages = "\n " .join (err ["message" ] for err in data .get ("errors" , []))
65+ pytest .fail (f"Validation errors in { ics_path } :\n { messages } " )
66+
67+ if warnings > 0 :
68+ messages = "\n " .join (warn ["message" ] for warn in data .get ("warnings" , []))
69+ pytest .skip (f"Validation warnings in { ics_path } :\n { messages } " )
0 commit comments