diff --git a/src/py_moodle/draftfile.py b/src/py_moodle/draftfile.py index 3d3de9a..0e0e617 100644 --- a/src/py_moodle/draftfile.py +++ b/src/py_moodle/draftfile.py @@ -123,7 +123,12 @@ def detect_upload_repo(session: requests.Session, base_url: str, course_id: int) for repo_data in repositories.values(): if repo_data.get("type") == "upload": - return int(repo_data["id"]) + repo_id = int(repo_data["id"]) + if repo_id <= 0: + raise MoodleDraftFileError( + f"Invalid repository ID detected: {repo_id}. Repository ID must be a positive integer." + ) + return repo_id raise MoodleDraftFileError( "No repository with type='upload' found in the configuration." diff --git a/tests/test_draftfile.py b/tests/test_draftfile.py index 30afbb5..cfc0b23 100644 --- a/tests/test_draftfile.py +++ b/tests/test_draftfile.py @@ -145,12 +145,9 @@ def test_detect_upload_repo_scraping(moodle, request, temporary_course_for_draft session=moodle, base_url=base_url, course_id=course_id ) - # 1. Verify that the result is an integer + # Verify that the result is a positive integer assert isinstance(repo_id, int), "The returned repo_id should be an integer." - - # 2. In a standard Moodle installation, the upload repository ID is 5. - # This is a good check to ensure we are not getting a random value. - assert repo_id == 5, "The detected repo_id for 'upload' should typically be 5." + assert repo_id > 0, "The detected repo_id should be a positive integer." except MoodleDraftFileError as e: pytest.fail(f"detect_upload_repo failed with an exception: {e}")