Skip to content

Commit d1982fe

Browse files
committed
Merge branch 'reduce-bash-tests'
2 parents a363bae + 3cbcb4a commit d1982fe

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

.github/workflows/jekyll-gh-pages.yml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,6 @@ jobs:
2222
steps:
2323
- name: Checkout
2424
uses: actions/checkout@v3
25-
- name: Test files
26-
run: |
27-
for s in $(find -type f -name "*.ics" -print); do
28-
echo "::group::Test file $s";
29-
echo "Make http request"
30-
response=$(curl -sS -F "jform[task]=validate" -F "jform[ical_file]=@$s" "https://icalendar.org/validator.html?json=1")
31-
echo "::debug::$response"
32-
error_count=$(echo "$response" | jq '.totals.errors')
33-
warning_count=$(echo "$response" | jq '.totals.warnings')
34-
echo "File has $error_count errors and $warning_count warnings."
35-
if [ "$error_count" -gt "0" ]; then
36-
echo "::error title=Error found::$(echo "$response" | jq -r '.errors | map(.message) | join("\n")')"
37-
exit 1
38-
fi
39-
if [ "$warning_count" -gt "0" ]; then
40-
echo "::warning title=Warning found::$(echo "$response" | jq -r '.warnings | map(.message) | join("\n")')"
41-
exit 2
42-
fi
43-
echo "::endgroup::"
44-
done
4525
- name: Set up Python
4626
uses: actions/setup-python@v4
4727
with:

tests/requirements.txt

184 Bytes
Binary file not shown.

tests/test_calendar_files.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import pytest
22
import os
3+
4+
import requests
35
from icalendar import Calendar
46

7+
ICAL_VALIDATOR_URL = "https://icalendar.org/validator.html?json=1"
8+
59
def 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

Comments
 (0)