Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/py_moodle/draftfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
7 changes: 2 additions & 5 deletions tests/test_draftfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
Loading